forked from ExternalVendorCode/Signal-Server
Detect and handle errors in loading udt
This commit is contained in:
223
inputs.cc
223
inputs.cc
@@ -1537,7 +1537,7 @@ int LoadTopoData(int max_lon, int min_lon, int max_lat, int min_lat)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadUDT(char *filename)
|
int LoadUDT(char *filename)
|
||||||
{
|
{
|
||||||
/* This function reads a file containing User-Defined Terrain
|
/* This function reads a file containing User-Defined Terrain
|
||||||
features for their addition to the digital elevation model
|
features for their addition to the digital elevation model
|
||||||
@@ -1552,13 +1552,83 @@ void LoadUDT(char *filename)
|
|||||||
double latitude, longitude, height, tempheight;
|
double latitude, longitude, height, tempheight;
|
||||||
FILE *fd1 = NULL, *fd2 = NULL;
|
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) {
|
if( (fd = mkstemp(tempname)) == -1 )
|
||||||
fd = mkstemp(tempname);
|
return errno;
|
||||||
fd2 = fopen(tempname, "w");
|
|
||||||
|
if( (fd2 = fdopen(fd,"w")) == NULL ){
|
||||||
|
fclose(fd1);
|
||||||
|
close(fd);
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = fgets(input, 78, fd1);
|
||||||
|
|
||||||
|
pointer = strchr(input, ';');
|
||||||
|
|
||||||
|
if (pointer != NULL)
|
||||||
|
*pointer = 0;
|
||||||
|
|
||||||
|
while (feof(fd1) == 0) {
|
||||||
|
/* Parse line for latitude, longitude, height */
|
||||||
|
|
||||||
|
for (x = 0, y = 0, z = 0;
|
||||||
|
x < 78 && input[x] != 0 && z < 3; x++) {
|
||||||
|
if (input[x] != ',' && y < 78) {
|
||||||
|
str[z][y] = input[x];
|
||||||
|
y++;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
str[z][y] = 0;
|
||||||
|
z++;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
latitude = ReadBearing(str[0]);
|
||||||
|
longitude = ReadBearing(str[1]);
|
||||||
|
|
||||||
|
if (longitude < 0.0)
|
||||||
|
longitude += 360;
|
||||||
|
|
||||||
|
/* Remove <CR> and/or <LF> from antenna height string */
|
||||||
|
|
||||||
|
for (i = 0;
|
||||||
|
str[2][i] != 13 && str[2][i] != 10
|
||||||
|
&& str[2][i] != 0; i++) ;
|
||||||
|
|
||||||
|
str[2][i] = 0;
|
||||||
|
|
||||||
|
/* The terrain feature may be expressed in either
|
||||||
|
feet or meters. If the letter 'M' or 'm' is
|
||||||
|
discovered in the string, then this is an
|
||||||
|
indication that the value given is expressed
|
||||||
|
in meters. Otherwise the height is interpreted
|
||||||
|
as being expressed in feet. */
|
||||||
|
|
||||||
|
for (i = 0;
|
||||||
|
str[2][i] != 'M' && str[2][i] != 'm'
|
||||||
|
&& str[2][i] != 0 && i < 48; i++) ;
|
||||||
|
|
||||||
|
if (str[2][i] == 'M' || str[2][i] == 'm') {
|
||||||
|
str[2][i] = 0;
|
||||||
|
height = rint(atof(str[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
str[2][i] = 0;
|
||||||
|
height = rint(METERS_PER_FOOT * atof(str[2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (height > 0.0)
|
||||||
|
fprintf(fd2, "%d, %d, %f\n",
|
||||||
|
(int)rint(latitude / dpp),
|
||||||
|
(int)rint(longitude / dpp), height);
|
||||||
|
|
||||||
s = fgets(input, 78, fd1);
|
s = fgets(input, 78, fd1);
|
||||||
|
|
||||||
@@ -1566,125 +1636,64 @@ void LoadUDT(char *filename)
|
|||||||
|
|
||||||
if (pointer != NULL)
|
if (pointer != NULL)
|
||||||
*pointer = 0;
|
*pointer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (feof(fd1) == 0) {
|
fclose(fd1);
|
||||||
/* Parse line for latitude, longitude, height */
|
fclose(fd2);
|
||||||
|
|
||||||
for (x = 0, y = 0, z = 0;
|
if( (fd1 = fopen(tempname, "r")) == NULL )
|
||||||
x < 78 && input[x] != 0 && z < 3; x++) {
|
return errno;
|
||||||
if (input[x] != ',' && y < 78) {
|
|
||||||
str[z][y] = input[x];
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
if( (fd2 = fopen(tempname, "r")) == NULL ){
|
||||||
str[z][y] = 0;
|
fclose(fd1);
|
||||||
z++;
|
return errno;
|
||||||
y = 0;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
latitude = ReadBearing(str[0]);
|
y = 0;
|
||||||
longitude = ReadBearing(str[1]);
|
|
||||||
|
|
||||||
if (longitude < 0.0)
|
n = fscanf(fd1, "%d, %d, %lf", &xpix, &ypix, &height);
|
||||||
longitude += 360;
|
|
||||||
|
|
||||||
/* Remove <CR> and/or <LF> from antenna height string */
|
do {
|
||||||
|
x = 0;
|
||||||
|
z = 0;
|
||||||
|
|
||||||
for (i = 0;
|
n = fscanf(fd2, "%d, %d, %lf", &tempxpix, &tempypix,
|
||||||
str[2][i] != 13 && str[2][i] != 10
|
&tempheight);
|
||||||
&& str[2][i] != 0; i++) ;
|
|
||||||
|
|
||||||
str[2][i] = 0;
|
do {
|
||||||
|
if (x > y && xpix == tempxpix
|
||||||
|
&& ypix == tempypix) {
|
||||||
|
z = 1; /* Dupe! */
|
||||||
|
|
||||||
/* The terrain feature may be expressed in either
|
if (tempheight > height)
|
||||||
feet or meters. If the letter 'M' or 'm' is
|
height = tempheight;
|
||||||
discovered in the string, then this is an
|
|
||||||
indication that the value given is expressed
|
|
||||||
in meters. Otherwise the height is interpreted
|
|
||||||
as being expressed in feet. */
|
|
||||||
|
|
||||||
for (i = 0;
|
|
||||||
str[2][i] != 'M' && str[2][i] != 'm'
|
|
||||||
&& str[2][i] != 0 && i < 48; i++) ;
|
|
||||||
|
|
||||||
if (str[2][i] == 'M' || str[2][i] == 'm') {
|
|
||||||
str[2][i] = 0;
|
|
||||||
height = rint(atof(str[2]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
str[2][i] = 0;
|
n = fscanf(fd2, "%d, %d, %lf",
|
||||||
height = rint(METERS_PER_FOOT * atof(str[2]));
|
&tempxpix, &tempypix,
|
||||||
|
&tempheight);
|
||||||
|
x++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (height > 0.0)
|
} while (feof(fd2) == 0 && z == 0);
|
||||||
fprintf(fd2, "%d, %d, %f\n",
|
|
||||||
(int)rint(latitude / dpp),
|
|
||||||
(int)rint(longitude / dpp), height);
|
|
||||||
|
|
||||||
s = fgets(input, 78, fd1);
|
if (z == 0)
|
||||||
|
/* No duplicate found */
|
||||||
pointer = strchr(input, ';');
|
//fprintf(stderr,"%lf, %lf \n",xpix*dpp, ypix*dpp);
|
||||||
|
fflush(stderr);
|
||||||
if (pointer != NULL)
|
AddElevation(xpix * dpp, ypix * dpp, height, 1);
|
||||||
*pointer = 0;
|
fflush(stderr);
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fd1);
|
|
||||||
fclose(fd2);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
fd1 = fopen(tempname, "r");
|
|
||||||
fd2 = fopen(tempname, "r");
|
|
||||||
|
|
||||||
y = 0;
|
|
||||||
|
|
||||||
n = fscanf(fd1, "%d, %d, %lf", &xpix, &ypix, &height);
|
n = fscanf(fd1, "%d, %d, %lf", &xpix, &ypix, &height);
|
||||||
|
y++;
|
||||||
|
|
||||||
do {
|
rewind(fd2);
|
||||||
x = 0;
|
|
||||||
z = 0;
|
|
||||||
|
|
||||||
n = fscanf(fd2, "%d, %d, %lf", &tempxpix, &tempypix,
|
} while (feof(fd1) == 0);
|
||||||
&tempheight);
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (x > y && xpix == tempxpix
|
|
||||||
&& ypix == tempypix) {
|
|
||||||
z = 1; /* Dupe! */
|
|
||||||
|
|
||||||
if (tempheight > height)
|
|
||||||
height = tempheight;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
n = fscanf(fd2, "%d, %d, %lf",
|
|
||||||
&tempxpix, &tempypix,
|
|
||||||
&tempheight);
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (feof(fd2) == 0 && z == 0);
|
|
||||||
|
|
||||||
if (z == 0)
|
|
||||||
/* No duplicate found */
|
|
||||||
//fprintf(stderr,"%lf, %lf \n",xpix*dpp, ypix*dpp);
|
|
||||||
fflush(stderr);
|
|
||||||
AddElevation(xpix * dpp, ypix * dpp, height, 1);
|
|
||||||
fflush(stderr);
|
|
||||||
|
|
||||||
n = fscanf(fd1, "%d, %d, %lf", &xpix, &ypix, &height);
|
|
||||||
y++;
|
|
||||||
|
|
||||||
rewind(fd2);
|
|
||||||
|
|
||||||
} while (feof(fd1) == 0);
|
|
||||||
|
|
||||||
fclose(fd1);
|
|
||||||
fclose(fd2);
|
|
||||||
unlink(tempname);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
fclose(fd1);
|
||||||
|
fclose(fd2);
|
||||||
|
unlink(tempname);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ int LoadSignalColors(struct site xmtr);
|
|||||||
int LoadLossColors(struct site xmtr);
|
int LoadLossColors(struct site xmtr);
|
||||||
int LoadDBMColors(struct site xmtr);
|
int LoadDBMColors(struct site xmtr);
|
||||||
int LoadTopoData(int max_lon, int min_lon, int max_lat, int min_lat);
|
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 loadLIDAR(char *filename);
|
||||||
int loadClutter(char *filename, double radius, struct site tx);
|
int loadClutter(char *filename, double radius, struct site tx);
|
||||||
|
|
||||||
|
18
main.cc
18
main.cc
@@ -28,6 +28,7 @@ double version = 3.02;
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "inputs.hh"
|
#include "inputs.hh"
|
||||||
@@ -1049,8 +1050,8 @@ int main(int argc, char *argv[])
|
|||||||
unsigned char LRmap = 0, txsites = 0, topomap = 0, geo = 0, kml =
|
unsigned char LRmap = 0, txsites = 0, topomap = 0, geo = 0, kml =
|
||||||
0, area_mode = 0, max_txsites, ngs = 0;
|
0, area_mode = 0, max_txsites, ngs = 0;
|
||||||
|
|
||||||
char mapfile[255], udt_file[255], ano_filename[255], lidar_tiles[4096], clutter_file[255];
|
char mapfile[255], ano_filename[255], lidar_tiles[4096], clutter_file[255];
|
||||||
char *az_filename, *el_filename;
|
char *az_filename, *el_filename, *udt_file = NULL;
|
||||||
|
|
||||||
double altitude = 0.0, altitudeLR = 0.0, tx_range = 0.0,
|
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;
|
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_erp = -1.0;
|
||||||
forced_freq = 0.0;
|
forced_freq = 0.0;
|
||||||
sdf_path[0] = 0;
|
sdf_path[0] = 0;
|
||||||
udt_file[0] = 0;
|
udt_file = NULL;
|
||||||
path.length = 0;
|
path.length = 0;
|
||||||
max_txsites = 30;
|
max_txsites = 30;
|
||||||
fzone_clearance = 0.6;
|
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;
|
z = x + 1;
|
||||||
|
|
||||||
if (z <= y && argv[z][0]) {
|
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);
|
strncpy(udt_file, argv[z], 253);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1813,7 +1818,10 @@ int main(int argc, char *argv[])
|
|||||||
mpi = ippd-1;
|
mpi = ippd-1;
|
||||||
|
|
||||||
// User defined clutter file
|
// 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
|
// Enrich with Clutter
|
||||||
if(strlen(clutter_file) > 1){
|
if(strlen(clutter_file) > 1){
|
||||||
|
@@ -507,7 +507,7 @@ int DoSigStr(char *filename, unsigned char geo, unsigned char kml,
|
|||||||
fclose(fd);
|
fclose(fd);
|
||||||
fd = NULL;
|
fd = NULL;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,
|
void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,
|
||||||
|
Reference in New Issue
Block a user