private void read_Array(float[][] arr, int r) { try { int i, j, tkns; String[] tempArr; String line, temp; StringTokenizer token; for (i = 0; i < r; i++) { // Turn this for loop into a function because it will be reused 3 times. line = dFile.readLine(); token = new StringTokenizer(line); tkns = token.countTokens(); if (tkns == 4) { temp = token.nextToken(); tempArr = token.nextToken().split("\\]|=|\\{|,"); arr[i][0] = Float.parseFloat(tempArr[3]); tempArr = token.nextToken().split(","); arr[i][1] = Float.parseFloat(tempArr[0]); tempArr = token.nextToken().split("\\}"); arr[i][2] = Float.parseFloat(tempArr[0]); } else if (tkns == 5) { temp = token.nextToken(); temp = token.nextToken(); tempArr = token.nextToken().split("\\]|=|\\{|,"); arr[i][0] = Float.parseFloat(tempArr[0]); tempArr = token.nextToken().split(","); arr[i][1] = Float.parseFloat(tempArr[0]); tempArr = token.nextToken().split("\\}"); arr[i][2] = Float.parseFloat(tempArr[0]); } } } catch (IOException e) { System.err.println(e); } }
// private float mean(int nO){return 0.0;} private void read_header(String line, String[] frameData) { try { String[] tempArr; String temp; StringTokenizer token; token = new StringTokenizer(line); int c, r, i, j, tkns; if (token.countTokens() != 3) { System.out.println( "ERROR:A line that does not have 3 tokens can not be the begining of a frame."); } else { temp = token.nextToken(); temp = token.nextToken(); tempArr = token.nextToken().split(":"); frameData[0] = tempArr[0]; line = dFile.readLine(); token = new StringTokenizer(line); temp = token.nextToken(); frameData[1] = token.nextToken(); temp = token.nextToken(); frameData[2] = token.nextToken(); tempArr = token.nextToken().split("="); frameData[3] = tempArr[1]; temp = token.nextToken(); frameData[4] = token.nextToken(); } } catch (IOException e) { System.err.println(e); } }
private void read_frame(float[][] box, float[][] crd, float[][] vel, float[][] frc) { try { String[] tempArr; String line, temp; StringTokenizer token; int c, r, i, j, tkns; line = dFile.readLine(); token = new StringTokenizer(line); if (token.nextToken().equals("box")) { tempArr = token.nextToken().split("\\(|x|\\)|:"); r = Integer.parseInt(tempArr[1]); c = Integer.parseInt(tempArr[2]); read_Array(box, r); } line = dFile.readLine(); token = new StringTokenizer(line); if (token.nextToken().equals("x")) { tempArr = token.nextToken().split("\\(|x|\\)|:"); r = Integer.parseInt(tempArr[1]); c = Integer.parseInt(tempArr[2]); read_Array(crd, r); } line = dFile.readLine(); token = new StringTokenizer(line); if (token.nextToken().equals("v")) { tempArr = token.nextToken().split("\\(|x|\\)|:"); r = Integer.parseInt(tempArr[1]); c = Integer.parseInt(tempArr[2]); read_Array(vel, r); } line = dFile.readLine(); token = new StringTokenizer(line); if (token.nextToken().equals("f")) { tempArr = token.nextToken().split("\\(|x|\\)|:"); r = Integer.parseInt(tempArr[1]); c = Integer.parseInt(tempArr[2]); read_Array(frc, r); } } catch (IOException e) { System.err.println(e); } }
public void read_trr_file() { try { String line; int lineCount, frameCount, natoms, i; float time; lineCount = frameCount = 0; while ((line = dFile.readLine()) != null) { if (frameCount == 0) { read_header(line, frameData1); natoms = Integer.parseInt(frameData1[1]); box1 = new float[3][3]; crd1 = new float[natoms][3]; vel1 = new float[natoms][3]; frc1 = new float[natoms][3]; read_frame(box1, crd1, vel1, frc1); frameCount++; } else if (frameCount == 1) { read_header(line, frameData2); natoms = Integer.parseInt(frameData2[1]); time = Float.parseFloat(frameData2[3]); box2 = new float[3][3]; crd2 = new float[natoms][3]; vel2 = new float[natoms][3]; frc2 = new float[natoms][3]; read_frame(box2, crd2, vel2, frc2); write_xvg_mean_sd(time, natoms, crd1, crd2, box2, "crd"); write_MSD(time, natoms, crd1, crd2, box2); write_xvg_mean_sd(time, natoms, vel1, vel2, box2, "vel"); write_xvg_mean_sd(time, natoms, frc1, frc2, box2, "frc"); // System.out.println(frameCount+" "+time+" crd1, crd2: "+frameData1[1]+" // "+frameData2[1]+" "+frameData1[2]+" "+frameData2[2]+" "+frameData1[3]+" // "+frameData2[3]); frameCount++; } else { if ((frameCount % 2) == 0) { read_header(line, frameData1); natoms = Integer.parseInt(frameData1[1]); time = Float.parseFloat(frameData1[3]); box1 = new float[3][3]; crd1 = new float[natoms][3]; vel1 = new float[natoms][3]; frc1 = new float[natoms][3]; read_frame(box1, crd1, vel1, frc1); write_xvg_mean_sd(time, natoms, crd2, crd1, box1, "crd"); write_xvg_mean_sd(time, natoms, vel2, vel1, box1, "vel"); write_xvg_mean_sd(time, natoms, frc2, frc1, box1, "frc"); // System.out.println(frameCount+" "+time+" crd2, crd1: "+frameData2[1]+" // "+frameData1[1]+" "+frameData2[2]+" "+frameData1[2]+" "+frameData2[3]+" // "+frameData1[3]); frameCount++; } else { read_header(line, frameData2); natoms = Integer.parseInt(frameData2[1]); time = Float.parseFloat(frameData2[3]); box2 = new float[3][3]; crd2 = new float[natoms][3]; vel2 = new float[natoms][3]; frc2 = new float[natoms][3]; read_frame(box2, crd2, vel2, frc2); write_xvg_mean_sd(time, natoms, crd1, crd2, box2, "crd"); write_xvg_mean_sd(time, natoms, vel1, vel2, box2, "vel"); write_xvg_mean_sd(time, natoms, frc1, frc2, box2, "frc"); // System.out.println(frameCount+" "+time+" crd1, crd2: "+frameData1[1]+" // "+frameData2[1]+" "+frameData1[2]+" "+frameData2[2]+" "+frameData1[3]+" // "+frameData2[3]); frameCount++; } } } } catch (IOException e) { System.err.println(e); } }