/** * title: Frame Error Rate Calculator * author: Matt Rankin, 2007 */ public class ErrorProb{ static char type; static double probF,fSize,probB; public static void main(String[] argv){ if(argv.length<1 || argv.length>3) type='h'; else type=(argv[0].matches("-[fh]"))?argv[0].charAt(1):'h'; switch(type){ case 'f': probF=calcProb(argv[1],argv[2]); System.out.println("Frame Error Rate is: "+probF); break; case 'h': System.out.println(help()); break; } System.exit(0); } static double calcProb(String f,String p){ try{ fSize=Double.parseDouble(f); probB=1/Double.parseDouble(p); }catch(NumberFormatException e){ epicFail(); } double r1=fSize*probB; if(r1<0.1){ System.err.println("simple < 0.1"); return r1; }else{ System.err.println("complicated"); return 1-Math.pow((1-probB),fSize); } } static String help(){ String h; h="Calculates probability of a frame error given a frame size and a\n"+ "BER (Bit Error Rate).\n\n"+ " ErrorProb -[fh] framesize BER\n\n"+ " -f Calculate frame error rate\n"+ " -h Help\n"+ " framesize Frame size (in bits)\n"+ " BER Bit Error Rate (1/n)\n\n"+ "The only functional option for this program requires the two\n"+ "specified values in a set order. The syntax for the BER parameter is\n"+ "the denominator over 1. So for an error rate of 1 in 1,000, simply\n"+ "enter '1000' as your paramenter."; return h; } static void epicFail(){ System.err.println("Epic fail!"); System.exit(0); } }