From: <ha...@us...> - 2007-02-17 05:17:18
|
Revision: 6841 http://svn.sourceforge.net/jmol/?rev=6841&view=rev Author: hansonr Date: 2007-02-16 21:17:16 -0800 (Fri, 16 Feb 2007) Log Message: ----------- Static parser applied to Viewer classes Modified Paths: -------------- trunk/Jmol/src/org/jmol/viewer/Frame.java trunk/Jmol/src/org/jmol/viewer/Isosurface.java trunk/Jmol/src/org/jmol/viewer/Pmesh.java Removed Paths: ------------- trunk/Jmol/src/org/jmol/viewer/MeshFileCollection.java Modified: trunk/Jmol/src/org/jmol/viewer/Frame.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Frame.java 2007-02-17 05:15:59 UTC (rev 6840) +++ trunk/Jmol/src/org/jmol/viewer/Frame.java 2007-02-17 05:17:16 UTC (rev 6841) @@ -3091,16 +3091,16 @@ } void loadCoordinates(String data) { - Parser p = new Parser(); - int[] lines = p.markLines(data, ';'); + int[] next = new int[1]; + int[] lines = Parser.markLines(data, ';'); try { - int nData = p.parseInt(data.substring(0, lines[0] - 1)); + int nData = Parser.parseInt(data.substring(0, lines[0] - 1), next); for (int i = 1; i <= nData; i++) { - String[] tokens = p.getTokens(p.parseTrimmed(data.substring(lines[i], lines[i + 1]))); - int atomIndex = p.parseInt(tokens[0]) - 1; - float x = p.parseFloat(tokens[3]); - float y = p.parseFloat(tokens[4]); - float z = p.parseFloat(tokens[5]); + String[] tokens = Parser.getTokens(Parser.parseTrimmed(data.substring(lines[i], lines[i + 1]), next)); + int atomIndex = Parser.parseInt(tokens[0], next) - 1; + float x = Parser.parseFloat(tokens[3], next); + float y = Parser.parseFloat(tokens[4], next); + float z = Parser.parseFloat(tokens[5], next); setAtomCoord(atomIndex, x, y, z); } } catch (Exception e) { Modified: trunk/Jmol/src/org/jmol/viewer/Isosurface.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Isosurface.java 2007-02-17 05:15:59 UTC (rev 6840) +++ trunk/Jmol/src/org/jmol/viewer/Isosurface.java 2007-02-17 05:17:16 UTC (rev 6841) @@ -1327,7 +1327,7 @@ if (!isSilent) Logger.debug(line); atomCount = parseInt(line); - String atomLine = line.substring(ichNextParse); + String atomLine = line.substring(next[0]); negativeAtomCount = (atomCount < 0); if (!isSilent) Logger.debug("atom Count: " + atomCount); @@ -1446,7 +1446,7 @@ */ boolean inside = false; int dataCount = 0; - ichNextParse = 0; + next[0] = 0; nThisValue = 0; surfaceData = ""; nPointsX = voxelCounts[0]; @@ -1867,7 +1867,7 @@ int n = parseInt(str); while (n != Integer.MIN_VALUE) { count += n; - n = parseInt(str, ichNextParse); + n = parseIntNext(str); } return count; } @@ -2541,7 +2541,7 @@ } else { for (int c = 0; c < nChar; c++) dataOut += chLast; - i = ichNextParse; + i = next[0]; } } else { dataOut += ch; Deleted: trunk/Jmol/src/org/jmol/viewer/MeshFileCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/MeshFileCollection.java 2007-02-17 05:15:59 UTC (rev 6840) +++ trunk/Jmol/src/org/jmol/viewer/MeshFileCollection.java 2007-02-17 05:17:16 UTC (rev 6841) @@ -1,170 +0,0 @@ -/* $RCSfile$ - * $Author: hansonr $ - * $Date: 2006-11-16 14:04:41 -0600 (Thu, 16 Nov 2006) $ - * $Revision: 6233 $ - * - * Copyright (C) 2002-2005 The Jmol Development Team - * - * Contact: jmo...@li... - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jmol.viewer; - -abstract class MeshFileCollection extends MeshCollection { - - String line; - int ichNextParse; - - float parseFloat() { - return parseFloat(line, ichNextParse); - } - - float parseFloat(String str) { - return parseFloatChecked(str, 0, str.length()); - } - - float parseFloat(String str, int ich) { - int cch = str.length(); - if (ich >= cch) - return Float.NaN; - return parseFloatChecked(str, ich, cch); - } - - float parseFloat(String str, int ichStart, int ichMax) { - int cch = str.length(); - if (ichMax > cch) - ichMax = cch; - if (ichStart >= ichMax) - return Float.NaN; - return parseFloatChecked(str, ichStart, ichMax); - } - - final static float[] decimalScale = - {0.1f, 0.01f, 0.001f, 0.0001f, 0.00001f, 0.000001f, 0.0000001f, 0.00000001f}; - final static float[] tensScale = - {10, 100, 1000, 10000, 100000, 1000000}; - - float parseFloatChecked(String str, int ichStart, int ichMax) { - boolean digitSeen = false; - float value = 0; - int ich = ichStart; - char ch; - while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' || ch == '\t')) - ++ich; - boolean negative = false; - if (ich < ichMax && str.charAt(ich) == '-') { - ++ich; - negative = true; - } - ch = 0; - while (ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') { - value = value * 10 + (ch - '0'); - ++ich; - digitSeen = true; - } - if (ch == '.') { - int iscale = 0; - while (++ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') { - if (iscale < decimalScale.length) - value += (ch - '0') * decimalScale[iscale]; - ++iscale; - digitSeen = true; - } - } - if (! digitSeen) - value = Float.NaN; - else if (negative) - value = -value; - if (ich < ichMax && (ch == 'E' || ch == 'e')) { - if (++ich >= ichMax) - return Float.NaN; - ch = str.charAt(ich); - if ((ch == '+') && (++ich >= ichMax)) - return Float.NaN; - int exponent = parseIntChecked(str, ich, ichMax); - if (exponent == Integer.MIN_VALUE) - return Float.NaN; - if (exponent > 0) - value *= ((exponent < tensScale.length) - ? tensScale[exponent - 1] - : Math.pow(10, exponent)); - else if (exponent < 0) - value *= ((-exponent < decimalScale.length) - ? decimalScale[-exponent - 1] - : Math.pow(10, exponent)); - } else { - ichNextParse = ich; // the exponent code finds its own ichNextParse - } - //Logger.debug("parseFloat(" + str + "," + ichStart + "," + - // ichMax + ") -> " + value); - return value; - } - - int parseInt() { - return parseInt(line, ichNextParse); - } - - int parseInt(String str) { - return parseIntChecked(str, 0, str.length()); - } - - int parseInt(String str, int ich) { - int cch = str.length(); - if (ich >= cch) - return Integer.MIN_VALUE; - return parseIntChecked(str, ich, cch); - } - - int parseInt(String str, int ichStart, int ichMax) { - int cch = str.length(); - if (ichMax > cch) - ichMax = cch; - if (ichStart >= ichMax) - return Integer.MIN_VALUE; - return parseIntChecked(str, ichStart, ichMax); - } - - int parseIntChecked(String str, int ichStart, int ichMax) { - boolean digitSeen = false; - int value = 0; - int ich = ichStart; - char ch; - while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' || ch == '\t')) - ++ich; - boolean negative = false; - if (ich < ichMax && str.charAt(ich) == '-') { - negative = true; - ++ich; - } - while (ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') { - value = value * 10 + (ch - '0'); - digitSeen = true; - ++ich; - } - if (! digitSeen) - value = Integer.MIN_VALUE; - else if (negative) - value = -value; - //Logger.debug("parseInt(" + str + "," + ichStart + "," + - // ichMax + ") -> " + value); - ichNextParse = ich; - return value; - } - -} - - \ No newline at end of file Modified: trunk/Jmol/src/org/jmol/viewer/Pmesh.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Pmesh.java 2007-02-17 05:15:59 UTC (rev 6840) +++ trunk/Jmol/src/org/jmol/viewer/Pmesh.java 2007-02-17 05:17:16 UTC (rev 6841) @@ -122,8 +122,8 @@ for (int i = 0; i < currentMesh.vertexCount; ++i) { String line = br.readLine(); float x = parseFloat(line); - float y = parseFloat(line, ichNextParse); - float z = parseFloat(line, ichNextParse); + float y = parseFloat(); + float z = parseFloat(); currentMesh.vertices[i] = new Point3f(x, y, z); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |