[GRASS5] Does this G_readsites_xyz() meet peoples needs?

Eric G . Miller egm2 at jps.net
Sun Oct 1 01:01:16 EDT 2000


Okay, I've modified the G_readsites() function to G_readsites_xyz() with
the API below.  I tested out the implementation and it works okay. So if 
nobody objects in the next couple days, I'll add the header to site.h
and put the implementation into the libgis.a. 

Basically, you'd use the G_alloc_site_xyz() to allocate an array of
SITE_XYZ struct (or just allocate a fixed array), then make iterative
calls until the number of records returned is less than the size of the
array, or EOF is returned. Finally free the dynamically allocated array
(if you used G_alloc_site_xyz()) with G_free_site_xyz(). 

The current implementation just dies if there are any conversion or
index errors.  This implies that site_lists must not have missing
dimensions or attributes for any of the records.  Lack of a category
value will have 'cattype' set to the same value set by G_site_get().

## Modifications for site.h ##

/* Some defines for which column type to use */
#define SITE_COL_DIM 1
#define SITE_COL_DBL 2
#define SITE_COL_STR 3


/* The XYZ site struct. Note the use of a union for the cat value is
 * different than the Site struct.
 */
typedef struct {
	double x, y, z;
	RASTER_MAP_TYPE cattype;
	union {
		double d;
		float  f;
		int    c;
	} cat ;
} SITE_XYZ;


/* Allocate 'num' SITE_XYZ structs. Returns NULL on failure */
SITE_XYZ * G_alloc_site_xyz(size_t num);


/* Free the array of SITE_XYZ struct */
void G_free_site_xyz(SITE_XYZ *theSites);


/* G_readsites_xyz: Reads a sites file converting to a site struct of xyz
 * values and the cat value.  The Z value can come from one of the
 * n-dimensions, a double attribute, or a string attribute converted to a
 * double with strtod().  The 'size' must not be greater than the number
 * of elements in the SITE_XYZ array, or bad things will happen. The number 
 * of records read is returned or EOF on end of file. NOTE: EOF won't be
 * returned unless no records are read and the EOF bit is set. It's safe
 * to assume that if the number of records read is less than the size of
 * the array, that there aren't any more records.
 */
int G_readsites_xyz( 
	FILE * fdsite,   /* The FILE stream to the sites file               */
	int    type,     /* Attribute type: SITE_COL_DIM, etc...            */
	int    index,    /* The field index (1 based) for the attribute     */
	int    size,     /* Size of the array                               */
	SITE_XYZ *xyz    /* The site array of size 'size'                   */
	);

-- 
/bin/sh ~/.signature:
Command not found
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-dev/attachments/20000930/22d84d2b/attachment.bin


More information about the grass-dev mailing list