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

static char *modefreqid = "$Id: mode_freq.c,v 1.3 1996/12/30 20:21:38 galway Exp $";

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

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



    This routine returns the frequency of the mode of a column in
    a particular block.

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

extern struct valcnt *col_freq();
extern int find_mode();
extern void free_valcnt();

int mode_freq(d,icol,blk)
struct datamat *d;int icol;struct block *blk;
{
  struct valcnt *cv;int mode,freq,i;

  cv = col_freq(d,icol,blk);  /* Compute frequencies (excluding block
				 symbols) for a column in a block */
  mode = find_mode(cv);       /*  Find the mode in the valcnt */
  for (i=0;i<cv->nvals;i++) { /*  Retrieve the frequency */
    if (cv->vals[i] == mode) freq = cv->cnts[i];
  };
  free_valcnt(cv); /*  Clean up the valcnt */
  return(freq);
}
