2023-01-14 04:03:16 -07:00
|
|
|
#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;
|
2023-01-14 05:24:58 -07:00
|
|
|
int count = 0;
|
2023-01-14 04:03:16 -07:00
|
|
|
char line[LIM];
|
|
|
|
FILE *file;
|
|
|
|
int id;
|
|
|
|
double lat,lng;
|
|
|
|
float alt;
|
|
|
|
char abbrev[3],observer[64];
|
|
|
|
site_t s;
|
2023-01-14 04:18:18 -07:00
|
|
|
char *env_datadir,*env_sites_txt,filename[LIM];
|
2023-01-14 04:03:16 -07:00
|
|
|
|
2023-01-14 04:18:18 -07:00
|
|
|
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 {
|
2023-01-14 05:24:58 -07:00
|
|
|
sprintf(filename, "%s", env_sites_txt);
|
2023-01-14 04:18:18 -07:00
|
|
|
}
|
2023-01-14 04:03:16 -07:00
|
|
|
|
|
|
|
file=fopen(filename,"r");
|
|
|
|
if (file==NULL) {
|
2023-01-14 05:24:58 -07:00
|
|
|
printf("File with site information not count!\n");
|
2023-01-14 04:03:16 -07:00
|
|
|
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) {
|
2023-01-14 05:24:58 -07:00
|
|
|
count += 1;
|
2023-01-14 04:03:16 -07:00
|
|
|
s.lat=lat;
|
|
|
|
s.lng=lng;
|
|
|
|
s.alt=alt;
|
|
|
|
s.id=id;
|
|
|
|
strcpy(s.observer,observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
|
2023-01-14 05:24:58 -07:00
|
|
|
if (count == 0) {
|
|
|
|
printf("Error: Site %d was not found in sites.txt!", site_id);
|
|
|
|
exit(-1);
|
|
|
|
} else if (count > 1) {
|
|
|
|
printf("Site %d was found multiple times in sites.txt, use last occurence.", site_id);
|
|
|
|
}
|
|
|
|
|
2023-01-14 04:03:16 -07:00
|
|
|
return s;
|
|
|
|
}
|