-
Notifications
You must be signed in to change notification settings - Fork 10
/
read_ephm_data.c
54 lines (50 loc) · 1.18 KB
/
read_ephm_data.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include"utils.h"
#include<stdio.h>
#include<stdlib.h>
int read_ephm_data(char *filename,double *TIME,double *E,double *E0)
{
double cao=1.731446326742403e+02;
FILE *fid;
char *buffer=calloc(2048,sizeof(char));
double E2[3];
double E02[3];
double time;
double lttime;
int count=0;
int nreads=0;
fid=fopen(filename,"r");
if(fid==NULL)
{
fprintf(stderr,"Error opening ephm file %s\n",filename);
exit(-1);
}
while(fgets(buffer,2048,fid))
{
nreads=sscanf(buffer,"%lf %lf %lf %lf %lf %lf %lf",&time,E02,E02+1,E02+2,E2,E2+1,E2+2);
if(nreads==7)
{
E0[3*count]=E02[0];
E0[3*count+1]=E02[1];
E0[3*count+2]=E02[2];
E[3*count]=E2[0];
E[3*count+1]=E2[1];
E[3*count+2]=E2[2];
TIME[count]=time;
}
else if(nreads==4)
{
E[3*count]=E02[0];
E[3*count+1]=E02[1];
E[3*count+2]=E02[2];
TIME[count]=time;
}
else
{
break;
}
count++;
}
fclose(fid);
free(buffer);
return count;
}