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

static char *rowscoreid = "$Id: row_score.c,v 1.3 1996/12/30 23:29:08 galway Exp $";

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

    row_score.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




    Computes the score of a row as number of block codes (from teh
    current block) minus the number of block symbols (from previous
    blocks).  This is called during block construction where no block
    symbol indicators have been set.

    Note that this is coded to have a net zero effect if the current
    block code is also one for a previous block.  This can occur
    according to Hartigan's example, but algorithm is unclear.  The
    coding is consistent with the paper.

    L. Galway 30-DEC-1996
/*****************************************************************/

extern enum logical is_blkind();

int row_score(dat,blk,nrow)
struct datamat *dat;struct block *blk;int nrow;
{
  int i,rscore;

  rscore = 0;
  for (i=0;i<blk->NC;i++) {
    if (blk->icol[i] == 1) {
      /*  Should this be an if-else if ??? */
      if (blk->blkcd[i]==dat->data[nrow][i]) rscore++;
      if (is_blkind(nrow,i,dat)==TRUE) rscore--;
    };
  };
  return(rscore);
}
