im not quite sure how to do that or what you mean. how will that affect reading the code?
Code:
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#define FILENAME "seismic.dat"
#define MAX_SIZE 1000
#define THRESHOLD 1.5
main()
{
/* Declare variables and function prototypes. */
int k, npts, short_window, long_window;
double sensor[MAX_SIZE], time_incr, short_power,
long_power, ratio;
FILE *file_ptr;
double power_w(double x[], int length, int n);
/* Read data file. */
file_ptr = fopen(FILENAME,"r");
fscanf(file_ptr,"%i %lf",&npts,&time_incr);
if (npts > MAX_SIZE)
{
printf("Data file too large for array. \n");
return EXIT_FAILURE;
}
else
{
/* Read data into an array. */
for (k=0; k<=npts-1; k++)
fscanf(file_ptr,"%lf",&sensor[k]);
}
/* Read window sizes from the keyboard. */
printf("Enter number of points for short-window: \n");
scanf("%i",&short_window);
printf("Enter number of points for long-window: \n");
scanf("%i",&long_window);
/* 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",
time_incr*k);
}
/* Close file and exit program. */
fclose(file_ptr);
return EXIT_SUCCESS;
}
/*--------------------------------------------------------*/
/* 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. */
int k;
double xsquare=0;
/* 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. */
return xsquare/length;
}
/*--------------------------------------------------------*/