1 #include "mrilib.h"
2 
main(int argc,char * argv[])3 int main( int argc , char * argv[] )
4 {
5    double qq , nn , pp , tt ;
6 
7    if( argc < 4 || strcmp(argv[1],"-help")==0 ){
8       printf("Usage: ibinom Q N p\n"
9              "  Q = upper tail probability\n"
10              "  N = number of trials\n"
11              "  p = probability of success per trial\n"
12              "Output is value 'm' such that the binomial probability\n"
13              "of getting m or more successes in N trials is Q.\n"
14             ) ;
15       exit(0) ;
16    }
17 
18    qq = strtod( argv[1] , NULL ) ;
19    nn = strtod( argv[2] , NULL ) ;
20    pp = strtod( argv[3] , NULL ) ;
21 
22 #define BAD(str) ( fprintf(stderr,"Bad value of %s\n",str) , exit(1) )
23 
24    if( qq <= 0.0 || qq >= 1.0 ) BAD("Q") ;
25    if( nn <= 1.0 )              BAD("N") ;
26    if( pp <= 0.0 || pp >= 1.0 ) BAD("p") ;
27 
28    tt = binomial_p2t( qq , nn , pp ) ;
29    printf("threshold = %g\n",tt) ;
30    exit(0) ;
31 }
32