1 /****************************************************************************
2 * USGS2SDF: USGS to SPLAT Data File Converter Utility *
3 * Copyright John A. Magliacane, KD2BD 1997-2001 *
4 * Last update: 13-Apr-2002 *
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],
65 selat[30], string[40];
66 double max_el, min_el, max_west, min_west, max_north, min_north;
67 int x, y, z, c, array[1202][1202];
73 fprintf(stderr,"Usage: usgs2sdf uncompressed_delimited_usgs_datafile (ie: wilmington-e)\n");
77 fd=fopen(argv[1],"rb");
81 fprintf(stdout,"Reading \"%s\"...",argv[1]);
84 /* Skip first 548 bytes */
89 /* Read quadrangle corners */
91 /* Read southwest longitude */
102 /* Read southwest latitude */
113 /* Read northwest longitude */
124 /* Read northwest latitude */
135 /* Read northeast longitude */
146 /* Read northeast latitude */
157 /* Read southeast longitude */
168 /* Read southeast latitude */
179 /* Read minimum elevation */
190 /* Read maximum elevation */
197 sscanf(d2e(minimum),"%lf",&min_el);
198 sscanf(d2e(maximum),"%lf",&max_el);
200 sscanf(d2e(swlong),"%lf",&max_west);
201 sscanf(d2e(swlat),"%lf",&min_north);
203 sscanf(d2e(nelong),"%lf",&min_west);
204 sscanf(d2e(nelat),"%lf",&max_north);
216 /* Read elevation data... */
218 for (x=1200; x>=0; x--)
222 printf(" 25%c...",37);
228 printf(" 50%c...",37);
234 printf(" 75%c... ",37);
238 /* Skip over 9 strings of data */
248 } while (c==' ' || c=='\n');
250 for (z=0; c!=' ' && c!='\n' && z<28; z++)
259 /* Store elevation data in array */
261 for (y=0; y<1201; y++)
269 } while (c==' ' || c=='\n');
271 for (z=0; c!=' ' && c!='\n' && z<28; z++)
278 sscanf(string,"%d",&array[y][x]);
284 /* Write splat data file to disk */
286 sprintf(splatfile,"%.0f:%.0f:%.0f:%.0f.sdf",min_north,max_north,min_west,max_west);
288 fprintf(stdout," Done!\nWriting \"%s\"... ",splatfile);
291 fd=fopen(splatfile,"w");
293 fprintf(fd,"%.0f\n%.0f\n%.0f\n%.0f\n", max_west, min_north, min_west, max_north);
295 for (x=0; x<1200; x++)
296 for (y=0; y<1200; y++)
297 fprintf(fd,"%d\n",array[x][y]);
300 fprintf(stdout,"Done!\n");
306 fprintf(stderr,"*** %c%s%c: File Not Found!\n",34,argv[1],34);