[GRASS5] readsites() TODO list...

Eric G . Miller egm2 at jps.net
Wed Sep 20 21:24:25 EDT 2000


Thanks for the responses.

Here's the deal.  I just picked this up, cause I saw it on the TODO list
on the website(s).  Anyway, I've coded this thing up, tested it, and it
works as planned.  The question of course, is this functionality worthy
of a library function?  I will have to concede, I think it isn't.  I
guessed that there must've been a significant demand for this limited
function, but perhaps the more general is desirable.  That is,
G_readsites() just makes an array of Site structs for the caller's
consumption.  I'll agree, that for speed, etc. reuse of the array is
certainly a better idea than dynamically allocating, then freeing, then
repeating, ...  As far as using a static variable, I didn't see the
need.  I was taking it on faith that the caller wouldn't make operations
on the file between calls (why would they?).

Anyway, shall I look at writing a generalized G_readsites() (and maybe
G_writesites() ?) using the standard Site struct?  I'm ambivalent.

Here's an annotated explanation of the API for those who had questions.


int G_readsites(

  --- G_readsites() returns either (a) the number of records read, or
  --- (b) a negative error condition (think, recoverable memory
  --- handling). 
  
        FILE * fdsite,

  --- The file stream opened with G_open_sites_old(), Assumed that if
  --- multiple calls are used, the caller does not manipulate the
  --- file stream (it still points where the last call left off).
  
        int    num,     /* Number of records to read */

  --- This is the number of records requested (whether or not that
  --- many exist, or more exist. Don't know right?).  If this was
  --- a pointer, then the caller would have to have a local copy,
  --- don't know that's any better than just returning the number read.
  
        int    type,    /* 0 = Z-dim, 1 = double, 2 = string */
	
  --- This is the attribute type. By "Z-dim", I mean any of the n-dims
  --- in the Site file spec. Double, is double attribute, string is
  --- string attribute.  Yes, an enum or #define's are in order.
 
        int    index,   /* The field index (1 based) */

  --- The one-based index of the attribute, so the second z-dim is 2,
  --- etc...
  
        int  * done,    /* No more records in file? 0 = false, 1 = true*/

  --- This allows the caller to use that twisted logic if (!done) {...}
  --- It's completely superfluous, since if the function returns 0, 
  --- well, you're done!
  
        site **xyz /* The site array, caller must free between calls */

  --- This is the heart of the matter.  I didn't come up with this, so
  --- I'll shift blame.  I guessed this simplified view of the Site
  --- world was somehow desireable.  Maybe only in the special case?
);

  --- The End ---

-- 
/bin/sh ~/.signature:
Command not found

---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list