Detect and handle errors in loading udt

This commit is contained in:
Gareth Evans
2017-03-04 20:14:41 +00:00
parent f3029bb3cf
commit 4109c6488f
4 changed files with 131 additions and 114 deletions

View File

@@ -1537,7 +1537,7 @@ int LoadTopoData(int max_lon, int min_lon, int max_lat, int min_lat)
return 0;
}
void LoadUDT(char *filename)
int LoadUDT(char *filename)
{
/* This function reads a file containing User-Defined Terrain
features for their addition to the digital elevation model
@@ -1552,13 +1552,19 @@ void LoadUDT(char *filename)
double latitude, longitude, height, tempheight;
FILE *fd1 = NULL, *fd2 = NULL;
strcpy(tempname, "/tmp/XXXXXX\0");
strcpy(tempname, "/tmp/XXXXXX");
fd1 = fopen(filename, "r");
if( (fd1 = fopen(filename, "r")) == NULL )
return errno;
if (fd1 != NULL) {
fd = mkstemp(tempname);
fd2 = fopen(tempname, "w");
if( (fd = mkstemp(tempname)) == -1 )
return errno;
if( (fd2 = fdopen(fd,"w")) == NULL ){
fclose(fd1);
close(fd);
return errno;
}
s = fgets(input, 78, fd1);
@@ -1634,10 +1640,14 @@ void LoadUDT(char *filename)
fclose(fd1);
fclose(fd2);
close(fd);
fd1 = fopen(tempname, "r");
fd2 = fopen(tempname, "r");
if( (fd1 = fopen(tempname, "r")) == NULL )
return errno;
if( (fd2 = fopen(tempname, "r")) == NULL ){
fclose(fd1);
return errno;
}
y = 0;
@@ -1685,6 +1695,5 @@ void LoadUDT(char *filename)
fclose(fd1);
fclose(fd2);
unlink(tempname);
}
return 0;
}

View File

@@ -10,7 +10,7 @@ int LoadSignalColors(struct site xmtr);
int LoadLossColors(struct site xmtr);
int LoadDBMColors(struct site xmtr);
int LoadTopoData(int max_lon, int min_lon, int max_lat, int min_lat);
void LoadUDT(char *filename);
int LoadUDT(char *filename);
int loadLIDAR(char *filename);
int loadClutter(char *filename, double radius, struct site tx);

18
main.cc
View File

@@ -28,6 +28,7 @@ double version = 3.02;
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include "common.h"
#include "inputs.hh"
@@ -1049,8 +1050,8 @@ int main(int argc, char *argv[])
unsigned char LRmap = 0, txsites = 0, topomap = 0, geo = 0, kml =
0, area_mode = 0, max_txsites, ngs = 0;
char mapfile[255], udt_file[255], ano_filename[255], lidar_tiles[4096], clutter_file[255];
char *az_filename, *el_filename;
char mapfile[255], ano_filename[255], lidar_tiles[4096], clutter_file[255];
char *az_filename, *el_filename, *udt_file = NULL;
double altitude = 0.0, altitudeLR = 0.0, tx_range = 0.0,
rx_range = 0.0, deg_range = 0.0, deg_limit = 0.0, deg_range_lon;
@@ -1142,7 +1143,7 @@ int main(int argc, char *argv[])
forced_erp = -1.0;
forced_freq = 0.0;
sdf_path[0] = 0;
udt_file[0] = 0;
udt_file = NULL;
path.length = 0;
max_txsites = 30;
fzone_clearance = 0.6;
@@ -1488,10 +1489,14 @@ int main(int argc, char *argv[])
}
/*UDT*/ if (strcmp(argv[x], "-udt") == 0) {
/*UDT*/
if (strcmp(argv[x], "-udt") == 0) {
z = x + 1;
if (z <= y && argv[z][0]) {
udt_file = (char*) calloc(PATH_MAX+1, sizeof(char));
if( udt_file == NULL )
return ENOMEM;
strncpy(udt_file, argv[z], 253);
}
}
@@ -1813,7 +1818,10 @@ int main(int argc, char *argv[])
mpi = ippd-1;
// User defined clutter file
LoadUDT(udt_file);
if( udt_file != NULL && (result = LoadUDT(udt_file)) != 0 ){
fprintf(stderr, "Error loading clutter file\n");
return result;
}
// Enrich with Clutter
if(strlen(clutter_file) > 1){

View File

@@ -507,7 +507,7 @@ int DoSigStr(char *filename, unsigned char geo, unsigned char kml,
fclose(fd);
fd = NULL;
}
return 0;
}
void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,