A Little Help
Eric McDonald
mcdonald@phy.cmich.edu
Tue Oct 12 02:36:00 GMT 2004
D. Cooper Stevenson wrote:
> * I haven't written (but do respect) the C language in a long time and it
> shows; I've had a tough go of it getting the application to work.
>
> I think it's time to ask for help.
>
> As I mentioned above, the GIS ASCII file format is simple. Here's a
> description:
>
> The first 7 or so lines represent the header of the file. The most relevant
> numbers for our purposes are the "rows" and "cols" numbers. The last line is
> the actual elevation (or landcover) data. Here's an example:
>
> north: 3980319.16466812
> south: 3978824.85093895
> east: 443960
> west: 442296
If you don't need these values, you might want to just toss them. That
way you wouldn't have to tell your parser to ignore them.
> rows: 747
> cols: 832
You'll probably want to keep this information. The number of rows is
probably a better termination condition than EOF. And the number of
columns is useful for determining how many times to call strtok(3), for
example.
Here is a vague handwaving outline of how one might go about some of
this. This is not guaranteed to be the best way. Just some spewing off
the top of my head...:
/* Some definitions earlier on. */
#define BUFSIZE 256
#define DATAWIDTH 5
char data [BUFSIZE]
int numrows = numcols = 0;
/* Some code.... */
/* Part of your parser. (One possible way; there are others. Assumes you
are inside some sort of loop.) */
if (numrows && numcols)
break;
fgets(data, BUFSIZE, ifp);
if (!strncmp("rows: ", data, 6)) {
numrows = atoi(data+6);
continue;
}
else if (!strncmp("cols: ", data, 6)) {
numcols = atoi(data+6);
continue;
}
/* Some code...? */
/* Another part of your parser. */
data2 = malloc(numcols*DATAWIDTH);
boxrowsz = numcols / BOXWIDTH;
elevbox = malloc(numcols * BOXHEIGHT * sizeof(int));
for (i = 0; i < numrows; ++i) {
fgets(data2, numcols * DATAWIDTH, ifp);
memset(elevrow, 0, numcols * sizeof(int));
for (j = 0; j < numcols; ++j) {
if (!j)
nextdata = strtok(data2, " ");
else
nextdata = strtok(NULL, " ");
/* Stuff the data into the appropriate elev row box and slot(s)
within the box. */
/* You can use / and % (div and mod) to help determine which box to
stuff things in. */
}
if (i && (0 == (i % BOXHEIGHT)))
/* Take median, mean, or whatever. */
}
/* More code.... */
/* You can use existing functions in libconq.a or maybe even just
libconqlow.a to help in writing out Xconq-readable forms, including
layer data. */
/* Hope this helps,
Eric */
More information about the Xconq7
mailing list