/** * Converts bandscop.txt to bandscop.dat for applet bandscope.class * @author Robert J Morton * @version 25 Feb 2002 */ /* This program uses the Java 1.1.8 API. Format of a data line as it arrives from the AR8600 into bs.txt DS0319:2222222222222222 2222222222222222 COMMAND LINE ARGUMENT IS FILE NAME WITHOUT EXTENSION */ import java.io.*; class bstxtdat { public static void main(String args[]) throws IOException { int B[] = new int[1000], // byte array for signal strengths fs = 0, // frequency span b = 0, // data byte number l = 0, // data line number q = 0, // sample block number start = 0, end = 1000; String s; if(args.length < 2) { System.out.println("parameters required:"); System.out.println("FileName (no extension) &"); System.out.println("Lines per block (4 or 32)"); } else { String fn = args[0]; int bl = Integer.parseInt(args[1]); for(int k = 0; k < 1000; k++) B[k] = 0; // OPEN THE INPUT STREAM FROM THE AR86000 BufferedReader r = new BufferedReader( new InputStreamReader( new FileInputStream(fn + ".txt") ) ); // READ IN EACH AR86000 BANDSCOPE DATA LINE while((s = r.readLine()) != null) { if(s.startsWith("DS") // provided it starts with "DS" && (s.indexOf(":") == 6)) { // and 7th char is a colon s = s.substring(7, 23) // form the 32-character data string + s.substring(24, 40); if(l == 0) s = s.substring(12, 32); // skip the first 12 bytes of Line 1 else if((bl == 4) // if the block length is 4 && (l == 3) // and the length is 3 || (bl == 32) // or the block length is 32 && (l == 31)) // and the length is 31 s = s.substring(0, 20); // skip last 12 bytes of Line 32 /* For each Hex character in the line string, write hex char as an int value to array. */ for(int i = 0; i < s.length(); i++) B[b++] += Character.digit(s.charAt(i),16); if(++l == bl) { // increment the line number b = 0; l = 0; q++; } } } r.close(); // close the AR86000 input stream System.out.println("q = " + q); // print number of blocks if(bl == 4) { // if it is a short data file start = 2; end = 102; } for(int k = start; k < end; k++) B[k] /= q; // OPEN THE BANDSCOPE DATA OUTPUT FILE [bs.dat] DataOutputStream w = new DataOutputStream( new FileOutputStream(fn + ".dat") ); /* Proceeding reverse direction, write hex char as a single signed byte value to bs.dat. */ for(int k = end - 1; k > start - 1; k--) w.writeByte(B[k]); w.close(); // close the bandscope data output file } } }