-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathrfsites.c
76 lines (63 loc) · 1.53 KB
/
rfsites.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "rfsites.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LIM 80
// Get observing site
site_t get_site(int site_id) {
int i=0,status;
int count = 0;
char line[LIM];
FILE *file;
int id;
double lat,lng;
float alt;
char abbrev[3],observer[64];
site_t s;
char *env_datadir,*env_sites_txt,filename[LIM];
env_datadir = getenv("ST_DATADIR");
if (env_datadir == NULL || strlen(env_datadir) == 0) {
env_datadir = ".";
}
env_sites_txt = getenv("ST_SITES_TXT");
if (env_sites_txt == NULL || strlen(env_sites_txt) == 0) {
sprintf(filename, "%s/data/sites.txt", env_datadir);
} else {
sprintf(filename, "%s", env_sites_txt);
}
file=fopen(filename,"r");
if (file==NULL) {
printf("File with site information not count!\n");
exit(0);
}
while (fgets(line,LIM,file)!=NULL) {
// Skip
if (strstr(line,"#")!=NULL)
continue;
// Strip newline
line[strlen(line)-1]='\0';
// Read data
status=sscanf(line,"%4d %2s %lf %lf %f",
&id,abbrev,&lat,&lng,&alt);
strcpy(observer,line+38);
// Change to km
alt/=1000.0;
// Copy site
if (id==site_id) {
count += 1;
s.lat=lat;
s.lng=lng;
s.alt=alt;
s.id=id;
strcpy(s.observer,observer);
}
}
fclose(file);
if (count == 0) {
printf("Error: Site %d was not found in %s!\n", site_id, filename);
exit(-1);
} else if (count > 1) {
printf("Site %d was found multiple times in %s, use last occurence.\n", site_id, filename);
}
return s;
}