Add error/warning if site is missing/duplicate from sites.txt

Previously a missing site / wrongly configured sites.txt was a common
source of frustration for me.
master
Fabian P. Schmidt 2023-01-14 13:24:58 +01:00 committed by Cees Bassa
parent 84f526c2ec
commit 0c07ce585c
1 changed files with 11 additions and 2 deletions

View File

@ -9,6 +9,7 @@
// Get observing site
site_t get_site(int site_id) {
int i=0,status;
int count = 0;
char line[LIM];
FILE *file;
int id;
@ -27,12 +28,12 @@ site_t get_site(int site_id) {
if (env_sites_txt == NULL || strlen(env_sites_txt) == 0) {
sprintf(filename, "%s/data/sites.txt", env_datadir);
} else {
sprintf(filename, "%s", env_datadir);
sprintf(filename, "%s", env_sites_txt);
}
file=fopen(filename,"r");
if (file==NULL) {
printf("File with site information not found!\n");
printf("File with site information not count!\n");
exit(0);
}
while (fgets(line,LIM,file)!=NULL) {
@ -53,6 +54,7 @@ site_t get_site(int site_id) {
// Copy site
if (id==site_id) {
count += 1;
s.lat=lat;
s.lng=lng;
s.alt=alt;
@ -63,5 +65,12 @@ site_t get_site(int site_id) {
}
fclose(file);
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);
}
return s;
}