static String determineFileType(BufferedReader bufferedReader) { // JVXL should be on the FIRST line of the file, but it may be // after comments or missing. // Apbs, Jvxl, or Cube String line; LimitedLineReader br = new LimitedLineReader(bufferedReader, 16000); // sure bets, but not REQUIRED: if ((line = br.info()).indexOf("#JVXL+") == 0) return "Jvxl+"; if (line.indexOf("#JVXL") == 0) return "Jvxl"; if (line.indexOf("&plot") == 0) return "Jaguar"; if (line.indexOf("!NTITLE") >= 0 || line.indexOf("REMARKS ") >= 0) return "Xplor"; line = br.readNonCommentLine(); if (line.indexOf("object 1 class gridpositions counts") == 0) return "Apbs"; // Jvxl, or Cube, maybe formatted Plt String[] tokens = Parser.getTokens(line); line = br.readNonCommentLine(); // second line if (tokens.length == 2 && Parser.parseInt(tokens[0]) == 3 && Parser.parseInt(tokens[1]) != Integer.MIN_VALUE) { tokens = Parser.getTokens(line); if (tokens.length == 3 && Parser.parseInt(tokens[0]) != Integer.MIN_VALUE && Parser.parseInt(tokens[1]) != Integer.MIN_VALUE && Parser.parseInt(tokens[2]) != Integer.MIN_VALUE) return "PltFormatted"; } line = br.readNonCommentLine(); // third line // next line should be the atom line int nAtoms = Parser.parseInt(line); if (nAtoms == Integer.MIN_VALUE) return (line.indexOf("+") == 0 ? "Jvxl+" : "UNKNOWN"); if (nAtoms >= 0) return "Cube"; // Can't be a Jvxl file nAtoms = -nAtoms; for (int i = 4 + nAtoms; --i >= 0; ) if ((line = br.readNonCommentLine()) == null) return "UNKNOWN"; int nSurfaces = Parser.parseInt(line); if (nSurfaces == Integer.MIN_VALUE) return "UNKNOWN"; return (nSurfaces < 0 ? "Jvxl" : "Cube"); // Final test looks at surface definition line }
int parseInt(String s, int iStart) { next[0] = iStart; return Parser.parseInt(s, next); }
int parseIntNext(String s) { return Parser.parseInt(s, next); }
int parseInt(String s) { next[0] = 0; return Parser.parseInt(s, next); }
int parseInt() { return Parser.parseInt(line, next); }
protected int parseInt(String s, int iStart, int iEnd) { next[0] = iStart; return Parser.parseInt(s, iEnd, next); }