NAME

RputSomeCells - write a stream of cells

SYNOPSIS

#include "csf.h"

size_t RputSomeCells
(
	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
read-write. Buffer large enough to hold nrCells cells in the in-file cell representation or the in-app cell representation. If these types are not equal then the buffer is converted from the in-app to the in-file cell representation.

DESCRIPTION

RputSomeCells views a raster as one linear stream of cells, with row i+1 placed after row i. In this stream any sequence can be written by specifying an offset and the number of cells to be written

RETURNS

the number of cells written, just as fwrite

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);
}