actual java code page


Here is the main class that gets passed the name of the input file:



/**
 * This program takes a file with ATWD pulses one it, and displays
 * them using the JAS package.  The data file must be in a specific
 * format as shown below:
 *
 * 90084000 00000064 0000005b 0000005c 0000004e
 * 90084010 0000003f 0000004b 00000047 00000046
 *
 * With the first column being addresses, and the following four
 * columns containing data in hexadecimal form.
 *
 * Created by IntelliJ IDEA.
 * User: phil
 * Date: May 29, 2003
 * Time: 4:33:12 PM
 */
public class DumpDisplayMain {


    public static void main (String[] arg){
       

        ParseDataFile parseDataFile = new ParseDataFile( arg[0] );
        double[][] dataArray = parseDataFile.parse();
        new DumpDisplay( dataArray );

    }

}



The ParseDataFile class
:



import java.io.*;

/**
 * This class actually reads the data from the file, putting the data
 * into a dataArray that is sent to the parse method. The input file
 * name must be included in this classes constructer.
 *
 * Created by IntelliJ IDEA.
 * User: phil
 * Date: May 29, 2003
 * Time: 4:34:13 PM
 */
public class ParseDataFile {

    BufferedReader bufferReader;
    // The data from the file is thrown here.
    double[][] dataArray;
    // Keeps track of how many lines of actual data have been read.
    int lineCounter;
    // The current line being read is stored in this string.
    String currentLine;

    /**
     * Constructor - opens given input file.
     *
     * @param inputFileName
     */
    ParseDataFile( String inputFileName ){

        try {

            bufferReader = new BufferedReader( new InputStreamReader(
                    new FileInputStream ( inputFileName ) ) );
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        }

        this.dataArray = new double[8][128];
        this.lineCounter = 0;
        this.currentLine = null;
    }

    /**
     * Takes data from the file, and enters it into an array of doubles.
     *
     */
    public double[][] parse(){

        try {

            //Reads the first line from the file.
            this.currentLine = bufferReader.readLine();

            do{

                // Processes the line, and then advances the counter
                processLine();
                this.lineCounter++;

                // Reads the next line from the file.
                currentLine = bufferReader.readLine();

                // Continues to read until the file is empty, or enough data
                // for eight waveforms have been read.
            }while( !(currentLine == null) && ( this.lineCounter < 256 ) );

        } catch (IOException e) {
            e.printStackTrace();
        }

        return this.dataArray;
    }

    /**
     *
     * Takes the line of data in currentLine, and converts it to four doubles,
     * and enters those doubles into the correct spot in the array.  Each pulse
     * has 128 entries, with time reversed.  There are eight pulses.
     *
     */
    public void parseLine(){

        // Splits the line of data into the five string tokens
        String tokens[] = this.currentLine.split(" ");

        // Loops for each double in the curentLine
        for(int iToken = 1; iToken < 5; iToken++){

            // Counts which double this entry is
            int entryCounter = this.lineCounter * 4 + iToken;
            // Counts which pulse this entry belongs to
            int channel = (int) Math.floor( entryCounter / 128 );
            // Makes sure the pulse number is within bounds
            if( channel > 7){
                channel = 7;
            }
            // Counts which tick this entry is in the pulse, from 0 to 127
            int tick = ( 127 - ( entryCounter % 128 ) );
            // Converts the hexadecimal string into a double and inserts it
            // into the array
            this.dataArray[channel][tick] = Long.parseLong( tokens[iToken], 16 );
        }

    }

    /**
     * Decides if the currentLine is a line of data or not, and then sends it
     * to parseLine if it is a line of data.
     *
     */
    public void processLine(){

        // A line of data will start with an address beginning with 900
        if( this.currentLine.matches( "^900.+" ) ){

            // Reads the data to the array
            parseLine();
        }else{

            // Since the currentLine was not data, subtracts from this counter
            this.lineCounter--;

        }
    }
}



And the DumpDisplay class:



import jas.hist.JASHist;
import jas.hist.JASHist1DHistogramStyle;
import jas.hist.JASHistData;

import javax.swing.*;
import java.awt.*;

/**
 * Takes eight pulses in an array of doubles and displays them in a window.
 *
 * Created by IntelliJ IDEA.
 * User: phil
 * Date: May 29, 2003
 * Time: 4:42:32 PM
 */
public class DumpDisplay extends JFrame  {

    DumpDisplay( double[][] inputData ){

        // Window title settings, and the property that the program will end
        // when the window is closed
        super( "Dump Display");
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

        JPanel graphArea = new JPanel();
        JASHist1DHistogramStyle histogramStyle = new JASHist1DHistogramStyle();
        JASHist [] dumpPlot = new JASHist[8];
        ArrayData[] arrayData = new ArrayData[8];
        JASHistData jasHistData;

        // Sets a grid on the window, so the histograms can be filled accordingly
        GridLayout graphLayout = new GridLayout( 2 , 4 );
        graphArea.setLayout( graphLayout );

        // Sets the style of the histograms to be displayed
        histogramStyle.setShowErrorBars(false);
        histogramStyle.setShowLinesBetweenPoints(true);
        histogramStyle.setShowHistogramBars(false);
        histogramStyle.setShowDataPoints(true);
        histogramStyle.setDataPointColor( Color.red );
        histogramStyle.setLineColor( Color.black );
        histogramStyle.setDataPointSize( 4 );

        // Loops once for each histogram
        for(int iChannel = 0; iChannel < inputData.length; iChannel++){

            // Catches the loop if it goes longer than necessary
            try{

                dumpPlot[ iChannel ] = new JASHist();
                arrayData[ iChannel ] = new ArrayData();

                // Enters the data from the array of doubles into the arrayData object
                arrayData[ iChannel ].setNewData( inputData[ iChannel ] );

                // Enters the data into the dumpPlot object, creating a jasHistData object
                jasHistData = dumpPlot[ iChannel ].addData( arrayData[ iChannel ]);

                // Sets the style of the histogram to the above settings
                jasHistData.setStyle( histogramStyle );
                jasHistData.show( true );

                // Formats the title and axis of the histogram
                int whichATWD = (int) Math.floor( iChannel / 4 );
                int channel = iChannel % 4;
                dumpPlot[ iChannel ].setTitle( "ATWD" + whichATWD + " Channel " + channel );
                dumpPlot[ iChannel ].getXAxis().setLabel( "Time (Ticks)" );
                dumpPlot[ iChannel ].getYAxis().setLabel( "Amplitude (Ticks)" );

                // Adds the histogram to the window
                graphArea.add( dumpPlot[ iChannel ] );

         }catch( ArrayIndexOutOfBoundsException e ){

                break;
            }
        }

        // Shows the JPanel window after the histograms have been added
        setContentPane( graphArea );
        setSize( 1000, 600 );
        show();

    }

}