};
// reset inputfile pointer to start position
this.randomAccessFile.seek(0);
LongArrayList tempFramePositions = new LongArrayList(50000); // tmp vector to store the starting position of the
// frames randomAccessFile input file (length of
// vector can be increased, the length of a array
// not !)
int framesDetected = 0;
long pos = 0;
int magicRead; // frameHeader
int noOfAtomsRead; // frameHeader
int noOfAtomsRead2; // coordinates header
int sizeOfCoordinates; // coordinates header
/*
* double realExpectedTime = 0.0d; double expectedTime = 0.0d; double
* eps = 0.1d;
*/
do
{
pos = randomAccessFile.getFilePointer();
tempFramePositions.add(pos);
// System.out.println("Frame " + framesDetected + " at " + pos );
framesDetected++;
magicRead = randomAccessFile.readInt(); // 4
if (magicRead == this.magicNrFileVersion)
{
noOfAtomsRead = randomAccessFile.readInt(); // 4
// frameNoRead = randomAccessFile.readInt(); // 4
// simulationTime = randomAccessFile.readFloat();// 4 is simulation time
// 36 is 3x3 cell axis a 4bytes each
randomAccessFile.skipBytes(4 + 4 + 36);
// 52 randomAccessFile total
/*
* //200 - 0.4 System.out.println( "off: " +
* randomAccessFile.getFilePointer() + " frame# " + frameNoRead
* + " sim t: " + simulationTime + " expected t after reset: " +
* expectedTime + " real t: " + realExpectedTime); if (
* Math.abs( (double)simulationTime - expectedTime ) > eps ) {
* System.out.println( "Missing: off: " +
* randomAccessFile.getFilePointer() + " frame# " + frameNoRead
* + " sim t: " + simulationTime + " expected t after reset: " +
* expectedTime + " real t: " + realExpectedTime); expectedTime
* = simulationTime; } expectedTime += 0.2d; realExpectedTime +=
* 0.2d;
*
*/
// now entering coordinates header
noOfAtomsRead2 = randomAccessFile.readInt();
if (noOfAtomsRead == noOfAtomsRead2)
{
if (noOfAtomsRead > 9)
{ // compressed format (case b)
// 4 is precision
// 24 = (4 * 2 * 3 ) is min and max of x, y and z
// 4 is number of bits used for compression
randomAccessFile.skipBytes(4 + 24 + 4);
sizeOfCoordinates = randomAccessFile.readInt();
int mod4 = sizeOfCoordinates % 4;
if (mod4 > 0)
{
sizeOfCoordinates += (4 - mod4);
}
randomAccessFile.skipBytes(sizeOfCoordinates); // skip coordinates
}
else
{ // uncompressed format (case a)
// x, y and z per atom a 4 bytes each
randomAccessFile.skipBytes(noOfAtomsRead * 3 * 4);
}
}
else
{
throw new RuntimeException("Problem with atom sizes");
} // end if-else
}
else
{
throw new RuntimeException("No magic bytes found. Error in trajectory.");
} // end if-else
}
while (randomAccessFile.getFilePointer() < randomAccessFile.length());
this.numOfFrames = framesDetected;
// copy starting postion of frames from vector into an array and check their size
int numberOfFrames = tempFramePositions.size();
this.framePos = new long[numberOfFrames];
this.frameBroken = new BitSet(numberOfFrames);
long tmpPosition_old = 0; // tmp variable to calculate the size of a frame
for (int i = 0; i < numberOfFrames; i++)
{
long tmpPosition = tempFramePositions.getLong(i);
if (((tmpPosition - tmpPosition_old) % 4) != 0)
{ // check if the frame size is a multiple of 4 bytes
this.frameBroken.set(i); // mark frame as broken
System.err.println("WARNING: Frame " + i