X-Git-Url: https://git.gag.com/?p=debian%2Fsplat;a=blobdiff_plain;f=utils%2Fsrtm2sdf.c;fp=utils%2Fsrtm2sdf.c;h=c955eb9ca15df2fce673804c735c0fecf907178b;hp=0d29b41da17d080ed8f77aad2c12c48267b36707;hb=68a3cad00312b42922f10cc4822349802f50ed20;hpb=0fe7930a10436ce250cae6daf2077415f8727af6 diff --git a/utils/srtm2sdf.c b/utils/srtm2sdf.c index 0d29b41..c955eb9 100644 --- a/utils/srtm2sdf.c +++ b/utils/srtm2sdf.c @@ -1,12 +1,13 @@ /**************************************************************\ - ** Created originally by Jonathan Naylor, G4KLX ** + ** Created originally by Jonathan Naylor, G4KLX. ** ** Later embellished by John Magliacane, KD2BD to ** - ** detect and handle voids found in the SRTM data ** - ** and to handle SRTM data in .BIL as well as .HGT format. ** + ** detect and handle voids found in the SRTM data, ** + ** SRTM-3 data in .BIL and .HGT format, and high ** + ** resolution SRTM-1 one arc-second topography data. ** ************************************************************** ** Compile like this: ** ** cc -Wall -O3 -s -lbz2 srtm2sdf.c -o srtm2sdf ** - ** Last modification: 23-Sep-2007 ** + ** Last modification: 12-Mar-2009 ** \**************************************************************/ #include @@ -18,11 +19,11 @@ #define BZBUFFER 65536 -char sdf_filename[25], sdf_path[255], replacement_flag, opened=0, +char sdf_filename[30], sdf_path[255], replacement_flag, opened=0, hgt=0, bil=0; -int srtm[1201][1201], usgs[1200][1200], max_north, max_west, - min_north, min_west, merge=0, min_elevation, bzerror; +int srtm[3601][3601], usgs[1201][1201], max_north, max_west, n, + min_north, min_west, merge=0, min_elevation, bzerror, ippd, mpi; int ReadSRTM(char *filename) { @@ -120,7 +121,7 @@ int ReadSRTM(char *filename) if (fd!=NULL) { - fscanf(fd,"%lf",&cell_size); + n=fscanf(fd,"%lf",&cell_size); if ((cell_size<0.0008) || (cell_size>0.0009)) { @@ -128,13 +129,13 @@ int ReadSRTM(char *filename) exit(1); } - fscanf(fd,"%lf",°_west); - fscanf(fd,"%lf",°_west); - fscanf(fd,"%lf",°_west); + n=fscanf(fd,"%lf",°_west); + n=fscanf(fd,"%lf",°_west); + n=fscanf(fd,"%lf",°_west); - fscanf(fd,"%lf",°_west); + n=fscanf(fd,"%lf",°_west); - fscanf(fd,"%lf",°_north); + n=fscanf(fd,"%lf",°_north); fclose(fd); } @@ -164,7 +165,7 @@ int ReadSRTM(char *filename) return -1; } - read(infile,&buffer,2); + n=read(infile,&buffer,2); if ((buffer[0]=='P') && (buffer[1]=='K')) { @@ -175,7 +176,10 @@ int ReadSRTM(char *filename) lseek(infile,0L,SEEK_SET); - sprintf(sdf_filename, "%d:%d:%d:%d.sdf", min_north, max_north, min_west, max_west); + if (ippd==3600) + sprintf(sdf_filename, "%d:%d:%d:%d-hd.sdf", min_north, max_north, min_west, max_west); + else + sprintf(sdf_filename, "%d:%d:%d:%d.sdf", min_north, max_north, min_west, max_west); error=0; replacement_flag=0; @@ -183,8 +187,8 @@ int ReadSRTM(char *filename) printf("Reading %s... ", filename); fflush(stdout); - for (x=0; (x<1201 && error==0); x++) - for (y=0; (y<1201 && error==0); y++) + for (x=0; (x<=ippd && error==0); x++) + for (y=0; (y<=ippd && error==0); y++) { bytes_read=read(infile,&buffer,2); @@ -243,7 +247,7 @@ int LoadSDF_SDF(char *name) /* This function reads uncompressed SPLAT Data Files (.sdf) into memory. */ - int x, y, dummy; + int x, y, n, dummy; char sdf_file[255], path_plus_name[255]; FILE *infile; @@ -264,17 +268,17 @@ int LoadSDF_SDF(char *name) if (infile==NULL) return 0; - fscanf(infile,"%d", &dummy); - fscanf(infile,"%d", &dummy); - fscanf(infile,"%d", &dummy); - fscanf(infile,"%d", &dummy); + n=fscanf(infile,"%d", &dummy); + n=fscanf(infile,"%d", &dummy); + n=fscanf(infile,"%d", &dummy); + n=fscanf(infile,"%d", &dummy); printf("\nReading %s... ",path_plus_name); fflush(stdout); for (x=0; x<1200; x++) for (y=0; y<1200; y++) - fscanf(infile,"%d",&usgs[x][y]); + n=fscanf(infile,"%d",&usgs[x][y]); fclose(infile); @@ -429,21 +433,21 @@ int ReadUSGS() return (LoadSDF(usgs_filename)); } -void average_terrain(x,y,z) +void average_terrain(y,x,z) int x, y, z; { long accum; int temp=0, count, bad_value; double average; - bad_value=srtm[x][y]; + bad_value=srtm[y][x]; accum=0L; count=0; - if (x!=0) + if (y>=2) { - temp=srtm[x-1][y]; + temp=srtm[y-1][x]; if (temp>bad_value) { @@ -452,9 +456,9 @@ int x, y, z; } } - if (x!=1201) + if (y<=mpi) { - temp=srtm[x+1][y]; + temp=srtm[y+1][x]; if (temp>bad_value) { @@ -463,9 +467,9 @@ int x, y, z; } } - if ((x!=0) && (y!=1201)) + if ((y>=2) && (x<=(mpi-1))) { - temp=srtm[x-1][y+1]; + temp=srtm[y-1][x+1]; if (temp>bad_value) { @@ -474,9 +478,9 @@ int x, y, z; } } - if (y!=1201) + if (x<=(mpi-1)) { - temp=srtm[x][y+1]; + temp=srtm[y][x+1]; if (temp>bad_value) { @@ -485,9 +489,9 @@ int x, y, z; } } - if ((x!=1201) && (y!=1201)) + if ((x<=(mpi-1)) && (y<=mpi)) { - temp=srtm[x+1][y+1]; + temp=srtm[y+1][x+1]; if (temp>bad_value) { @@ -496,9 +500,9 @@ int x, y, z; } } - if ((x!=0) && (y!=0)) + if ((x>=1) && (y>=2)) { - temp=srtm[x-1][y-1]; + temp=srtm[y-1][x-1]; if (temp>bad_value) { @@ -507,9 +511,9 @@ int x, y, z; } } - if (y!=0) + if (x>=1) { - temp=srtm[x][y-1]; + temp=srtm[y][x-1]; if (temp>bad_value) { @@ -518,9 +522,9 @@ int x, y, z; } } - if ((x!=1201) && (y!=0)) + if ((y<=mpi) && (x>=1)) { - temp=srtm[x+1][y-1]; + temp=srtm[y+1][x-1]; if (temp>bad_value) { @@ -536,13 +540,24 @@ int x, y, z; } if (temp>min_elevation) - srtm[x][y]=temp; + srtm[y][x]=temp; else - srtm[x][y]=min_elevation; + srtm[y][x]=min_elevation; } void WriteSDF(char *filename) { + /* Like the HGT files, the extreme southwest corner + * provides the point of reference for the SDF file. + * The SDF file extends from min_north degrees to + * the south to min_north+(mpi/ippd) degrees to + * the north, and max_west degrees to the west to + * max_west-(mpi/ippd) degrees to the east. The + * overlapping edge redundancy present in the HGT + * and earlier USGS files is not necessary, nor + * is it present in SDF files. + */ + int x, y, byte, last_good_byte=0; FILE *outfile; @@ -553,10 +568,10 @@ void WriteSDF(char *filename) fprintf(outfile, "%d\n%d\n%d\n%d\n", max_west, min_north, min_west, max_north); - for (x=1200; x>0; x--) - for (y=1200; y>0; y--) + for (y=ippd; y>=1; y--) /* Omit the northern most edge */ + for (x=mpi; x>=0; x--) /* Omit the eastern most edge */ { - byte=srtm[x][y]; + byte=srtm[y][x]; if (byte>min_elevation) last_good_byte=byte; @@ -564,12 +579,18 @@ void WriteSDF(char *filename) if (byte and/or from string */