1 /****************************************************************************
2 * USGS2SDF: USGS to SPLAT Data File Converter Utility *
3 * Copyright John A. Magliacane, KD2BD 1997-2009 *
4 * Last update: 14-Mar-2009 *
5 *****************************************************************************
7 * This program reads files containing delimited US Geological Survey *
8 * Digital Elevation Model Data files, and creates Splat Data Files *
9 * containing ONLY the raw information needed by SPLAT!, thereby saving *
10 * disk space, as well as read/write time. *
12 * The format of .sdf files created by this utility is as follows: *
14 * maximum west longitude (degrees West) *
15 * minimum north latitude (degrees North) *
16 * minimum west longitude (degrees West) *
17 * maximum north latitude (degrees North) *
18 * ...1440000 elevation points... (1200x1200) *
20 * All data is represented as integers. A single '\n' follows each value. *
22 * SPLAT Data Files are named according to the geographical locations *
23 * they represent (ie: min_north:max_north:min_west:max_west.sdf). *
25 *****************************************************************************
26 * To compile: gcc -Wall -O6 -s splat2sdf.c -o splat2sdf *
27 *****************************************************************************
29 * This program is free software; you can redistribute it and/or modify it *
30 * under the terms of the GNU General Public License as published by the *
31 * Free Software Foundation; either version 2 of the License or any later *
34 * This program is distributed in the hope that it will useful, but WITHOUT *
35 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
36 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
39 *****************************************************************************/
47 /* This function is used to replace 'D's with 'E's for proper
48 exponential notation of numeric strings read from delimited
49 USGS data files. It returns a pointer to a string. */
53 for (x=0; string[x]!=0; x++)
63 unsigned char minimum[30], maximum[30], swlong[30], swlat[30],
64 nwlong[30], nwlat[30], nelong[30], nelat[30], selong[30],
67 double max_el, min_el, max_west, min_west, max_north, min_north;
68 int x, y, z, c, array[1202][1202];
74 fprintf(stderr,"Usage: usgs2sdf uncompressed_delimited_usgs_datafile (ie: wilmington-e)\n");
78 fd=fopen(argv[1],"rb");
82 fprintf(stdout,"Reading \"%s\"...",argv[1]);
85 /* Skip first 548 bytes */
90 /* Read quadrangle corners */
92 /* Read southwest longitude */
103 /* Read southwest latitude */
114 /* Read northwest longitude */
125 /* Read northwest latitude */
136 /* Read northeast longitude */
147 /* Read northeast latitude */
158 /* Read southeast longitude */
169 /* Read southeast latitude */
180 /* Read minimum elevation */
191 /* Read maximum elevation */
198 sscanf(d2e((char*)minimum),"%lG",&min_el);
199 sscanf(d2e((char*)maximum),"%lf",&max_el);
201 sscanf(d2e((char*)swlong),"%lf",&max_west);
202 sscanf(d2e((char*)swlat),"%lf",&min_north);
204 sscanf(d2e((char*)nelong),"%lf",&min_west);
205 sscanf(d2e((char*)nelat),"%lf",&max_north);
217 /* Read elevation data... */
219 for (x=1200; x>=0; x--)
223 printf(" 25%c...",37);
229 printf(" 50%c...",37);
235 printf(" 75%c... ",37);
239 /* Skip over 9 strings of data */
249 } while (c==' ' || c=='\n');
251 for (z=0; c!=' ' && c!='\n' && z<28; z++)
260 /* Store elevation data in array */
262 for (y=0; y<1201; y++)
270 } while (c==' ' || c=='\n');
272 for (z=0; c!=' ' && c!='\n' && z<28; z++)
279 sscanf(string,"%d",&array[y][x]);
285 /* Write splat data file to disk */
287 sprintf(splatfile,"%.0f:%.0f:%.0f:%.0f.sdf",min_north,max_north,min_west,max_west);
289 fprintf(stdout," Done!\nWriting \"%s\"... ",splatfile);
292 fd=fopen(splatfile,"w");
294 fprintf(fd,"%.0f\n%.0f\n%.0f\n%.0f\n", max_west, min_north, min_west, max_north);
296 for (x=0; x<1200; x++)
297 for (y=0; y<1200; y++)
298 fprintf(fd,"%d\n",array[x][y]);
301 fprintf(stdout,"Done!\n");
307 fprintf(stderr,"*** %c%s%c: File Not Found!\n",34,argv[1],34);