edu.rit.clu.antimatter
Class AntiprotonFile

java.lang.Object
  extended by edu.rit.clu.antimatter.AntiprotonFile

public class AntiprotonFile
extends Object

Class AntiprotonFile provides an object for reading or writing a series of snapshots of antiproton positions from or to a file.

To write the snapshots to a file, call the prepareToWrite() method, specifying the output stream to write. The prepareToWrite() method returns an instance of class AntiprotonFile.Writer. Call the methods of the writer object to write the antiproton position snapshots to the output stream. When finished, close the writer.

To read the snapshots from a file, call the prepareToRead() method, specifying the input stream to read. The prepareToRead() method returns an instance of class AntiprotonFile.Reader. Call the methods of the reader object to read the antiproton position snapshots from the input stream. When finished, close the reader.

Class AntiprotonFile includes a main program to combine a group of antiproton files into one antiproton file. You might use this main program when the processes of a parallel program have computed slices of the antiprotons and stored the slices in separate files, and you want to combine the slices together into one file.

Antiproton File Format

An antiproton file is a binary file containing the following items. Each primitive item is written as though by java.io.DataOutput (int, four bytes; long, eight bytes; double, eight bytes; most significant byte first).

Each snapshot contains the following items. A snapshot contains information about a slice of the antiprotons.


Nested Class Summary
 class AntiprotonFile.Reader
          Class AntiprotonFile.Reader provides an object with which to read an AntiprotonFile from an input stream.
 class AntiprotonFile.Writer
          Class AntiprotonFile.Writer provides an object with which to write an AntiprotonFile to an output stream.
 
Constructor Summary
AntiprotonFile()
          Construct a new antiproton file object.
AntiprotonFile(long seed, double R, double dt, int steps, int snaps, int N, int L, int M)
          Construct a new antiproton file object with the given attributes.
 
Method Summary
 double getDt()
          Get the time step size.
 int getL()
          Get the lower antiproton index for each snapshot.
 int getM()
          Get the number of antiprotons in each snapshot.
 int getN()
          Get the total number of antiprotons.
 double getR()
          Get the side of the square used to generate the initial antiproton positions.
 long getSeed()
          Get the random seed used to generate the initial antiproton positions.
 int getSnaps()
          Get the number of snapshots.
 int getSteps()
          Get the number of time steps between snapshots.
static void main(String[] args)
          Main program to combine a group of antiproton files into one antiproton file.
 AntiprotonFile.Reader prepareToRead(InputStream theStream)
          Prepare to read this antiproton file from the given input stream.
 AntiprotonFile.Writer prepareToWrite(OutputStream theStream)
          Prepare to write this antiproton file to the given output stream.
 void setAttributes(long seed, double R, double dt, int steps, int snaps, int N, int L, int M)
          Set this antiproton file's attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AntiprotonFile

public AntiprotonFile()
Construct a new antiproton file object. The antiproton file's attributes are uninitialized. Before using the antiproton file, specify the attributes by calling the setAttributes() method or by reading the antiproton file from an input stream.


AntiprotonFile

public AntiprotonFile(long seed,
                      double R,
                      double dt,
                      int steps,
                      int snaps,
                      int N,
                      int L,
                      int M)
Construct a new antiproton file object with the given attributes.

Parameters:
seed - Random seed used to generate the initial antiproton positions.
R - Side of the square used to generate the initial antiproton positions.
dt - Time step size.
steps - Number of time steps between snapshots.
snaps - Number of snapshots.
N - Total number of antiprotons.
L - Lower antiproton index for each snapshot.
M - Number of antiprotons in each snapshot.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if R <= 0. Thrown if dt <= 0. Thrown if steps <= 0. Thrown if snaps < 0. Thrown if N < 0.
IndexOutOfBoundsException - (unchecked exception) Thrown if L < 0. Thrown if M < 0. Thrown if L+M > N.
Method Detail

getSeed

public long getSeed()
Get the random seed used to generate the initial antiproton positions.

Returns:
Random seed, seed.

getR

public double getR()
Get the side of the square used to generate the initial antiproton positions.

Returns:
Side, R.

getDt

public double getDt()
Get the time step size.

Returns:
Time step size, dt.

getSteps

public int getSteps()
Get the number of time steps between snapshots.

Returns:
Number of time steps, steps.

getSnaps

public int getSnaps()
Get the number of snapshots.

Returns:
Number of snapshots, snaps.

getN

public int getN()
Get the total number of antiprotons.

Returns:
Total number of antiprotons, N.

getL

public int getL()
Get the lower antiproton index for each snapshot.

Returns:
Lower antiproton index for each snapshot, L.

getM

public int getM()
Get the number of antiprotons in each snapshot.

Returns:
Number of antiprotons in each snapshot, M.

setAttributes

public void setAttributes(long seed,
                          double R,
                          double dt,
                          int steps,
                          int snaps,
                          int N,
                          int L,
                          int M)
Set this antiproton file's attributes.

Parameters:
seed - Random seed used to generate the initial antiproton positions.
R - Side of the square used to generate the initial antiproton positions.
dt - Time step size.
steps - Number of time steps between snapshots.
snaps - Number of snapshots.
N - Total number of antiprotons.
L - Lower antiproton index for each snapshot.
M - Number of antiprotons in each snapshot.
Throws:
IllegalArgumentException - (unchecked exception) Thrown if R <= 0. Thrown if dt <= 0. Thrown if steps <= 0. Thrown if snaps < 0. Thrown if N < 0.
IndexOutOfBoundsException - (unchecked exception) Thrown if L < 0. Thrown if M < 0. Thrown if L+M > N.

prepareToWrite

public AntiprotonFile.Writer prepareToWrite(OutputStream theStream)
                                     throws IOException
Prepare to write this antiproton file to the given output stream. This matrix file's attributes are written to the output stream at this time. To write this antiproton file's snapshots, call methods on the returned writer, then close the writer.

For improved performance, specify an output stream with buffering, such as an instance of class java.io.BufferedOutputStream.

Parameters:
theStream - Output stream.
Returns:
Writer object with which to write this antiproton file.
Throws:
IllegalStateException - (unchecked exception) Thrown if this antiproton file object is uninitialized.
NullPointerException - (unchecked exception) Thrown if theStream is null.
IOException - Thrown if an I/O error occurred.

prepareToRead

public AntiprotonFile.Reader prepareToRead(InputStream theStream)
                                    throws IOException
Prepare to read this antiproton file from the given input stream. This antiproton file's attributes are read from the input stream at this time. To read this antiproton file's snapshots, call methods on the returned reader, then close the reader.

For improved performance, specify an input stream with buffering, such as an instance of class java.io.BufferedInputStream.

Parameters:
theStream - Input stream.
Returns:
Reader object with which to read this antiproton file.
Throws:
NullPointerException - (unchecked exception) Thrown if theStream is null.
IOException - Thrown if an I/O error occurred.

main

public static void main(String[] args)
                 throws Exception
Main program to combine a group of antiproton files into one antiproton file. Each input file must be for an antiproton array with the same number of elements. Each input file must contain the same number of snapshots.

You might use this main program when the processes of a parallel program have computed slices of antiprotons and stored the slices in separate files, and you want to combine the slices together into one file.

Usage: java edu.rit.io.AntiprotonFile outfile infile1 [ infile2 . . . ]

Throws:
Exception


Copyright © 2005-2012 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.