NAME
RgetSomeCells - read a stream of cells
SYNOPSIS
#include "csf.h"
size_t RgetSomeCells
(
MAP *map,
size_t offset,
size_t nrCells,
void *buf
);
PARAMETERS
-
MAP *map
-
map handle
-
size_t offset
-
offset from pixel (row,col) = (0,0)
-
size_t nrCells
-
number of cells to be read
-
void *buf
-
write-only. Buffer large enough to
hold nrCells cells in the in-file cell representation
or the in-app cell representation.
DESCRIPTION
RgetSomeCells views a raster as one linear stream of
cells, with row i+1 placed after row i.
In this stream any sequence can be read by specifying an
offset and the number of cells to be read
RETURNS
the number of cells read, just as fread
EXAMPLE
#include
#include "csf.h"
/* process a raster in
* chunks of 2 rows
* assuming an even number of rows
*/
extern void DoThatWithIt(REAL4 * , size_t );
void main(int argc, char *argv[] )
{
REAL4 *buf;
MAP *map;
size_t r, nrCols;
size_t chunkSize;
if (argc != 2)
{
fprintf(stderr,"%s: no file specified\n",argv[0]);
exit(1);
}
map = Mopen(argv[1], M_READ_WRITE);
if (map == NULL)
{
Mperror(argv[1]);
exit(1);
}
nrCols = RgetNrCols(map);
chunkSize = 2*nrCols;
(void)RuseAs(map, CR_REAL4);
buf = (REAL4 *)Rmalloc(map, chunkSize);
for(r=0; r < RgetNrRows(map); r += 2)
{
RgetSomeCells(map, r*nrCols, chunkSize, buf);
DoThatWithIt(buf, chunkSize);
RputSomeCells(map,r*nrCols, chunkSize, buf);
}
Mclose(map);
free(buf);
exit(0);
}