+ /* Default values */
+
+ region.level[0]=80;
+ region.color[0][0]=255;
+ region.color[0][1]=0;
+ region.color[0][2]=0;
+
+ region.level[1]=90;
+ region.color[1][0]=255;
+ region.color[1][1]=128;
+ region.color[1][2]=0;
+
+ region.level[2]=100;
+ region.color[2][0]=255;
+ region.color[2][1]=165;
+ region.color[2][2]=0;
+
+ region.level[3]=110;
+ region.color[3][0]=255;
+ region.color[3][1]=206;
+ region.color[3][2]=0;
+
+ region.level[4]=120;
+ region.color[4][0]=255;
+ region.color[4][1]=255;
+ region.color[4][2]=0;
+
+ region.level[5]=130;
+ region.color[5][0]=184;
+ region.color[5][1]=255;
+ region.color[5][2]=0;
+
+ region.level[6]=140;
+ region.color[6][0]=0;
+ region.color[6][1]=255;
+ region.color[6][2]=0;
+
+ region.level[7]=150;
+ region.color[7][0]=0;
+ region.color[7][1]=208;
+ region.color[7][2]=0;
+
+ region.level[8]=160;
+ region.color[8][0]=0;
+ region.color[8][1]=196;
+ region.color[8][2]=196;
+
+ region.level[9]=170;
+ region.color[9][0]=0;
+ region.color[9][1]=148;
+ region.color[9][2]=255;
+
+ region.level[10]=180;
+ region.color[10][0]=80;
+ region.color[10][1]=80;
+ region.color[10][2]=255;
+
+ region.level[11]=190;
+ region.color[11][0]=0;
+ region.color[11][1]=38;
+ region.color[11][2]=255;
+
+ region.level[12]=200;
+ region.color[12][0]=142;
+ region.color[12][1]=63;
+ region.color[12][2]=255;
+
+ region.level[13]=210;
+ region.color[13][0]=196;
+ region.color[13][1]=54;
+ region.color[13][2]=255;
+
+ region.level[14]=220;
+ region.color[14][0]=255;
+ region.color[14][1]=0;
+ region.color[14][2]=255;
+
+ region.level[15]=230;
+ region.color[15][0]=255;
+ region.color[15][1]=194;
+ region.color[15][2]=204;
+
+ region.levels=16;
+
+ fd=fopen("splat.lcf","r");
+
+ if (fd==NULL)
+ fd=fopen(filename,"r");
+
+ if (fd==NULL)
+ {
+ fd=fopen(filename,"w");
+
+ fprintf(fd,"; SPLAT! Auto-generated Path-Loss Color Definition (\"%s\") File\n",filename);
+ fprintf(fd,";\n; Format for the parameters held in this file is as follows:\n;\n");
+ fprintf(fd,"; dB: red, green, blue\n;\n");
+ fprintf(fd,"; ...where \"dB\" is the path loss (in dB) and\n");
+ fprintf(fd,"; \"red\", \"green\", and \"blue\" are the corresponding RGB color\n");
+ fprintf(fd,"; definitions ranging from 0 to 255 for the region specified.\n");
+ fprintf(fd,";\n; The following parameters may be edited and/or expanded\n");
+ fprintf(fd,"; for future runs of SPLAT! A total of 32 contour regions\n");
+ fprintf(fd,"; may be defined in this file.\n;\n;\n");
+
+ for (x=0; x<region.levels; x++)
+ fprintf(fd,"%3d: %3d, %3d, %3d\n",region.level[x], region.color[x][0], region.color[x][1], region.color[x][2]);
+
+ fclose(fd);
+ }
+
+ else
+ {
+ x=0;
+ fgets(string,80,fd);
+
+ while (x<32 && feof(fd)==0)
+ {
+ pointer=strchr(string,';');
+
+ if (pointer!=NULL)
+ *pointer=0;
+
+ ok=sscanf(string,"%d: %d, %d, %d", &val[0], &val[1], &val[2], &val[3]);
+
+ if (ok==4)
+ {
+ for (y=0; y<4; y++)
+ {
+ if (val[y]>255)
+ val[y]=255;
+
+ if (val[y]<0)
+ val[y]=0;
+ }
+
+ region.level[x]=val[0];
+ region.color[x][0]=val[1];
+ region.color[x][1]=val[2];
+ region.color[x][2]=val[3];
+ x++;
+ }
+
+ fgets(string,80,fd);
+ }
+
+ fclose(fd);
+ region.levels=x;
+ }
+}
+
+void WritePPM(char *filename, unsigned char geo, unsigned char kml, unsigned char ngs)
+{
+ /* This function generates a topographic map in Portable Pix Map
+ (PPM) format based on logarithmically scaled topology data,
+ as well as the content of flags held in the mask[][] array.
+ The image created is rotated counter-clockwise 90 degrees
+ from its representation in dem[][] so that north points
+ up and east points right in the image generated. */
+
+ char mapfile[255], geofile[255], kmlfile[255];
+ unsigned char found, mask;
+ unsigned width, height, terrain;
+ int indx, x, y, x0=0, y0=0;
+ double lat, lon, one_pixel, conversion, one_over_gamma; /* USED to be float... */
+ FILE *fd;
+
+ one_pixel=1.0/1200.0;
+ one_over_gamma=1.0/GAMMA;
+ conversion=255.0/pow((double)(max_elevation-min_elevation),one_over_gamma);
+
+ width=(unsigned)(1200*ReduceAngle(max_west-min_west));
+ height=(unsigned)(1200*ReduceAngle(max_north-min_north));
+
+ if (filename[0]==0)
+ strncpy(filename, "map.ppm\0",8);
+
+ for (x=0; filename[x]!='.' && filename[x]!=0 && x<250; x++)
+ {
+ mapfile[x]=filename[x];
+ geofile[x]=filename[x];
+ kmlfile[x]=filename[x];
+ }
+
+ mapfile[x]='.';
+ geofile[x]='.';
+ kmlfile[x]='.';
+ mapfile[x+1]='p';
+ geofile[x+1]='g';
+ kmlfile[x+1]='k';
+ mapfile[x+2]='p';
+ geofile[x+2]='e';
+ kmlfile[x+2]='m';
+ mapfile[x+3]='m';
+ geofile[x+3]='o';
+ kmlfile[x+3]='l';
+ mapfile[x+4]=0;
+ geofile[x+4]=0;
+ kmlfile[x+4]=0;
+
+ if (kml==0 && geo)
+ {
+ fd=fopen(geofile,"wb");
+
+ fprintf(fd,"FILENAME\t%s\n",mapfile);
+ fprintf(fd,"#\t\tX\tY\tLong\t\tLat\n");
+ fprintf(fd,"TIEPOINT\t0\t0\t%d.000\t\t%d.000\n",(max_west<180?-max_west:360-max_west),max_north);
+ fprintf(fd,"TIEPOINT\t%u\t%u\t%d.000\t\t%d.000\n",width-1,height-1,(min_west<180?-min_west:360-min_west),min_north);
+ fprintf(fd,"IMAGESIZE\t%u\t%u\n",width,height);
+ fprintf(fd,"#\n# Auto Generated by SPLAT! v%s\n#\n",splat_version);
+
+ fclose(fd);
+ }
+
+ if (kml && geo==0)
+ {
+ fd=fopen(kmlfile,"wb");
+
+ fprintf(fd,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ fprintf(fd,"<kml xmlns=\"http://earth.google.com/kml/2.1\">\n");
+ fprintf(fd," <Folder>\n");
+ fprintf(fd," <name>SPLAT!</name>\n");
+ fprintf(fd," <description>Line-of-Sight Overlay</description>\n");
+ fprintf(fd," <GroundOverlay>\n");
+ fprintf(fd," <name>SPLAT! Line-of-Sight Overlay</name>\n");
+ fprintf(fd," <description>SPLAT! Coverage</description>\n");
+ fprintf(fd," <Icon>\n");
+ fprintf(fd," <href>%s</href>\n",mapfile);
+ fprintf(fd," </Icon>\n");
+ fprintf(fd," <opacity>128</opacity>\n");
+ fprintf(fd," <LatLonBox>\n");
+ fprintf(fd," <north>%.5f</north>\n",(double)max_north-one_pixel);
+ fprintf(fd," <south>%.5f</south>\n",(double)min_north);
+ fprintf(fd," <east>%.5f</east>\n",((double)min_west<180.0?(double)-min_west:360.0-(double)min_west));
+ fprintf(fd," <west>%.5f</west>\n",(((double)max_west-one_pixel)<180.0?-((double)max_west-one_pixel):(360.0-(double)max_west-one_pixel)));
+ fprintf(fd," <rotation>0.0</rotation>\n");
+ fprintf(fd," </LatLonBox>\n");
+ fprintf(fd," </GroundOverlay>\n");
+ fprintf(fd," </Folder>\n");
+ fprintf(fd,"</kml>\n");
+
+ fclose(fd);
+ }
+
+ fd=fopen(mapfile,"wb");
+
+ fprintf(fd,"P6\n%u %u\n255\n",width,height);
+ fprintf(stdout,"\nWriting \"%s\" (%ux%u pixmap image)... ",mapfile,width,height);
+ fflush(stdout);
+
+ for (y=0, lat=(double)max_north-one_pixel; y<(int)height; y++, lat=(double)max_north-(one_pixel*(double)y))
+ {
+ for (x=0, lon=(double)max_west-one_pixel; x<(int)width; x++, lon=(double)max_west-(one_pixel*(double)x))
+ {
+ if (lon<0.0)
+ lon+=360.0;
+
+ for (indx=0, found=0; indx<MAXPAGES && found==0;)
+ if (lat>=(double)dem[indx].min_north && lat<(double)dem[indx].max_north && LonDiff(lon,(double)dem[indx].min_west)>=0.0 && LonDiff(lon,(double)dem[indx].max_west)<0.0)
+ found=1;
+ else
+ indx++;
+
+ if (found)
+ {
+ x0=(int)(1199.0*(lat-floor(lat)));
+ y0=(int)(1199.0*(lon-floor(lon)));
+
+ mask=dem[indx].mask[x0][y0];
+
+ if (mask&2)
+ /* Text Labels: Red */
+ fprintf(fd,"%c%c%c",255,0,0);
+
+ else if (mask&4)
+ /* County Boundaries: Light Cyan */
+ fprintf(fd,"%c%c%c",128,128,255);
+
+ else switch (mask&57)
+ {
+ case 1:
+ /* TX1: Green */
+ fprintf(fd,"%c%c%c",0,255,0);
+ break;
+
+ case 8:
+ /* TX2: Cyan */
+ fprintf(fd,"%c%c%c",0,255,255);
+ break;
+
+ case 9:
+ /* TX1 + TX2: Yellow */
+ fprintf(fd,"%c%c%c",255,255,0);
+ break;
+
+ case 16:
+ /* TX3: Medium Violet */
+ fprintf(fd,"%c%c%c",147,112,219);
+ break;