From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26608 invoked by alias); 12 Oct 2004 02:15:10 -0000 Mailing-List: contact xconq7-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: xconq7-owner@sources.redhat.com Received: (qmail 26600 invoked from network); 12 Oct 2004 02:15:08 -0000 Received: from unknown (HELO rwcrmhc11.comcast.net) (204.127.198.35) by sourceware.org with SMTP; 12 Oct 2004 02:15:08 -0000 Received: from [192.168.181.128] (c-67-172-156-222.client.comcast.net[67.172.156.222]) by comcast.net (rwcrmhc11) with ESMTP id <2004101202150201300c66pue>; Tue, 12 Oct 2004 02:15:07 +0000 Message-ID: <416B3E1C.6050004@phy.cmich.edu> Date: Tue, 12 Oct 2004 02:36:00 -0000 From: Eric McDonald User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) MIME-Version: 1.0 To: cstevens@gencom.us CC: xconq7 Subject: Re: A Little Help References: <200410102134.15234.cstevens@gencom.us> In-Reply-To: <200410102134.15234.cstevens@gencom.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004/txt/msg01351.txt.bz2 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 */