-/****************************************************************************
+/***************************************************************************\
* USGS2SDF: USGS to SPLAT Data File Converter Utility *
* Copyright John A. Magliacane, KD2BD 1997-2001 *
-* Last update: 13-Apr-2002 *
+* Last update: 05-Sep-2005 *
+*****************************************************************************
+* Updated July 2005 by John Gabrysch (jgabby@gmail.com) to properly handle *
+* the updated USGS DEM file format and to properly scale Alaska tiles. *
*****************************************************************************
* *
* This program reads files containing delimited US Geological Survey *
* they represent (ie: min_north:max_north:min_west:max_west.sdf). *
* *
*****************************************************************************
-* To compile: gcc -Wall -O6 -s splat2sdf.c -o splat2sdf *
+* To compile: gcc -Wall -O3 -s usgs2sdf.c -o usgs2sdf *
*****************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
* for more details. *
* *
-*****************************************************************************/
+\***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
char *argv[];
{
unsigned char minimum[30], maximum[30], swlong[30], swlat[30],
- nwlong[30], nwlat[30], nelong[30], nelat[30], selong[30],
- selat[30], string[40];
- double max_el, min_el, max_west, min_west, max_north, min_north;
+ nwlong[30], nwlat[30], nelong[30], nelat[30],
+ selong[30], selat[30];
+ char string[40];
+ double max_el, min_el, max_west, min_west, max_north, min_north;
int x, y, z, c, array[1202][1202];
+ int arc_mod=0;
char splatfile[25];
FILE *fd;
for (x=0; x<22; x++)
swlong[x]=getc(fd);
+
swlong[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
swlat[x]=getc(fd);
+
swlat[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
nwlong[x]=getc(fd);
+
nwlong[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
nwlat[x]=getc(fd);
+
nwlat[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
nelong[x]=getc(fd);
+
nelong[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
nelat[x]=getc(fd);
+
nelat[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
selong[x]=getc(fd);
+
selong[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
selat[x]=getc(fd);
+
selat[x]=0;
/* Skip 2 bytes */
for (x=0; x<22; x++)
minimum[x]=getc(fd);
+
minimum[x]=0;
/* Skip 2 bytes */
maximum[x]=0;
- sscanf(d2e(minimum),"%lf",&min_el);
- sscanf(d2e(maximum),"%lf",&max_el);
+ sscanf(d2e((char*)minimum),"%lG",&min_el);
+ sscanf(d2e((char*)maximum),"%lf",&max_el);
- sscanf(d2e(swlong),"%lf",&max_west);
- sscanf(d2e(swlat),"%lf",&min_north);
+ sscanf(d2e((char*)swlong),"%lf",&max_west);
+ sscanf(d2e((char*)swlat),"%lf",&min_north);
- sscanf(d2e(nelong),"%lf",&min_west);
- sscanf(d2e(nelat),"%lf",&max_north);
+ sscanf(d2e((char*)nelong),"%lf",&min_west);
+ sscanf(d2e((char*)nelat),"%lf",&max_north);
max_west/=-3600.0;
min_north/=3600.0;
max_north/=3600.0;
min_west/=-3600.0;
- /* Skip 84 Bytes */
+ /* If the latitude is between 50 and 70, there are only 600 vertical lines of data.
+ If the latitude is greater than 70, there are only 400. arc_mod is the flag for
+ use later */
+
+ if (min_north >= 50.0)
+ arc_mod++;
+
+ if (min_north >= 70.0)
+ arc_mod++;
- for (x=0; x<84; x++)
+
+ /* Skip 84 Bytes - Modified to 238 by jgabby 07/05 */
+
+ for (x=0; x<238; x++)
getc(fd);
/* Read elevation data... */
c=getc(fd);
}
- string[z]=0;
+ string[z]=0;
+
sscanf(string,"%d",&array[y][x]);
+
+ /* The next few lines either duplicate or triplicate the lines to
+ ensure a 1200x1200 result, depending on how arc_mod was set earlier */
+
+ if (arc_mod > 0)
+ sscanf(string,"%d",&array[y][x-1]);
+
+ if (arc_mod > 1)
+ sscanf(string,"%d",&array[y][x-2]);
}
+
+ if (arc_mod > 0)
+ x--;
+
+
+ if (arc_mod > 1)
+ x--;
}
fclose(fd);
fprintf(stderr,"*** %c%s%c: File Not Found!\n",34,argv[1],34);
exit(-1);
}
+
else
exit(0);
}
+