public inbox for xconq7@sourceware.org
 help / color / mirror / Atom feed
From: Eric McDonald <mcdonald@phy.cmich.edu>
To: cstevens@gencom.us
Cc: xconq7 <xconq7@sources.redhat.com>
Subject: Re: A Little Help
Date: Tue, 12 Oct 2004 02:36:00 -0000	[thread overview]
Message-ID: <416B3E1C.6050004@phy.cmich.edu> (raw)
In-Reply-To: <200410102134.15234.cstevens@gencom.us>

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 */

  reply	other threads:[~2004-10-12  2:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-12  2:15 D. Cooper Stevenson
2004-10-12  2:36 ` Eric McDonald [this message]
2004-10-13  2:38   ` Eric McDonald
2004-10-16  5:08   ` D. Cooper Stevenson
2004-10-16 18:22     ` Website Update Request Elijah Meeks
2004-10-17 14:45       ` Eric McDonald
2004-10-18 23:47         ` D. Cooper Stevenson
2004-10-23 19:39           ` Elijah Meeks

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=416B3E1C.6050004@phy.cmich.edu \
    --to=mcdonald@phy.cmich.edu \
    --cc=cstevens@gencom.us \
    --cc=xconq7@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).