/***************************************************************************/
/***                                                                     ***/
/***                             process()                               ***/
/***          Reads in a raster files row by row for processing          ***/
/***                  Jo Wood, V1.2, 13th September, 1995		 ***/
/***                                                                     ***/
/***************************************************************************/

#include "example.h"

process()
{

    /*------------------------------------------------------------------*/
    /*				INITIALISE				*/
    /*------------------------------------------------------------------*/ 
									
    CELL        *row1,*row2,   	/* Buffers to hold raster rows.		*/
                *row_out;       

    int         nrows,          /* Will store the current number of     */
                ncols,          /* rows and columns in the raster.      */

                row,col;        /* Counts through each row and column   */
                                /* of the input raster.                 */
                           

    /*------------------------------------------------------------------*/
    /*                       GET DETAILS OF INPUT RASTER                */
    /*------------------------------------------------------------------*/ 

    row1    = G_allocate_cell_buf(); /* Allocate row buffers for I/O.	*/
    row2    = G_allocate_cell_buf(); 
    row_out = G_allocate_cell_buf();
                                        
    nrows = G_window_rows();         /* Find out the number of rows and	*/
    ncols = G_window_cols();         /* columns in the raster 'view'.	*/


    /*------------------------------------------------------------------*/
    /*     PROCESS INPUT RASTERS AND WRITE OUT RASTER LINE BY LINE	*/
    /*------------------------------------------------------------------*/ 
                                                                             
    for(row=0; row<nrows; row++)
    {
        G_get_map_row(fd_rast1_in, row1, row);
        G_get_map_row(fd_rast2_in, row2, row);

        for(col = 0; col < ncols; col++)
        {
	    *(row_out + col) = *(row1 + col) + *(row2 + col);
	    /* example process adds the contents of the two rasters.	*/
        }
	
        G_put_map_row(fd_out,row_out);
    }
}


