// Once we have the data read in, we need to convert the continuous data to discrete data.
// We will do that by first calculating the new bins and then replacing Item[#][att] with whatever bin it goes in.
// For this test, we shall use 10bins.

void nBins( int bins, int isEff )
{
  int a, i, x;
  
  ForEach( a, 0, MaxAtt )
  {
    if ( SpecialStatus[a] == Nil )  // Continuous case //
    {
      // Go through each item to get the min and max values.
      // This allows us to cut up the continuous value into bins.
      float minVal = 9999999, maxVal = -9999999, chopIncr = 0, curMin;
      MaxAttVal[a] = bins;
      ForEach( i, 0, MaxItem )
      {
	if ( Item[i][a]._cont_val >= maxVal ) maxVal = Item[i][a]._cont_val;
	else if ( Item[i][a]._cont_val <= minVal ) minVal = Item[i][a]._cont_val;
      }
      curMin = minVal;
      chopIncr = ( maxVal - minVal ) / (float)bins;
      AttValName[a] = (char**)realloc( AttValName[a], (bins+1) * sizeof( char* ) );
      ForEach( x, 1, bins+1 )
      {
	AttValName[a][x] = (char*)malloc( 50 * sizeof( char ) );
	strcpy( AttValName[a][x], "" );
	//sprintf( AttValName[a][x], "Bin %d", x );
	if (isEff ) sprintf( AttValName[a][x], "[ %03.2f to %03.2f ]\0", exp( curMin ), exp( curMin+chopIncr ) );
	else sprintf( AttValName[a][x], "[ %03.2f to %03.2f ]\0", curMin, curMin+chopIncr );
	curMin += chopIncr;
      }
      // Now that we have each bin's min and max, we can change the Item[#][att] to be a bin number, instead of an
      // continuous value.
      curMin = 0;
      ForEach( i, 0, MaxItem )
      {
	curMin = minVal;
	ForEach( x, 0, bins )
	{
	  // If we are less than the current max, we are in bin number x
	  // And end the bin counting.  We are done with this item.
	  if ( Item[i][a]._cont_val <= curMin + chopIncr )
	  {
	    Item[i][a]._discr_val = x;
	    x = bins;
	  }
	  curMin += chopIncr;
	}
      }
      //SpecialStatus[a] == DISCRETE;
    }
  }
}
