#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "group.h"

extern int init;
extern int cnt;
extern int t_last;

// safe to use exit: pump and power are off

int seis(int mag)
{
int t;
FILE *fp;

if ((fp = fopen( "/seismonitor/seis.dat","rt" )) == NULL) {
    	printf("Can't open data file.\n");
	exit(0); 
} 

// printf("prescan: t_last is %d mag is %d\n", t_last, mag);
while (fscanf(fp, "%06d %i", &t, &mag) == 2) {
// printf("postscan: t is %d mag is %d\n", t_last, mag);
	if (mag > 20 && mag < 90) {
            	if (init == 0) {
            		t_last = t;
            	} else if (t != t_last) {
            		t_last = t;
            		return mag;
		} 
	} else if (mag==-1) {
        	return mag;
       	} else {
    		printf("Check data file contents.\n");
		exit(0); 
       	}
}
fclose ( fp );
}
