forked from ExternalVendorCode/Signal-Server
195
inputs.cc
195
inputs.cc
@@ -3,6 +3,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "main.hh"
|
#include "main.hh"
|
||||||
|
|
||||||
@@ -22,9 +24,8 @@ int loadClutter(char *filename, double radius, struct site tx)
|
|||||||
char * pch;
|
char * pch;
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
|
|
||||||
fd = fopen(filename, "rb");
|
if( (fd = fopen(filename, "rb")) == NULL)
|
||||||
|
return errno;
|
||||||
if (fd != NULL) {
|
|
||||||
|
|
||||||
if (fgets(line, 19, fd) != NULL) {
|
if (fgets(line, 19, fd) != NULL) {
|
||||||
pch = strtok (line," ");
|
pch = strtok (line," ");
|
||||||
@@ -120,7 +121,7 @@ int loadClutter(char *filename, double radius, struct site tx)
|
|||||||
fprintf(stderr, "Clutter error @ x %d y %d\n", x, y);
|
fprintf(stderr, "Clutter error @ x %d y %d\n", x, y);
|
||||||
}//if
|
}//if
|
||||||
}//for
|
}//for
|
||||||
}
|
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -234,9 +235,8 @@ int loadLIDAR(char *filenames)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (indx < fc) {
|
while (indx < fc) {
|
||||||
fd = fopen(files[indx], "rb");
|
if( (fd = fopen(files[indx], "rb")) == NULL )
|
||||||
|
return errno;
|
||||||
if (fd != NULL) {
|
|
||||||
|
|
||||||
if (fgets(line, 255, fd) != NULL) {
|
if (fgets(line, 255, fd) != NULL) {
|
||||||
pch = strtok (line," ");
|
pch = strtok (line," ");
|
||||||
@@ -332,9 +332,6 @@ int loadLIDAR(char *filenames)
|
|||||||
fclose(fd);
|
fclose(fd);
|
||||||
if (debug)
|
if (debug)
|
||||||
fprintf(stderr, "LIDAR LOADED %d x %d\n", width, height);
|
fprintf(stderr, "LIDAR LOADED %d x %d\n", width, height);
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
indx++;
|
indx++;
|
||||||
} // filename(s)
|
} // filename(s)
|
||||||
IPPD=width;
|
IPPD=width;
|
||||||
@@ -353,11 +350,12 @@ int LoadSDF_SDF(char *name)
|
|||||||
containing digital elevation model data into memory.
|
containing digital elevation model data into memory.
|
||||||
Elevation data, maximum and minimum elevations, and
|
Elevation data, maximum and minimum elevations, and
|
||||||
quadrangle limits are stored in the first available
|
quadrangle limits are stored in the first available
|
||||||
dem[] structure. */
|
dem[] structure.
|
||||||
|
NOTE: On error, this function returns a negative errno */
|
||||||
|
|
||||||
int x, y, data = 0, indx, minlat, minlon, maxlat, maxlon, j;
|
int x, y, data = 0, indx, minlat, minlon, maxlat, maxlon, j;
|
||||||
char found, free_page = 0, line[20], jline[20], sdf_file[255],
|
char found, free_page = 0, line[20], jline[20], sdf_file[255],
|
||||||
path_plus_name[255], *junk = NULL;
|
path_plus_name[PATH_MAX];
|
||||||
|
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
|
|
||||||
@@ -368,9 +366,8 @@ int LoadSDF_SDF(char *name)
|
|||||||
|
|
||||||
/* Parse filename for minimum latitude and longitude values */
|
/* Parse filename for minimum latitude and longitude values */
|
||||||
|
|
||||||
sscanf(sdf_file, "%d:%d:%d:%d", &minlat, &maxlat, &minlon,
|
if( sscanf(sdf_file, "%d:%d:%d:%d", &minlat, &maxlat, &minlon, &maxlon) != 4 )
|
||||||
&maxlon);
|
return -EINVAL;
|
||||||
|
|
||||||
|
|
||||||
sdf_file[x] = '.';
|
sdf_file[x] = '.';
|
||||||
sdf_file[x + 1] = 's';
|
sdf_file[x + 1] = 's';
|
||||||
@@ -402,20 +399,19 @@ int LoadSDF_SDF(char *name)
|
|||||||
if (free_page && found == 0 && indx >= 0 && indx < MAXPAGES) {
|
if (free_page && found == 0 && indx >= 0 && indx < MAXPAGES) {
|
||||||
/* Search for SDF file in current working directory first */
|
/* Search for SDF file in current working directory first */
|
||||||
|
|
||||||
strncpy(path_plus_name, sdf_file, 255);
|
strncpy(path_plus_name, sdf_file, sizeof(path_plus_name)-1);
|
||||||
|
|
||||||
fd = fopen(path_plus_name, "rb");
|
if( (fd = fopen(path_plus_name, "rb")) == NULL ){
|
||||||
|
|
||||||
if (fd == NULL) {
|
|
||||||
/* Next, try loading SDF file from path specified
|
/* Next, try loading SDF file from path specified
|
||||||
in $HOME/.ss_path file or by -d argument */
|
in $HOME/.ss_path file or by -d argument */
|
||||||
|
|
||||||
strncpy(path_plus_name, sdf_path, 255);
|
strncpy(path_plus_name, sdf_path, sizeof(path_plus_name)-1);
|
||||||
strncat(path_plus_name, sdf_file, 255);
|
strncat(path_plus_name, sdf_file, sizeof(path_plus_name)-1);
|
||||||
fd = fopen(path_plus_name, "rb");
|
if( (fd = fopen(path_plus_name, "rb")) == NULL ){
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd != NULL) {
|
|
||||||
if (debug == 1) {
|
if (debug == 1) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Loading \"%s\" into page %d...",
|
"Loading \"%s\" into page %d...",
|
||||||
@@ -424,19 +420,23 @@ int LoadSDF_SDF(char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(line, 19, fd) != NULL) {
|
if (fgets(line, 19, fd) != NULL) {
|
||||||
sscanf(line, "%f", &dem[indx].max_west);
|
if( sscanf(line, "%f", &dem[indx].max_west) == EOF )
|
||||||
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(line, 19, fd) != NULL) {
|
if (fgets(line, 19, fd) != NULL) {
|
||||||
sscanf(line, "%f", &dem[indx].min_north);
|
if( sscanf(line, "%f", &dem[indx].min_north) == EOF )
|
||||||
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(line, 19, fd) != NULL) {
|
if (fgets(line, 19, fd) != NULL) {
|
||||||
sscanf(line, "%f", &dem[indx].min_west);
|
if( sscanf(line, "%f", &dem[indx].min_west) == EOF )
|
||||||
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(line, 19, fd) != NULL) {
|
if (fgets(line, 19, fd) != NULL) {
|
||||||
sscanf(line, "%f", &dem[indx].max_north);
|
if( sscanf(line, "%f", &dem[indx].max_north) == EOF )
|
||||||
|
return -errno;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Here X lines of DEM will be read until IPPD is reached.
|
Here X lines of DEM will be read until IPPD is reached.
|
||||||
@@ -447,10 +447,11 @@ int LoadSDF_SDF(char *name)
|
|||||||
for (y = 0; y < ippd; y++) {
|
for (y = 0; y < ippd; y++) {
|
||||||
|
|
||||||
for (j = 0; j < jgets; j++) {
|
for (j = 0; j < jgets; j++) {
|
||||||
junk = fgets(jline, 19, fd);
|
if( fgets(jline, sizeof(jline), fd) == NULL )
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(line, 19, fd) != NULL) {
|
if (fgets(line, sizeof(line), fd) != NULL) {
|
||||||
data = atoi(line);
|
data = atoi(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,15 +469,18 @@ int LoadSDF_SDF(char *name)
|
|||||||
|
|
||||||
if (ippd == 600) {
|
if (ippd == 600) {
|
||||||
for (j = 0; j < IPPD; j++) {
|
for (j = 0; j < IPPD; j++) {
|
||||||
junk = fgets(jline, 19, fd);
|
if( fgets(jline, sizeof(jline), fd) == NULL )
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ippd == 300) {
|
if (ippd == 300) {
|
||||||
for (j = 0; j < IPPD; j++) {
|
for (j = 0; j < IPPD; j++) {
|
||||||
junk = fgets(jline, 19, fd);
|
if( fgets(jline, sizeof(jline), fd) == NULL )
|
||||||
junk = fgets(jline, 19, fd);
|
return -EIO;
|
||||||
junk = fgets(jline, 19, fd);
|
if( fgets(jline, sizeof(jline), fd) == NULL )
|
||||||
|
return -EIO;
|
||||||
|
if( fgets(jline, sizeof(jline), fd) == NULL )
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -534,15 +538,11 @@ int LoadSDF_SDF(char *name)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char LoadSDF(char *name)
|
int LoadSDF(char *name)
|
||||||
{
|
{
|
||||||
/* This function loads the requested SDF file from the filesystem.
|
/* This function loads the requested SDF file from the filesystem.
|
||||||
It first tries to invoke the LoadSDF_SDF() function to load an
|
It first tries to invoke the LoadSDF_SDF() function to load an
|
||||||
@@ -561,7 +561,7 @@ char LoadSDF(char *name)
|
|||||||
|
|
||||||
/* If neither format can be found, then assume the area is water. */
|
/* If neither format can be found, then assume the area is water. */
|
||||||
|
|
||||||
if (return_value == 0 || return_value == -1) {
|
if ( return_value == 0 || return_value < 0 ) {
|
||||||
|
|
||||||
|
|
||||||
sscanf(name, "%d:%d:%d:%d", &minlat, &maxlat, &minlon,
|
sscanf(name, "%d:%d:%d:%d", &minlat, &maxlat, &minlon,
|
||||||
@@ -668,14 +668,14 @@ char LoadSDF(char *name)
|
|||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadPAT(char *filename)
|
int LoadPAT(char *az_filename, char *el_filename)
|
||||||
{
|
{
|
||||||
/* This function reads and processes antenna pattern (.az
|
/* This function reads and processes antenna pattern (.az
|
||||||
and .el) files that correspond in name to previously
|
and .el) files that correspond in name to previously
|
||||||
loaded ss .lrp files. */
|
loaded ss .lrp files. */
|
||||||
|
|
||||||
int a, b, w, x, y, z, last_index, next_index, span;
|
int a, b, w, x, y, z, last_index, next_index, span;
|
||||||
char string[255], azfile[255], elfile[255], *pointer = NULL;
|
char string[255], *pointer = NULL;
|
||||||
float az, xx, elevation, amplitude, rotation, valid1, valid2,
|
float az, xx, elevation, amplitude, rotation, valid1, valid2,
|
||||||
delta, azimuth[361], azimuth_pattern[361], el_pattern[10001],
|
delta, azimuth[361], azimuth_pattern[361], el_pattern[10001],
|
||||||
elevation_pattern[361][1001], slant_angle[361], tilt,
|
elevation_pattern[361][1001], slant_angle[361], tilt,
|
||||||
@@ -683,21 +683,6 @@ void LoadPAT(char *filename)
|
|||||||
FILE *fd = NULL;
|
FILE *fd = NULL;
|
||||||
unsigned char read_count[10001];
|
unsigned char read_count[10001];
|
||||||
|
|
||||||
for (x = 0; filename[x] != '.' && filename[x] != 0 && x < 250; x++) {
|
|
||||||
azfile[x] = filename[x];
|
|
||||||
elfile[x] = filename[x];
|
|
||||||
}
|
|
||||||
|
|
||||||
azfile[x] = '.';
|
|
||||||
azfile[x + 1] = 'a';
|
|
||||||
azfile[x + 2] = 'z';
|
|
||||||
azfile[x + 3] = 0;
|
|
||||||
|
|
||||||
elfile[x] = '.';
|
|
||||||
elfile[x + 1] = 'e';
|
|
||||||
elfile[x + 2] = 'l';
|
|
||||||
elfile[x + 3] = 0;
|
|
||||||
|
|
||||||
rotation = 0.0;
|
rotation = 0.0;
|
||||||
|
|
||||||
got_azimuth_pattern = 0;
|
got_azimuth_pattern = 0;
|
||||||
@@ -705,9 +690,11 @@ void LoadPAT(char *filename)
|
|||||||
|
|
||||||
/* Load .az antenna pattern file */
|
/* Load .az antenna pattern file */
|
||||||
|
|
||||||
fd = fopen(azfile, "r");
|
if( az_filename != NULL && (fd = fopen(az_filename, "r")) == NULL && errno != ENOENT )
|
||||||
|
/* Any error other than file not existing is an error */
|
||||||
|
return errno;
|
||||||
|
|
||||||
if (fd != NULL) {
|
if( fd != NULL ){
|
||||||
/* Clear azimuth pattern array */
|
/* Clear azimuth pattern array */
|
||||||
|
|
||||||
for (x = 0; x <= 360; x++) {
|
for (x = 0; x <= 360; x++) {
|
||||||
@@ -767,6 +754,7 @@ void LoadPAT(char *filename)
|
|||||||
} while (feof(fd) == 0);
|
} while (feof(fd) == 0);
|
||||||
|
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
fd = NULL;
|
||||||
|
|
||||||
/* Handle 0=360 degree ambiguity */
|
/* Handle 0=360 degree ambiguity */
|
||||||
|
|
||||||
@@ -837,9 +825,12 @@ void LoadPAT(char *filename)
|
|||||||
|
|
||||||
/* Read and process .el file */
|
/* Read and process .el file */
|
||||||
|
|
||||||
fd = fopen(elfile, "r");
|
if( el_filename != NULL && (fd = fopen(el_filename, "r")) == NULL && errno != ENOENT )
|
||||||
|
/* Any error other than file not existing is an error */
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
if( fd != NULL ){
|
||||||
|
|
||||||
if (fd != NULL) {
|
|
||||||
for (x = 0; x <= 10000; x++) {
|
for (x = 0; x <= 10000; x++) {
|
||||||
el_pattern[x] = 0.0;
|
el_pattern[x] = 0.0;
|
||||||
read_count[x] = 0;
|
read_count[x] = 0;
|
||||||
@@ -1002,7 +993,6 @@ void LoadPAT(char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
got_elevation_pattern = 255;
|
got_elevation_pattern = 255;
|
||||||
}
|
|
||||||
|
|
||||||
for (x = 0; x <= 360; x++) {
|
for (x = 0; x <= 360; x++) {
|
||||||
for (y = 0; y <= 1000; y++) {
|
for (y = 0; y <= 1000; y++) {
|
||||||
@@ -1019,9 +1009,11 @@ void LoadPAT(char *filename)
|
|||||||
LR.antenna_pattern[x][y] = az * elevation;
|
LR.antenna_pattern[x][y] = az * elevation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSignalColors(struct site xmtr)
|
int LoadSignalColors(struct site xmtr)
|
||||||
{
|
{
|
||||||
int x, y, ok, val[4];
|
int x, y, ok, val[4];
|
||||||
char filename[255], string[80], *pointer = NULL, *s = NULL;
|
char filename[255], string[80], *pointer = NULL, *s = NULL;
|
||||||
@@ -1106,14 +1098,13 @@ void LoadSignalColors(struct site xmtr)
|
|||||||
|
|
||||||
region.levels = 13;
|
region.levels = 13;
|
||||||
|
|
||||||
fd = fopen(filename, "r");
|
|
||||||
|
|
||||||
if (fd == NULL && xmtr.filename[0] == '\0')
|
|
||||||
/* Don't save if we don't have an output file */
|
/* Don't save if we don't have an output file */
|
||||||
return;
|
if ( xmtr.filename[0] == '\0' && (fd = fopen(filename, "r")) == NULL )
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
fd = fopen(filename, "w");
|
if( (fd = fopen(filename, "w")) == NULL )
|
||||||
|
return errno;
|
||||||
|
|
||||||
for (x = 0; x < region.levels; x++)
|
for (x = 0; x < region.levels; x++)
|
||||||
fprintf(fd, "%3d: %3d, %3d, %3d\n", region.level[x],
|
fprintf(fd, "%3d: %3d, %3d, %3d\n", region.level[x],
|
||||||
@@ -1158,9 +1149,10 @@ void LoadSignalColors(struct site xmtr)
|
|||||||
fclose(fd);
|
fclose(fd);
|
||||||
region.levels = x;
|
region.levels = x;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadLossColors(struct site xmtr)
|
int LoadLossColors(struct site xmtr)
|
||||||
{
|
{
|
||||||
int x, y, ok, val[4];
|
int x, y, ok, val[4];
|
||||||
char filename[255], string[80], *pointer = NULL, *s = NULL;
|
char filename[255], string[80], *pointer = NULL, *s = NULL;
|
||||||
@@ -1260,14 +1252,13 @@ void LoadLossColors(struct site xmtr)
|
|||||||
|
|
||||||
region.levels = 16;
|
region.levels = 16;
|
||||||
|
|
||||||
fd = fopen(filename, "r");
|
if ( xmtr.filename[0] == '\0' && (fd = fopen(filename, "r")) == NULL )
|
||||||
|
|
||||||
if (fd == NULL && xmtr.filename[0] == '\0')
|
|
||||||
/* Don't save if we don't have an output file */
|
/* Don't save if we don't have an output file */
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
fd = fopen(filename, "w");
|
if( (fd = fopen(filename, "w")) == NULL )
|
||||||
|
return errno;
|
||||||
|
|
||||||
for (x = 0; x < region.levels; x++)
|
for (x = 0; x < region.levels; x++)
|
||||||
fprintf(fd, "%3d: %3d, %3d, %3d\n", region.level[x],
|
fprintf(fd, "%3d: %3d, %3d, %3d\n", region.level[x],
|
||||||
@@ -1312,9 +1303,10 @@ void LoadLossColors(struct site xmtr)
|
|||||||
fclose(fd);
|
fclose(fd);
|
||||||
region.levels = x;
|
region.levels = x;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadDBMColors(struct site xmtr)
|
int LoadDBMColors(struct site xmtr)
|
||||||
{
|
{
|
||||||
int x, y, ok, val[4];
|
int x, y, ok, val[4];
|
||||||
char filename[255], string[80], *pointer = NULL, *s = NULL;
|
char filename[255], string[80], *pointer = NULL, *s = NULL;
|
||||||
@@ -1414,14 +1406,13 @@ void LoadDBMColors(struct site xmtr)
|
|||||||
|
|
||||||
region.levels = 16;
|
region.levels = 16;
|
||||||
|
|
||||||
fd = fopen(filename, "r");
|
if ( (fd = fopen(filename, "r")) == NULL && xmtr.filename[0] == '\0' )
|
||||||
|
|
||||||
if (fd == NULL && xmtr.filename[0] == '\0')
|
|
||||||
/* Don't save if we don't have an output file */
|
/* Don't save if we don't have an output file */
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
fd = fopen(filename, "w");
|
if( (fd = fopen(filename, "w")) == NULL )
|
||||||
|
return errno;
|
||||||
|
|
||||||
for (x = 0; x < region.levels; x++)
|
for (x = 0; x < region.levels; x++)
|
||||||
fprintf(fd, "%+4d: %3d, %3d, %3d\n", region.level[x],
|
fprintf(fd, "%+4d: %3d, %3d, %3d\n", region.level[x],
|
||||||
@@ -1473,14 +1464,16 @@ void LoadDBMColors(struct site xmtr)
|
|||||||
fclose(fd);
|
fclose(fd);
|
||||||
region.levels = x;
|
region.levels = x;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void 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)
|
||||||
{
|
{
|
||||||
/* This function loads the SDF files required
|
/* This function loads the SDF files required
|
||||||
to cover the limits of the region specified. */
|
to cover the limits of the region specified. */
|
||||||
|
|
||||||
int x, y, width, ymin, ymax;
|
int x, y, width, ymin, ymax;
|
||||||
|
int success;
|
||||||
|
|
||||||
width = ReduceAngle(max_lon - min_lon);
|
width = ReduceAngle(max_lon - min_lon);
|
||||||
|
|
||||||
@@ -1512,7 +1505,9 @@ void LoadTopoData(int max_lon, int min_lon, int max_lat, int min_lat)
|
|||||||
snprintf(string, 16,
|
snprintf(string, 16,
|
||||||
"%d:%d:%d:%d", x,
|
"%d:%d:%d:%d", x,
|
||||||
x + 1, ymin, ymax);
|
x + 1, ymin, ymax);
|
||||||
LoadSDF(string);
|
if( (success = LoadSDF(string)) < 0 ){
|
||||||
|
return -success;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1543,12 +1538,15 @@ void LoadTopoData(int max_lon, int min_lon, int max_lat, int min_lat)
|
|||||||
snprintf(string, 16,
|
snprintf(string, 16,
|
||||||
"%d:%d:%d:%d", x,
|
"%d:%d:%d:%d", x,
|
||||||
x + 1, ymin, ymax);
|
x + 1, ymin, ymax);
|
||||||
LoadSDF(string);
|
if( (success = LoadSDF(string)) < 0 ){
|
||||||
|
return -success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
@@ -1563,13 +1561,19 @@ 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);
|
s = fgets(input, 78, fd1);
|
||||||
|
|
||||||
@@ -1645,10 +1649,14 @@ void LoadUDT(char *filename)
|
|||||||
|
|
||||||
fclose(fd1);
|
fclose(fd1);
|
||||||
fclose(fd2);
|
fclose(fd2);
|
||||||
close(fd);
|
|
||||||
|
|
||||||
fd1 = fopen(tempname, "r");
|
if( (fd1 = fopen(tempname, "r")) == NULL )
|
||||||
fd2 = fopen(tempname, "r");
|
return errno;
|
||||||
|
|
||||||
|
if( (fd2 = fopen(tempname, "r")) == NULL ){
|
||||||
|
fclose(fd1);
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
||||||
@@ -1696,6 +1704,5 @@ void LoadUDT(char *filename)
|
|||||||
fclose(fd1);
|
fclose(fd1);
|
||||||
fclose(fd2);
|
fclose(fd2);
|
||||||
unlink(tempname);
|
unlink(tempname);
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
17
inputs.hh
17
inputs.hh
@@ -4,14 +4,17 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
int LoadSDF_SDF(char *name, int winfiles);
|
int LoadSDF_SDF(char *name, int winfiles);
|
||||||
char LoadSDF(char *name, int winfiles);
|
int LoadSDF(char *name, int winfiles);
|
||||||
void LoadPAT(char *filename);
|
int LoadPAT(char *az_filename, char *el_filename);
|
||||||
void LoadSignalColors(struct site xmtr);
|
int LoadSignalColors(struct site xmtr);
|
||||||
void LoadLossColors(struct site xmtr);
|
int LoadLossColors(struct site xmtr);
|
||||||
void LoadDBMColors(struct site xmtr);
|
int LoadDBMColors(struct site xmtr);
|
||||||
void 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);
|
||||||
|
|
||||||
|
static const char AZ_FILE_SUFFIX[] = ".az";
|
||||||
|
static const char EL_FILE_SUFFIX[] = ".el";
|
||||||
|
|
||||||
#endif /* _INPUTS_HH_ */
|
#endif /* _INPUTS_HH_ */
|
||||||
|
69
main.cc
69
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"
|
||||||
@@ -1042,14 +1043,15 @@ int main(int argc, char *argv[])
|
|||||||
int x, y, z = 0, min_lat, min_lon, max_lat, max_lon,
|
int x, y, z = 0, min_lat, min_lon, max_lat, max_lon,
|
||||||
rxlat, rxlon, txlat, txlon, west_min, west_max,
|
rxlat, rxlon, txlat, txlon, west_min, west_max,
|
||||||
nortRxHin, nortRxHax, propmodel, knifeedge = 0, ppa =
|
nortRxHin, nortRxHax, propmodel, knifeedge = 0, ppa =
|
||||||
0, normalise = 0, haf = 0, pmenv = 1, lidar=0, cropped;
|
0, normalise = 0, haf = 0, pmenv = 1, lidar=0, cropped, result;
|
||||||
|
|
||||||
bool use_threads = true;
|
bool use_threads = true;
|
||||||
|
|
||||||
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, *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;
|
||||||
@@ -1141,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;
|
||||||
@@ -1218,7 +1220,26 @@ int main(int argc, char *argv[])
|
|||||||
strncpy(mapfile, argv[z], 253);
|
strncpy(mapfile, argv[z], 253);
|
||||||
strncpy(tx_site[0].name, "Tx", 2);
|
strncpy(tx_site[0].name, "Tx", 2);
|
||||||
strncpy(tx_site[0].filename, argv[z], 253);
|
strncpy(tx_site[0].filename, argv[z], 253);
|
||||||
LoadPAT(argv[z]);
|
/* Antenna pattern files have the same basic name as the output file
|
||||||
|
* but with a different extension. If they exist, load them now */
|
||||||
|
if( (az_filename = (char*) calloc(strlen(argv[z]) + strlen(AZ_FILE_SUFFIX) + 1, sizeof(char))) == NULL )
|
||||||
|
return ENOMEM;
|
||||||
|
strcpy(az_filename, argv[z]);
|
||||||
|
strcat(az_filename, AZ_FILE_SUFFIX);
|
||||||
|
if( (el_filename = (char*) calloc(strlen(argv[z]) + strlen(EL_FILE_SUFFIX) + 1, sizeof(char))) == NULL ){
|
||||||
|
free(az_filename);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
strcpy(el_filename, argv[z]);
|
||||||
|
strcat(el_filename, EL_FILE_SUFFIX);
|
||||||
|
if( (result = LoadPAT(az_filename,el_filename)) != 0 ){
|
||||||
|
fprintf(stderr,"Permissions error reading antenna pattern file\n");
|
||||||
|
free(az_filename);
|
||||||
|
free(el_filename);
|
||||||
|
exit(result);
|
||||||
|
}
|
||||||
|
free(az_filename);
|
||||||
|
free(el_filename);
|
||||||
} else if (z <= y && argv[z][0] && argv[z][0] == '-' && argv[z][1] == '\0' ) {
|
} else if (z <= y && argv[z][0] && argv[z][0] == '-' && argv[z][1] == '\0' ) {
|
||||||
/* Handle writing image data to stdout */
|
/* Handle writing image data to stdout */
|
||||||
to_stdout = true;
|
to_stdout = true;
|
||||||
@@ -1468,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1665,17 +1690,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Load the required tiles */
|
/* Load the required tiles */
|
||||||
if(lidar){
|
if(lidar){
|
||||||
int err;
|
if( (result = loadLIDAR(lidar_tiles)) != 0 ){
|
||||||
|
|
||||||
err = loadLIDAR(lidar_tiles);
|
|
||||||
if (err) {
|
|
||||||
fprintf(stderr, "Couldn't find one or more of the "
|
fprintf(stderr, "Couldn't find one or more of the "
|
||||||
"lidar files. Please ensure their paths are "
|
"lidar files. Please ensure their paths are "
|
||||||
"correct and try again.\n");
|
"correct and try again.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(debug){
|
if(debug){
|
||||||
fprintf(stderr,"%.4f,%.4f,%.4f,%.4f,%d x %d\n",max_north,min_west,min_north,max_west,width,height);
|
fprintf(stderr,"%.4f,%.4f,%.4f,%.4f,%d x %d\n",max_north,min_west,min_north,max_west,width,height);
|
||||||
}
|
}
|
||||||
@@ -1692,7 +1713,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
}else{
|
}else{
|
||||||
// DEM first
|
// DEM first
|
||||||
LoadTopoData(max_lon, min_lon, max_lat, min_lat);
|
if( (result = LoadTopoData(max_lon, min_lon, max_lat, min_lat)) != 0 ){
|
||||||
|
// This only fails on errors loading SDF tiles
|
||||||
|
fprintf(stderr, "Error loading topo data\n");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
if (area_mode || topomap) {
|
if (area_mode || topomap) {
|
||||||
for (z = 0; z < txsites && z < max_txsites; z++) {
|
for (z = 0; z < txsites && z < max_txsites; z++) {
|
||||||
@@ -1777,7 +1802,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Load any additional SDF files, if required */
|
/* Load any additional SDF files, if required */
|
||||||
|
|
||||||
LoadTopoData(max_lon, min_lon, max_lat, min_lat);
|
if( (result = LoadTopoData(max_lon, min_lon, max_lat, min_lat)) != 0 ){
|
||||||
|
// This only fails on errors loading SDF tiles
|
||||||
|
fprintf(stderr, "Error loading topo data\n");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ppd=(double)ippd;
|
ppd=(double)ippd;
|
||||||
yppd=ppd;
|
yppd=ppd;
|
||||||
@@ -1789,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){
|
||||||
@@ -1797,7 +1829,10 @@ int main(int argc, char *argv[])
|
|||||||
Clutter tiles cover 16 x 12 degs but we only need a fraction of that area.
|
Clutter tiles cover 16 x 12 degs but we only need a fraction of that area.
|
||||||
Limit by max_range / miles per degree (at equator)
|
Limit by max_range / miles per degree (at equator)
|
||||||
*/
|
*/
|
||||||
loadClutter(clutter_file,max_range/45,tx_site[0]);
|
if( (result = loadClutter(clutter_file,max_range/45,tx_site[0])) != 0 ){
|
||||||
|
fprintf(stderr, "Error, invalid or clutter file not found\n");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ppa == 0) {
|
if (ppa == 0) {
|
||||||
@@ -1844,8 +1879,8 @@ int main(int argc, char *argv[])
|
|||||||
DoRxdPwr((to_stdout == true ? NULL : mapfile), geo, kml, ngs, tx_site,
|
DoRxdPwr((to_stdout == true ? NULL : mapfile), geo, kml, ngs, tx_site,
|
||||||
txsites);
|
txsites);
|
||||||
else
|
else
|
||||||
DoSigStr(mapfile, geo, kml, ngs, tx_site,
|
if( (result = DoSigStr(mapfile, geo, kml, ngs, tx_site,txsites)) != 0 )
|
||||||
txsites);
|
return result;
|
||||||
}
|
}
|
||||||
if(lidar){
|
if(lidar){
|
||||||
east=eastoffset;
|
east=eastoffset;
|
||||||
|
23
outputs.cc
23
outputs.cc
@@ -34,7 +34,7 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml,
|
|||||||
image_ctx_t ctx;
|
image_ctx_t ctx;
|
||||||
int success;
|
int success;
|
||||||
|
|
||||||
if((success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0){
|
if( (success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0 ){
|
||||||
fprintf(stderr,"Error initializing image\n");
|
fprintf(stderr,"Error initializing image\n");
|
||||||
exit(success);
|
exit(success);
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,10 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml,
|
|||||||
255.0 / pow((double)(max_elevation - min_elevation),
|
255.0 / pow((double)(max_elevation - min_elevation),
|
||||||
one_over_gamma);
|
one_over_gamma);
|
||||||
|
|
||||||
LoadLossColors(xmtr[0]);
|
if( (success = LoadLossColors(xmtr[0])) != 0 ){
|
||||||
|
fprintf(stderr,"Error loading loss colors\n");
|
||||||
|
exit(success);
|
||||||
|
}
|
||||||
|
|
||||||
if( filename != NULL ) {
|
if( filename != NULL ) {
|
||||||
|
|
||||||
@@ -256,7 +259,7 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoSigStr(char *filename, unsigned char geo, unsigned char kml,
|
int DoSigStr(char *filename, unsigned char geo, unsigned char kml,
|
||||||
unsigned char ngs, struct site *xmtr, unsigned char txsites)
|
unsigned char ngs, struct site *xmtr, unsigned char txsites)
|
||||||
{
|
{
|
||||||
/* This function generates a topographic map in Portable Pix Map
|
/* This function generates a topographic map in Portable Pix Map
|
||||||
@@ -284,7 +287,10 @@ void DoSigStr(char *filename, unsigned char geo, unsigned char kml,
|
|||||||
255.0 / pow((double)(max_elevation - min_elevation),
|
255.0 / pow((double)(max_elevation - min_elevation),
|
||||||
one_over_gamma);
|
one_over_gamma);
|
||||||
|
|
||||||
LoadSignalColors(xmtr[0]);
|
if( (success = LoadSignalColors(xmtr[0])) != 0 ){
|
||||||
|
fprintf(stderr,"Error loading signal colors\n");
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
if( filename != NULL ) {
|
if( filename != NULL ) {
|
||||||
|
|
||||||
@@ -501,7 +507,7 @@ void 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,
|
||||||
@@ -522,7 +528,7 @@ void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,
|
|||||||
image_ctx_t ctx;
|
image_ctx_t ctx;
|
||||||
int success;
|
int success;
|
||||||
|
|
||||||
if((success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0){
|
if( (success = image_init(&ctx, width, (kml ? height : height + 30), IMAGE_RGB, IMAGE_DEFAULT)) != 0 ){
|
||||||
fprintf(stderr,"Error initializing image\n");
|
fprintf(stderr,"Error initializing image\n");
|
||||||
exit(success);
|
exit(success);
|
||||||
}
|
}
|
||||||
@@ -532,7 +538,10 @@ void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,
|
|||||||
255.0 / pow((double)(max_elevation - min_elevation),
|
255.0 / pow((double)(max_elevation - min_elevation),
|
||||||
one_over_gamma);
|
one_over_gamma);
|
||||||
|
|
||||||
LoadDBMColors(xmtr[0]);
|
if( (success = LoadDBMColors(xmtr[0])) != 0 ){
|
||||||
|
fprintf(stderr,"Error loading DBM colors\n");
|
||||||
|
exit(success);
|
||||||
|
}
|
||||||
|
|
||||||
if( filename != NULL ) {
|
if( filename != NULL ) {
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
void DoPathLoss(char *filename, unsigned char geo, unsigned char kml,
|
void DoPathLoss(char *filename, unsigned char geo, unsigned char kml,
|
||||||
unsigned char ngs, struct site *xmtr, unsigned char txsites);
|
unsigned char ngs, struct site *xmtr, unsigned char txsites);
|
||||||
void DoSigStr(char *filename, unsigned char geo, unsigned char kml,
|
int DoSigStr(char *filename, unsigned char geo, unsigned char kml,
|
||||||
unsigned char ngs, struct site *xmtr, unsigned char txsites);
|
unsigned char ngs, struct site *xmtr, unsigned char txsites);
|
||||||
void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,
|
void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml,
|
||||||
unsigned char ngs, struct site *xmtr, unsigned char txsites);
|
unsigned char ngs, struct site *xmtr, unsigned char txsites);
|
||||||
|
Reference in New Issue
Block a user