#include "datamat.h"
#include "block.h"

static char *setblkindid ="$Id: setblkind.c,v 1.3 1996/12/30 21:59:34 galway Exp $";

/* ***************************************************************** */
/* 

    setblkind.c

    Copyright (C) 2004  Lionel A. Galway

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    For a copy of the GNU General Public License write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA





   Once block values have been determined, this routine identifies
   which elements within the block have those values and identifies
   them in the block value indicator array attached to the data matrix.
   This is done by putting a -1 where the value is not equal to the
   block value for the column, and setting the value to a positive
   integer where the value is equal to the block value.

   Note that this erases previous block symbols, which fits with
   Hartigan's article prose, but not (apparently) Table 9 (?).

   Could be made more efficient by testing row indicator before
   looping over columns.  Also order of looping effects with memory
   management.

   L. Galway 16-AUG-1996 */
/* ***************************************************************** */

void setblkind(d,blk)
struct datamat *d;struct block *blk;
{
	int i,j;

	for(i=0;i<blk->NR;i++) {
	  for(j=0;j<blk->NC;j++)
	    /* Check if data element is in the block */
	    if (blk->irow[i]==1 && blk->icol[j]==1) { 
		if (d->data[i][j]==blk->blkcd[j]) 
		  d->blkind[i][j]=blk->bcode; /* If a block code, set
						 to block number */
		else d->blkind[i][j]=-1;    /* Else set back to unmarked */
	    };
	};
	return;
}
