diff --git a/inputs.cc b/inputs.cc index 9245766..8d034df 100644 --- a/inputs.cc +++ b/inputs.cc @@ -45,8 +45,8 @@ int loadClutter(char *filename, double radius, struct site tx) return 0; // can't work with this yet } if (debug) { - fprintf(stdout, "\nLoading clutter file \"%s\" %d x %d...\n", filename, w,h); - fflush(stdout); + fprintf(stderr, "\nLoading clutter file \"%s\" %d x %d...\n", filename, w,h); + fflush(stderr); } if (fgets(line, 25, fd) != NULL) { sscanf(pch, "%lf", &xll); @@ -58,8 +58,8 @@ int loadClutter(char *filename, double radius, struct site tx) } if (debug) { - fprintf(stdout, "\nxll %.2f yll %.2f\n", xll, yll); - fflush(stdout); + fprintf(stderr, "\nxll %.2f yll %.2f\n", xll, yll); + fflush(stderr); } fgets(line, 25, fd); // cellsize @@ -117,7 +117,7 @@ int loadClutter(char *filename, double radius, struct site tx) pch = strtok(NULL, " "); }//while } else { - fprintf(stdout, "Clutter error @ x %d y %d\n", x, y); + fprintf(stderr, "Clutter error @ x %d y %d\n", x, y); }//if }//for } @@ -204,7 +204,7 @@ void readLIDAR(FILE *fd, int h, int w, int indx,double n, double e, double s, do } else { - fprintf(stdout, "LIDAR error @ x %d y %d indx %d\n", + fprintf(stderr, "LIDAR error @ x %d y %d indx %d\n", x, y, indx); }//if }//for @@ -244,8 +244,8 @@ int loadLIDAR(char *filenames) width = atoi(pch); // ncols if (debug) { - fprintf(stdout, "Loading \"%s\" into page %d with width %d...\n", files[indx], indx, width); - fflush(stdout); + fprintf(stderr, "Loading \"%s\" into page %d with width %d...\n", files[indx], indx, width); + fflush(stderr); } if (fgets(line, 255, fd) != NULL) @@ -297,7 +297,7 @@ int loadLIDAR(char *filenames) westoffset = xll; if (debug) - fprintf(stdout,"%d, %d, %.7f, %.7f, %.7f, %.7f, %.7f\n",width,height,xll,yll,cellsize,yur,xur); + fprintf(stderr,"%d, %d, %.7f, %.7f, %.7f, %.7f, %.7f\n",width,height,xll,yll,cellsize,yur,xur); // Greenwich straddling hack @@ -317,7 +317,7 @@ int loadLIDAR(char *filenames) xur = xur * -1; } if (debug) - fprintf(stdout, "POST yll %.7f yur %.7f xur %.7f xll %.7f delta %.6f\n", yll, yur, xur, xll, delta); + fprintf(stderr, "POST yll %.7f yur %.7f xur %.7f xll %.7f delta %.6f\n", yll, yur, xur, xll, delta); fgets(line, 255, fd); // NODATA @@ -325,13 +325,13 @@ int loadLIDAR(char *filenames) // tile 0 [x| ] if (debug) - fprintf(stdout, "readLIDAR(fd,%d,%d,%d,%.4f,%.4f,%.4f,%.4f)\n", height, width, indx, yur, xur, yll, xll); + fprintf(stderr, "readLIDAR(fd,%d,%d,%d,%.4f,%.4f,%.4f,%.4f)\n", height, width, indx, yur, xur, yll, xll); readLIDAR(fd, height, width, indx, yur, xur, yll, xll); fclose(fd); if (debug) - fprintf(stdout, "LIDAR LOADED %d x %d\n", width, height); + fprintf(stderr, "LIDAR LOADED %d x %d\n", width, height); } else { return -1; } @@ -343,7 +343,7 @@ int loadLIDAR(char *filenames) width = (unsigned)((max_west-min_west) / cellsize); if (debug) - fprintf(stdout, "fc %d WIDTH %d HEIGHT %d ippd %d minN %.5f maxN %.5f minW %.5f maxW %.5f avgCellsize %.5f\n", fc, width, height, ippd,min_north,max_north,min_west,max_west,avgCellsize); + fprintf(stderr, "fc %d WIDTH %d HEIGHT %d ippd %d minN %.5f maxN %.5f minW %.5f maxW %.5f avgCellsize %.5f\n", fc, width, height, ippd,min_north,max_north,min_west,max_west,avgCellsize); return 0; } @@ -417,10 +417,10 @@ int LoadSDF_SDF(char *name) if (fd != NULL) { if (debug == 1) { - fprintf(stdout, + fprintf(stderr, "Loading \"%s\" into page %d...", path_plus_name, indx + 1); - fflush(stdout); + fflush(stderr); } if (fgets(line, 19, fd) != NULL) { @@ -590,10 +590,10 @@ char LoadSDF(char *name) if (free_page && found == 0 && indx >= 0 && indx < MAXPAGES) { if (debug == 1) { - fprintf(stdout, - "Region \"%s\" assumed as sea-level into page %d...", + fprintf(stderr, + "Region \"%s\" assumed as sea-level into page %d...\n", name, indx + 1); - fflush(stdout); + fflush(stderr); } dem[indx].max_west = maxlon; @@ -720,7 +720,7 @@ void LoadPAT(char *filename) from true North. */ if (fgets(string, 254, fd) == NULL) { - //fprintf(stdout,"Azimuth read error\n"); + //fprintf(stderr,"Azimuth read error\n"); //exit(0); } pointer = strchr(string, ';'); @@ -735,7 +735,7 @@ void LoadPAT(char *filename) (0.0 to 1.0) until EOF is reached. */ if (fgets(string, 254, fd) == NULL) { - //fprintf(stdout,"Azimuth read error\n"); + //fprintf(stderr,"Azimuth read error\n"); //exit(0); } pointer = strchr(string, ';'); @@ -754,7 +754,7 @@ void LoadPAT(char *filename) } if (fgets(string, 254, fd) == NULL) { - //fprintf(stdout,"Azimuth read error\n"); + //fprintf(stderr,"Azimuth read error\n"); // exit(0); } pointer = strchr(string, ';'); @@ -850,7 +850,7 @@ void LoadPAT(char *filename) clockwise from true North. */ if (fgets(string, 254, fd) == NULL) { - //fprintf(stdout,"Tilt read error\n"); + //fprintf(stderr,"Tilt read error\n"); //exit(0); } pointer = strchr(string, ';'); @@ -865,7 +865,7 @@ void LoadPAT(char *filename) (0.0 to 1.0) until EOF is reached. */ if (fgets(string, 254, fd) == NULL) { - //fprintf(stdout,"Ant elevation read error\n"); + //fprintf(stderr,"Ant elevation read error\n"); //exit(0); } pointer = strchr(string, ';'); @@ -1108,8 +1108,9 @@ void LoadSignalColors(struct site xmtr) fd = fopen(filename, "r"); - if (fd == NULL) - fd = fopen(filename, "r"); + if (fd == NULL && xmtr.filename[0] == '\0') + /* Don't save if we don't have an output file */ + return; if (fd == NULL) { fd = fopen(filename, "w"); @@ -1261,8 +1262,9 @@ void LoadLossColors(struct site xmtr) fd = fopen(filename, "r"); - if (fd == NULL) - fd = fopen(filename, "r"); + if (fd == NULL && xmtr.filename[0] == '\0') + /* Don't save if we don't have an output file */ + return; if (fd == NULL) { fd = fopen(filename, "w"); @@ -1414,8 +1416,9 @@ void LoadDBMColors(struct site xmtr) fd = fopen(filename, "r"); - if (fd == NULL) - fd = fopen(filename, "r"); + if (fd == NULL && xmtr.filename[0] == '\0') + /* Don't save if we don't have an output file */ + return; if (fd == NULL) { fd = fopen(filename, "w"); @@ -1678,10 +1681,10 @@ void LoadUDT(char *filename) if (z == 0) /* No duplicate found */ - //fprintf(stdout,"%lf, %lf \n",xpix*dpp, ypix*dpp); - fflush(stdout); + //fprintf(stderr,"%lf, %lf \n",xpix*dpp, ypix*dpp); + fflush(stderr); AddElevation(xpix * dpp, ypix * dpp, height, 1); - fflush(stdout); + fflush(stderr); n = fscanf(fd1, "%d, %d, %lf", &xpix, &ypix, &height); y++; diff --git a/main.cc b/main.cc index 20bb00c..d5c2902 100644 --- a/main.cc +++ b/main.cc @@ -27,6 +27,7 @@ double version = 2.95; #include #include #include +#include #include "common.h" #include "inputs.hh" @@ -54,6 +55,8 @@ int ippd, mpi, unsigned char got_elevation_pattern, got_azimuth_pattern, metric = 0, dbm = 0; +bool to_stdout = false; + __thread double *elev; __thread struct path path; struct site tx_site[2]; @@ -1197,7 +1200,13 @@ int main(int argc, char *argv[]) strncpy(tx_site[0].name, "Tx", 2); strncpy(tx_site[0].filename, argv[z], 253); LoadPAT(argv[z]); - + } else if (z <= y && argv[z][0] && argv[z][0] == '-' && argv[z][1] == '\0' ) { + /* Handle writing image data to stdout */ + to_stdout = true; + mapfile[0] = '\0'; + strncpy(tx_site[0].name, "Tx", 2); + tx_site[0].filename[0] = '\0'; + fprintf(stderr,"Writing to stdout\n"); } } @@ -1497,66 +1506,72 @@ int main(int argc, char *argv[]) /* ERROR DETECTION */ if (tx_site[0].lat > 90 || tx_site[0].lat < -90) { - fprintf(stdout, + fprintf(stderr, "ERROR: Either the lat was missing or out of range!"); - exit(0); + exit(EINVAL); } if (tx_site[0].lon > 360 || tx_site[0].lon < 0) { - fprintf(stdout, + fprintf(stderr, "ERROR: Either the lon was missing or out of range!"); - exit(0); + exit(EINVAL); } if (LR.frq_mhz < 20 || LR.frq_mhz > 100000) { - fprintf(stdout, + fprintf(stderr, "ERROR: Either the Frequency was missing or out of range!"); - exit(0); + exit(EINVAL); } if (LR.erp > 500000000) { - fprintf(stdout, "ERROR: Power was out of range!"); - exit(0); + fprintf(stderr, "ERROR: Power was out of range!"); + exit(EINVAL); } if (LR.eps_dielect > 80 || LR.eps_dielect < 0.1) { - fprintf(stdout, "ERROR: Ground Dielectric value out of range!"); - exit(0); + fprintf(stderr, "ERROR: Ground Dielectric value out of range!"); + exit(EINVAL); } if (LR.sgm_conductivity > 0.01 || LR.sgm_conductivity < 0.000001) { - fprintf(stdout, "ERROR: Ground conductivity out of range!"); - exit(0); + fprintf(stderr, "ERROR: Ground conductivity out of range!"); + exit(EINVAL); } if (tx_site[0].alt < 0 || tx_site[0].alt > 60000) { - fprintf(stdout, + fprintf(stderr, "ERROR: Tx altitude above ground was too high: %f", tx_site[0].alt); - exit(0); + exit(EINVAL); } if (altitudeLR < 0 || altitudeLR > 60000) { - fprintf(stdout, + fprintf(stderr, "ERROR: Rx altitude above ground was too high!"); - exit(0); + exit(EINVAL); } if(!lidar){ if (ippd < 300 || ippd > 10000) { - fprintf(stdout, "ERROR: resolution out of range!"); - exit(0); + fprintf(stderr, "ERROR: resolution out of range!"); + exit(EINVAL); } } if (contour_threshold < -200 || contour_threshold > 200) { - fprintf(stdout, + fprintf(stderr, "ERROR: Receiver threshold out of range (-200 / +200)"); - exit(0); + exit(EINVAL); } if (propmodel > 2 && propmodel < 7 && LR.frq_mhz < 150) { - fprintf(stdout, + fprintf(stderr, "ERROR: Frequency too low for Propagation model"); - exit(0); + exit(EINVAL); + } + + if (to_stdout == true && ppa != 0) { + fprintf(stderr, + "ERROR: Cannot write to stdout in ppa mode"); + exit(EINVAL); } if (metric) { @@ -1627,7 +1642,7 @@ int main(int argc, char *argv[]) err = loadLIDAR(lidar_tiles); if (err) { - fprintf(stdout, "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 " "correct and try again.\n"); exit(EXIT_FAILURE); @@ -1635,7 +1650,7 @@ int main(int argc, char *argv[]) if(debug){ - fprintf(stdout,"%.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); } ppd=rint(height / (max_north-min_north)); yppd=rint(width / (max_west-min_west)); @@ -1768,7 +1783,7 @@ int main(int argc, char *argv[]) propmodel, knifeedge, haf, pmenv, use_threads); if(debug) - fprintf(stdout,"Finished PlotPropagation()\n"); + fprintf(stderr,"Finished PlotPropagation()\n"); if(!lidar){ if (LR.erp == 0.0) @@ -1786,13 +1801,13 @@ int main(int argc, char *argv[]) } } - + // Write bitmap if (LR.erp == 0.0) DoPathLoss(mapfile, geo, kml, ngs, tx_site, txsites); else if (dbm) - DoRxdPwr(mapfile, geo, kml, ngs, tx_site, + DoRxdPwr((to_stdout == true ? NULL : mapfile), geo, kml, ngs, tx_site, txsites); else DoSigStr(mapfile, geo, kml, ngs, tx_site, @@ -1805,10 +1820,11 @@ int main(int argc, char *argv[]) } // Print WGS84 bounds - fprintf(stdout, "|%.6f", north); - fprintf(stdout, "|%.6f", east); - fprintf(stdout, "|%.6f", south); - fprintf(stdout, "|%.6f|", west); + fprintf(stderr, "|%.6f", north); + fprintf(stderr, "|%.6f", east); + fprintf(stderr, "|%.6f", south); + fprintf(stderr, "|%.6f|", west); + fprintf(stderr, "\n"); } else { strncpy(tx_site[0].name, "Tx", 3); @@ -1819,7 +1835,7 @@ int main(int argc, char *argv[]) SeriesData(tx_site[1], tx_site[0], tx_site[0].filename, 1, normalise); } - fflush(stdout); + fflush(stderr); return 0; } diff --git a/models/los.cc b/models/los.cc index 7b47ff4..d4655f8 100644 --- a/models/los.cc +++ b/models/los.cc @@ -766,17 +766,17 @@ void PlotPropagation(struct site source, double altitude, char *plo_filename, FILE *fd = NULL; if (LR.erp == 0.0 && debug) - fprintf(stdout, "path loss"); + fprintf(stderr, "path loss"); else { if (debug) { if (dbm) - fprintf(stdout, "signal power level"); + fprintf(stderr, "signal power level"); else - fprintf(stdout, "field strength"); + fprintf(stderr, "field strength"); } } if (debug) { - fprintf(stdout, + fprintf(stderr, " contours of \"%s\"\nout to a radius of %.2f %s with Rx antenna(s) at %.2f %s AGL\n", source.name, metric ? max_range * KM_PER_MILE : max_range, @@ -786,7 +786,7 @@ void PlotPropagation(struct site source, double altitude, char *plo_filename, } if (clutter > 0.0 && debug) - fprintf(stdout, "\nand %.2f %s of ground clutter", + fprintf(stderr, "\nand %.2f %s of ground clutter", metric ? clutter * METERS_PER_FOOT : clutter, metric ? "meters" : "feet"); diff --git a/outputs.cc b/outputs.cc index 4e4ed95..77b4a8c 100644 --- a/outputs.cc +++ b/outputs.cc @@ -38,29 +38,40 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml, LoadLossColors(xmtr[0]); - if (filename[0] == 0) { - strncpy(filename, xmtr[0].filename, 254); - filename[strlen(filename) - 4] = 0; /* Remove .qth */ + if( filename != NULL ) { + + if (filename[0] == 0) { + strncpy(filename, xmtr[0].filename, 254); + filename[strlen(filename) - 4] = 0; /* Remove .qth */ + } + + y = strlen(filename); + + if (y > 4) { + if (filename[y - 1] == 'm' && filename[y - 2] == 'p' + && filename[y - 3] == 'p' && filename[y - 4] == '.') + y -= 4; + } + + for (x = 0; x < y; x++) { + mapfile[x] = filename[x]; + } + + mapfile[x] = '.'; + mapfile[x + 1] = 'p'; + mapfile[x + 2] = 'p'; + mapfile[x + 3] = 'm'; + mapfile[x + 4] = 0; + + fd = fopen(mapfile,"wb"); + + } else { + + fprintf(stderr,"Writing to stdout\n"); + fd = stdout; + } - y = strlen(filename); - - if (y > 4) { - if (filename[y - 1] == 'm' && filename[y - 2] == 'p' - && filename[y - 3] == 'p' && filename[y - 4] == '.') - y -= 4; - } - - for (x = 0; x < y; x++) { - mapfile[x] = filename[x]; - } - - mapfile[x] = '.'; - mapfile[x + 1] = 'p'; - mapfile[x + 2] = 'p'; - mapfile[x + 3] = 'm'; - mapfile[x + 4] = 0; - minwest = ((double)min_west) + dpp; if (minwest > 360.0) @@ -76,14 +87,13 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml, east = (minwest < 180.0 ? -minwest : 360.0 - min_west); west = (double)(max_west < 180 ? -max_west : 360 - max_west); - fd = fopen(mapfile, "wb"); - fprintf(fd, "P6\n%u %u\n255\n", width, (kml ? height : height + 30)); if (debug) { - fprintf(stdout, "\nWriting \"%s\" (%ux%u pixmap image)... ", - mapfile, width, (kml ? height : height + 30)); - fflush(stdout); + fprintf(stderr, "\nWriting \"%s\" (%ux%u pixmap image)...\n", + filename != NULL ? mapfile : "to stdout", width, (kml ? height : height + 30)); + fflush(stderr); } + for (y = 0, lat = north; y < (int)height; y++, lat = north - (dpp * (double)y)) { for (x = 0, lon = max_west; x < (int)width; @@ -242,7 +252,10 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml, } } - fclose(fd); + if( filename != NULL ) { + fclose(fd); + fd = NULL; + } } @@ -269,29 +282,40 @@ void DoSigStr(char *filename, unsigned char geo, unsigned char kml, LoadSignalColors(xmtr[0]); - if (filename[0] == 0) { - strncpy(filename, xmtr[0].filename, 254); - filename[strlen(filename) - 4] = 0; /* Remove .qth */ + if( filename != NULL ) { + + if (filename[0] == 0) { + strncpy(filename, xmtr[0].filename, 254); + filename[strlen(filename) - 4] = 0; /* Remove .qth */ + } + + y = strlen(filename); + + if (y > 4) { + if (filename[y - 1] == 'm' && filename[y - 2] == 'p' + && filename[y - 3] == 'p' && filename[y - 4] == '.') + y -= 4; + } + + for (x = 0; x < y; x++) { + mapfile[x] = filename[x]; + } + + mapfile[x] = '.'; + mapfile[x + 1] = 'p'; + mapfile[x + 2] = 'p'; + mapfile[x + 3] = 'm'; + mapfile[x + 4] = 0; + + fd = fopen(mapfile,"wb"); + + } else { + + fprintf(stderr,"Writing to stdout\n"); + fd = stdout; + } - y = strlen(filename); - - if (y > 4) { - if (filename[y - 1] == 'm' && filename[y - 2] == 'p' - && filename[y - 3] == 'p' && filename[y - 4] == '.') - y -= 4; - } - - for (x = 0; x < y; x++) { - mapfile[x] = filename[x]; - } - - mapfile[x] = '.'; - mapfile[x + 1] = 'p'; - mapfile[x + 2] = 'p'; - mapfile[x + 3] = 'm'; - mapfile[x + 4] = 0; - minwest = ((double)min_west) + dpp; if (minwest > 360.0) @@ -303,14 +327,14 @@ void DoSigStr(char *filename, unsigned char geo, unsigned char kml, east = (minwest < 180.0 ? -minwest : 360.0 - min_west); west = (double)(max_west < 180 ? -max_west : 360 - max_west); - fd = fopen(mapfile, "wb"); fprintf(fd, "P6\n%u %u\n255\n", width, (kml ? height : height + 30)); if (debug) { - fprintf(stdout, "\nWriting \"%s\" (%ux%u pixmap image)... ", - mapfile, width, (kml ? height : height + 30)); - fflush(stdout); + fprintf(stderr, "\nWriting \"%s\" (%ux%u pixmap image)...\n", + filename != NULL ? mapfile : "to stdout", width, (kml ? height : height + 30)); + fflush(stderr); } + for (y = 0, lat = north; y < (int)height; y++, lat = north - (dpp * (double)y)) { for (x = 0, lon = max_west; x < (int)width; @@ -483,7 +507,10 @@ void DoSigStr(char *filename, unsigned char geo, unsigned char kml, } } - fclose(fd); + if( filename != NULL ) { + fclose(fd); + fd = NULL; + } } @@ -510,29 +537,40 @@ void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml, LoadDBMColors(xmtr[0]); - if (filename[0] == 0) { - strncpy(filename, xmtr[0].filename, 254); - filename[strlen(filename) - 4] = 0; /* Remove .qth */ + if( filename != NULL ) { + + if (filename[0] == 0) { + strncpy(filename, xmtr[0].filename, 254); + filename[strlen(filename) - 4] = 0; /* Remove .qth */ + } + + y = strlen(filename); + + if (y > 4) { + if (filename[y - 1] == 'm' && filename[y - 2] == 'p' + && filename[y - 3] == 'p' && filename[y - 4] == '.') + y -= 4; + } + + for (x = 0; x < y; x++) { + mapfile[x] = filename[x]; + } + + mapfile[x] = '.'; + mapfile[x + 1] = 'p'; + mapfile[x + 2] = 'p'; + mapfile[x + 3] = 'm'; + mapfile[x + 4] = 0; + + fd = fopen(mapfile,"wb"); + + } else { + + fprintf(stderr,"Writing to stdout\n"); + fd = stdout; + } - y = strlen(filename); - - if (y > 4) { - if (filename[y - 1] == 'm' && filename[y - 2] == 'p' - && filename[y - 3] == 'p' && filename[y - 4] == '.') - y -= 4; - } - - for (x = 0; x < y; x++) { - mapfile[x] = filename[x]; - } - - mapfile[x] = '.'; - mapfile[x + 1] = 'p'; - mapfile[x + 2] = 'p'; - mapfile[x + 3] = 'm'; - mapfile[x + 4] = 0; - minwest = ((double)min_west) + dpp; if (minwest > 360.0) @@ -545,13 +583,11 @@ void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml, east = (minwest < 180.0 ? -minwest : 360.0 - min_west); west = (double)(max_west < 180 ? -max_west : 360 - max_west); - fd = fopen(mapfile, "wb"); - fprintf(fd, "P6\n%u %u\n255\n", width, (kml ? height : height)); if (debug) { - fprintf(stdout, "\nWriting \"%s\" (%ux%u pixmap image)...\n", - mapfile, width, (kml ? height : height)); - fflush(stdout); + fprintf(stderr, "\nWriting \"%s\" (%ux%u pixmap image)...\n", + (filename != NULL ? mapfile : "to stdout"), width, (kml ? height : height)); + fflush(stderr); } // Draw image of x by y pixels @@ -719,8 +755,12 @@ void DoRxdPwr(char *filename, unsigned char geo, unsigned char kml, } } + fflush(fd); - fclose(fd); + if( filename != NULL ) { + fclose(fd); + fd = NULL; + } } @@ -745,29 +785,40 @@ void DoLOS(char *filename, unsigned char geo, unsigned char kml, 255.0 / pow((double)(max_elevation - min_elevation), one_over_gamma); - if (filename[0] == 0) { - strncpy(filename, xmtr[0].filename, 254); - filename[strlen(filename) - 4] = 0; /* Remove .qth */ + if( filename != NULL ){ + + if (filename[0] == 0) { + strncpy(filename, xmtr[0].filename, 254); + filename[strlen(filename) - 4] = 0; /* Remove .qth */ + } + + y = strlen(filename); + + if (y > 4) { + if (filename[y - 1] == 'm' && filename[y - 2] == 'p' + && filename[y - 3] == 'p' && filename[y - 4] == '.') + y -= 4; + } + + for (x = 0; x < y; x++) { + mapfile[x] = filename[x]; + } + + mapfile[x] = '.'; + mapfile[x + 1] = 'p'; + mapfile[x + 2] = 'p'; + mapfile[x + 3] = 'm'; + mapfile[x + 4] = 0; + + fd = fopen(mapfile,"wb"); + + } else { + + fprintf(stderr,"Writing to stdout\n"); + fd = stdout; + } - y = strlen(filename); - - if (y > 4) { - if (filename[y - 1] == 'm' && filename[y - 2] == 'p' - && filename[y - 3] == 'p' && filename[y - 4] == '.') - y -= 4; - } - - for (x = 0; x < y; x++) { - mapfile[x] = filename[x]; - } - - mapfile[x] = '.'; - mapfile[x + 1] = 'p'; - mapfile[x + 2] = 'p'; - mapfile[x + 3] = 'm'; - mapfile[x + 4] = 0; - minwest = ((double)min_west) + dpp; if (minwest > 360.0) @@ -780,13 +831,11 @@ void DoLOS(char *filename, unsigned char geo, unsigned char kml, east = (minwest < 180.0 ? -minwest : 360.0 - min_west); west = (double)(max_west < 180 ? -max_west : 360 - max_west); - fd = fopen(mapfile, "wb"); - fprintf(fd, "P6\n%u %u\n255\n", width, (kml ? height : height + 30)); if (debug) { - fprintf(stdout, "\nWriting \"%s\" (%ux%u pixmap image)... ", - mapfile, width, (kml ? height : height + 30)); - fflush(stdout); + fprintf(stderr, "\nWriting \"%s\" (%ux%u pixmap image)...\n", + filename != NULL ? mapfile : "to stdout", width, (kml ? height : height + 30)); + fflush(stderr); } for (y = 0, lat = north; y < (int)height; @@ -954,7 +1003,10 @@ void DoLOS(char *filename, unsigned char geo, unsigned char kml, } } - fclose(fd); + if( filename != NULL) { + fclose(fd); + fd = NULL; + } } @@ -1622,7 +1674,7 @@ void PathReport(struct site source, struct site destination, char *name, fclose(fd2); - fprintf(stdout, + fprintf(stderr, "Path loss (dB), Received Power (dBm), Field strength (dBuV):\n%.1f\n%.1f\n%.1f", loss, dBm, field_strength); @@ -1992,7 +2044,7 @@ void SeriesData(struct site source, struct site destination, char *name, } } - fprintf(stdout, "\n"); - fflush(stdout); + fprintf(stderr, "\n"); + fflush(stderr); }