matrix permutations( vector _v);
matrix combinations( vector _v, int _n);
vector get_unique_perms( vector _c, matrix _perms);


/*
 * setup_combos: setup global variables: perms, combos, unique_perms,
 * MP, and M.  Global variables used: K and MM
 */
void setup_combos( void)
{
  matrix tc;
  vector up;
  int i;

  perms = permutations(1:K);
  MP = rows(perms);

  combos = combinations( 1:MM, K);

  unique_perms = reshape( 1:MP, rows(combos), MP);

  if( MISSED) {
    for( i = K-1; i >= 1; --i) {
      tc = combinations( 1:MM, i);
      tc = [tc, (MM+1)*ones(rows(tc),K-i)];	/* K-i missed target events */
      combos = [combos; tc];
      up = get_unique_perms( tc(1,:), perms);
      unique_perms = [unique_perms; reshape(up,rows(tc),MP)];

    }
    combos = [combos; (MM+1)*ones(1,K)];	/* K missed target events */
    unique_perms = [unique_perms; eye(1,MP)];
  }

  M = rows(combos);
}
