Code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
FILE *fp;
char fn[100];
int main(int argc, char *argv[]) {
//declare variables
int i,j,n;
float t[10000],b[10000];
float t1;
float t2;
float threshold;
float blank;
float tim[20];
threshold = 120.0;
blank = 60;
if(argc!=2) {
printf("you didn't include the filename silly\n");
}
else {
strcpy(fn,argv[1]); //put filename on command line
fp = fopen(fn,"r");
if(fp==NULL) {
printf("error opening file\n");
}
else {
//insert functionality here
//first find out how many points
i = 0;
j = 0;
while(fscanf(fp,"%g %g",&t[i],&b[i])!=EOF) {
i++;
}
n = i;
fclose(fp);
i = 0;
j = 0;
while(b[i]<threshold) {
i++;
}
tim[j] = t[i];
printf("t%d = %f\n",j+1,tim[j]);
//how do i skip over 60 points?
i = i + blank;
while(b[i]<threshold) {
i++;
}
tim[j+1] = t[i];
printf("t%d = %f\n",j+2,tim[j+1]);
printf("instantaneous HR for the period %d = %f\n",j+1,60/(tim[j+1]-tim[j]));
}
}
return 0;
}