#include <cstdio>
#include <cassert>

#include "blyth-still-casella.hh"
#include "clopper-pearson.hh"

int main( int argc, char *argv[] )
{
  if ( argc != 3 ) {
    fprintf( stderr,
	     "Usage: %s NUM_TOTAL CONFIDENCE\nExample: %s 100 0.95\n",
	     argv[ 0 ], argv[ 0 ] );
    exit( 1 );
  }

  const unsigned int num_total = myatoi( argv[ 1 ] );
  const double confidence = myatof( argv[ 2 ] );

  assert( num_total > 0 );
  assert( confidence >= 0.0 );
  assert( confidence < 1.0 );

  ClopperPearson cp( num_total, 1 - confidence );
  BlythStillCasella bsc( cp.limits() );
  IntervalCollection lims = bsc.limits();

  printf("lower;upper\n");
  for(size_t i=0;i<=lims.N();i++) {
    printf("%.8lf;%.8lf\n",lims.limits[i].lower,lims.limits[i].upper);
  }
  return 0;
}

