1 /***************************************************************************\
2 * USGS2SDF: USGS to SPLAT Data File Converter Utility *
3 * Copyright John A. Magliacane, KD2BD 1997-2001 *
4 * Last update: 05-Sep-2005 *
5 *****************************************************************************
6 * Updated July 2005 by John Gabrysch (jgabby@gmail.com) to properly handle *
7 * the updated USGS DEM file format and to properly scale Alaska tiles. *
8 *****************************************************************************
10 * This program reads files containing delimited US Geological Survey *
11 * Digital Elevation Model Data files, and creates Splat Data Files *
12 * containing ONLY the raw information needed by SPLAT!, thereby saving *
13 * disk space, as well as read/write time. *
15 * The format of .sdf files created by this utility is as follows: *
17 * maximum west longitude (degrees West) *
18 * minimum north latitude (degrees North) *
19 * minimum west longitude (degrees West) *
20 * maximum north latitude (degrees North) *
21 * ...1440000 elevation points... (1200x1200) *
23 * All data is represented as integers. A single '\n' follows each value. *
25 * SPLAT Data Files are named according to the geographical locations *
26 * they represent (ie: min_north:max_north:min_west:max_west.sdf). *
28 *****************************************************************************
29 * To compile: gcc -Wall -O3 -s usgs2sdf.c -o usgs2sdf *
30 *****************************************************************************
32 * This program is free software; you can redistribute it and/or modify it *
33 * under the terms of the GNU General Public License as published by the *
34 * Free Software Foundation; either version 2 of the License or any later *
37 * This program is distributed in the hope that it will useful, but WITHOUT *
38 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
39 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
42 \***************************************************************************/
50 /* This function is used to replace 'D's with 'E's for proper
51 exponential notation of numeric strings read from delimited
52 USGS data files. It returns a pointer to a string. */
56 for (x=0; string[x]!=0; x++)
66 unsigned char minimum[30], maximum[30], swlong[30], swlat[30],
67 nwlong[30], nwlat[30], nelong[30], nelat[30],
68 selong[30], selat[30];
70 double max_el, min_el, max_west, min_west, max_north, min_north;
71 int x, y, z, c, array[1202][1202];
78 fprintf(stderr,"Usage: usgs2sdf uncompressed_delimited_usgs_datafile (ie: wilmington-e)\n");
82 fd=fopen(argv[1],"rb");
86 fprintf(stdout,"Reading \"%s\"...",argv[1]);
89 /* Skip first 548 bytes */
94 /* Read quadrangle corners */
96 /* Read southwest longitude */
108 /* Read southwest latitude */
120 /* Read northwest longitude */
132 /* Read northwest latitude */
144 /* Read northeast longitude */
156 /* Read northeast latitude */
168 /* Read southeast longitude */
180 /* Read southeast latitude */
192 /* Read minimum elevation */
204 /* Read maximum elevation */
211 sscanf(d2e((char*)minimum),"%lG",&min_el);
212 sscanf(d2e((char*)maximum),"%lf",&max_el);
214 sscanf(d2e((char*)swlong),"%lf",&max_west);
215 sscanf(d2e((char*)swlat),"%lf",&min_north);
217 sscanf(d2e((char*)nelong),"%lf",&min_west);
218 sscanf(d2e((char*)nelat),"%lf",&max_north);
225 /* If the latitude is between 50 and 70, there are only 600 vertical lines of data.
226 If the latitude is greater than 70, there are only 400. arc_mod is the flag for
229 if (min_north >= 50.0)
232 if (min_north >= 70.0)
236 /* Skip 84 Bytes - Modified to 238 by jgabby 07/05 */
238 for (x=0; x<238; x++)
241 /* Read elevation data... */
243 for (x=1200; x>=0; x--)
247 printf(" 25%c...",37);
253 printf(" 50%c...",37);
259 printf(" 75%c... ",37);
263 /* Skip over 9 strings of data */
273 } while (c==' ' || c=='\n');
275 for (z=0; c!=' ' && c!='\n' && z<28; z++)
284 /* Store elevation data in array */
286 for (y=0; y<1201; y++)
294 } while (c==' ' || c=='\n');
296 for (z=0; c!=' ' && c!='\n' && z<28; z++)
304 sscanf(string,"%d",&array[y][x]);
306 /* The next few lines either duplicate or triplicate the lines to
307 ensure a 1200x1200 result, depending on how arc_mod was set earlier */
310 sscanf(string,"%d",&array[y][x-1]);
313 sscanf(string,"%d",&array[y][x-2]);
326 /* Write splat data file to disk */
328 sprintf(splatfile,"%.0f:%.0f:%.0f:%.0f.sdf",min_north,max_north,min_west,max_west);
330 fprintf(stdout," Done!\nWriting \"%s\"... ",splatfile);
333 fd=fopen(splatfile,"w");
335 fprintf(fd,"%.0f\n%.0f\n%.0f\n%.0f\n", max_west, min_north, min_west, max_north);
337 for (x=0; x<1200; x++)
338 for (y=0; y<1200; y++)
339 fprintf(fd,"%d\n",array[x][y]);
342 fprintf(stdout,"Done!\n");
348 fprintf(stderr,"*** %c%s%c: File Not Found!\n",34,argv[1],34);