New to grass -- a couple of questions

Eric G . Miller egm2 at jps.net
Mon Jun 5 04:43:42 EDT 2000


On Mon, Jun 05, 2000 at 09:49:35AM +0200, Michel Wurtz - ENGEES/CEREG wrote:
> "Eric G . Miller" wrote:
> > 
> > On Thu, Jun 01, 2000 at 04:47:17PM -0600, Stephen Griffiths wrote:
> > > Hi all,
> > >
> > > I am new to Grass so please forgive to simple nature of my questions.
> > >
> > > I have been trying to read my DEMs and Ortho images into grass.  I have
> > > used "r.in.bin".  This has worked fine if the data is in an 8bit
> > > unsigned binary format -- thats ok for the image, but not the DEM.  How
> > > can I read the DEM in as 16bit unsigned or even better 32bit float?  My
> > > DEM's are all in 32bit float flat binary raster format.  I really do not
> > > want to convert them to some other format first.
> > 
> > I don't see any way around it ;( Wouldn't be hard to convert to ascii
> > and then use r.in.ascii.
> 
> Maybe the opportunity to update r.in.bin for Grass5.0 (I know that
> reading floats that are not generated on the same processor may be
> non trivial :-) ?

It's not hard either. But you'd need a little help from the user (and
they might not know).  If we read a 4 byte float, or an 8 byte double,
as a char[n] array, then you just reorder the array and write it into a
float/double as appropriate.  Can't think of much of a sanity test for
the endianess except that reading the wrong way will get you really
large or really small numbers (and might get the wrong sign).  If the
particular file format were to specify 8 byte little-endian doubles,
then the procedure would be more straight forward.

void swap_4byte(char *data)
{
	char	temp[4];
	/* Make a temp copy */
	temp[0] = data[0];
	temp[1] = data[1];
	temp[2] = data[2];
	temp[3] = data[3];
	/* flip 'em */
	data[0] = temp[3];
	data[1] = temp[2];
	data[2] = temp[1];
	data[3] = temp[0];
}


/* somewhere else */
...
	float	number;
	char    cFlip[4];
	if(4 == (fread(&cFlip, sizeof(char), 4, inFile))) {
		swap_4byte(&cFlip);
		memmove(&number,&cFlip,4);
		/* now do something with that 'number' */
		...
	}
...

Or something like that... Probably with more sanity checking...
	
-- 
daw daw dit, daw daw daw, daw dit dit dit daw, dit dit daw dit,
dit dit, dit dit dit, dit dit dit dit, daw dit dit dit daw,




More information about the grass-user mailing list