?? hspiceout.java
字號(hào):
for(int j=0; j<4; j++) line.append((char)getByteFromFile()); } if (!line.toString().equals("$&%#")) { System.out.println("HSpice header improperly terminated (got "+line.toString()+")"); closeInput(); stopProgressDialog(); return; } resetBinaryTRACDCReader(); // setup the simulation information boolean isComplex = analysisType == Analysis.ANALYSIS_AC; double[] minValues = new double[numSignals]; double[] maxValues = new double[numSignals]; Arrays.fill(minValues, Double.POSITIVE_INFINITY); Arrays.fill(maxValues, Double.NEGATIVE_INFINITY); int sweepCounter = sweepcnt; for(;;) { // get sweep info if (sweepcnt > 0) { float sweepValue = getHSpiceFloat(false); if (eofReached) { System.out.println("EOF before sweep data"); break; } String sweepName = TextUtils.formatDouble(sweepValue); if (DEBUGCONDITIONS) System.out.println("READING SWEEP NUMBER: "+sweepValue); // if there are more than 2 conditions, read extra sweep values for(int i=2; i<cndcnt; i++) { float anotherSweepValue = getHSpiceFloat(false); if (eofReached) { System.out.println("EOF reading sweep header"); break; } sweepName += "," + TextUtils.formatDouble(anotherSweepValue); if (DEBUGCONDITIONS) System.out.println(" EXTRA SWEEP NUMBER: "+anotherSweepValue); } an.addSweep(sweepName); } // now read the data List<float[]> allTheData = new ArrayList<float[]>(); for(;;) { // get the first number, see if it terminates float time = getHSpiceFloat(true); if (eofReached) break; float [] oneSetOfData = new float[isComplex ? numSignals*2 + 1 : numSignals + 1]; oneSetOfData[0] = time; // get a row of numbers for(int k=0; k<numSignals; k++) { int numSignal = (k + numnoi) % numSignals; double value; if (isComplex) { float realPart = getHSpiceFloat(false); float imagPart = getHSpiceFloat(false); oneSetOfData[numSignal*2 + 1] = realPart; oneSetOfData[numSignal*2 + 2] = imagPart; value = Math.hypot(realPart, imagPart); // amplitude of complex number } else { value = oneSetOfData[numSignal + 1] = getHSpiceFloat(false); } if (eofReached) { System.out.println("EOF in the middle of the data (at " + k + " out of " + numSignals + " after " + allTheData.size() + " sets of data)"); break; } if (value < minValues[numSignal]) minValues[numSignal] = value; if (value > maxValues[numSignal]) maxValues[numSignal] = value; } if (eofReached) { System.out.println("EOF before the end of the data"); break; } allTheData.add(oneSetOfData); } an.theSweeps.add(allTheData); sweepCounter--; if (sweepCounter <= 0) break; eofReached = false; } closeInput(); // Put data to Stimuli an.commonTime = new double[an.theSweeps.size()][]; double minTime = Double.POSITIVE_INFINITY; double maxTime = Double.NEGATIVE_INFINITY; for (int sweepNum=0; sweepNum<an.commonTime.length; sweepNum++) { List<float[]> allTheData = an.theSweeps.get(sweepNum); an.commonTime[sweepNum] = new double[allTheData.size()]; for (int eventNum = 0; eventNum < allTheData.size(); eventNum++) { double time = allTheData.get(eventNum)[0]; an.commonTime[sweepNum][eventNum] = time; if (time < minTime) minTime = time; if (time > maxTime) maxTime = time; } } // preprocess signal names to remove constant prefix (this code also occurs in VerilogOut.readVerilogFile) String constantPrefix = null; boolean hasPrefix = true; for(int k=0; k<numSignals; k++) { String name = signalNames[k]; int dotPos = name.indexOf('.'); if (dotPos < 0) continue; String prefix = name.substring(0, dotPos); if (constantPrefix == null) constantPrefix = prefix; if (!constantPrefix.equals(prefix)) { hasPrefix = false; break; } } if (!hasPrefix) constantPrefix = null; else { String fileName = fileURL.getFile(); int pos = fileName.lastIndexOf(File.separatorChar); if (pos >= 0) fileName = fileName.substring(pos+1); pos = fileName.lastIndexOf('/'); if (pos >= 0) fileName = fileName.substring(pos+1); pos = fileName.indexOf('.'); if (pos >= 0) fileName = fileName.substring(0, pos); if (fileName.equals(constantPrefix)) constantPrefix += "."; else constantPrefix = null; } for(int k=0; k<numSignals; k++) { String name = signalNames[k]; if (constantPrefix != null && name.startsWith(constantPrefix)) name = name.substring(constantPrefix.length()); String context = null; int lastDotPos = name.lastIndexOf('.'); if (lastDotPos >= 0) { context = name.substring(0, lastDotPos); name = name.substring(lastDotPos+1); } an.addSignal(name, context, minTime, maxTime, minValues[k], maxValues[k]); } stopProgressDialog(); System.out.println("Done reading " + analysisType.toString() + " analysis"); } /** * Method to reset the binary block pointer (done between the header and * the data). */ private void resetBinaryTRACDCReader() { binaryTRACDCSize = 0; binaryTRACDCPosition = 0; } /** * Method to read the next block of tr, sw, or ac data. * @param firstbyteread true to skip the first byte. * @return true on EOF. */ private boolean readBinaryTRACDCBlock(boolean firstbyteread) throws IOException { // read the first word of a binary block if (!firstbyteread) { if (dataInputStream.read() == -1) return true; updateProgressDialog(1); } for(int i=0; i<3; i++) if (dataInputStream.read() == -1) return true; updateProgressDialog(3); // read the number of 8-byte blocks int blocks = 0; for(int i=0; i<4; i++) { int uval = dataInputStream.read(); if (uval == -1) return true; if (isTRACDCBinarySwapped) blocks = ((blocks >> 8) & 0xFFFFFF) | ((uval&0xFF) << 24); else blocks = (blocks << 8) | uval; } updateProgressDialog(4); // skip the dummy word for(int i=0; i<4; i++) if (dataInputStream.read() == -1) return true; updateProgressDialog(4); // read the number of bytes int bytes = 0; for(int i=0; i<4; i++) { int uval = dataInputStream.read(); if (uval == -1) return true; if (isTRACDCBinarySwapped) bytes = ((bytes >> 8) & 0xFFFFFF) | ((uval&0xFF) << 24); else bytes = (bytes << 8) | uval; } updateProgressDialog(4); // now read the data if (bytes > 8192) { System.out.println("ERROR: block is " + bytes + " long, but limit is 8192"); bytes = 8192; } int amtread = dataInputStream.read(binaryTRACDCBuffer, 0, bytes); if (amtread != bytes) { System.out.println("Expected to read " + bytes + " bytes but got only " + amtread); return true; } updateProgressDialog(bytes); // read the trailer count int trailer = 0; for(int i=0; i<4; i++) { int uval = dataInputStream.read(); if (uval == -1) return true; if (isTRACDCBinarySwapped) trailer = ((trailer >> 8) & 0xFFFFFF) | ((uval&0xFF) << 24); else trailer = (trailer << 8) | uval; } if (trailer != bytes) { System.out.println("Block trailer claims block had " + trailer + " bytes but block really had " + bytes); return true; } updateProgressDialog(4); // set pointers for the buffer binaryTRACDCPosition = 0; binaryTRACDCSize = bytes; return false; } /** * Method to get the next character from the simulator. * @return the next character (EOF at end of file). */ private int getByteFromFile() throws IOException { if (byteCount == 0) { // start of HSpice file: see if it is binary or ascii int i = dataInputStream.read(); if (i == -1) return(i); updateProgressDialog(1); if (i == 0 || i == 4) { isTRACDCBinary = true; isTRACDCBinarySwapped = false; if (i == 4) isTRACDCBinarySwapped = true; binaryTRACDCBuffer = new byte[8192]; if (readBinaryTRACDCBlock(true)) return(-1); } else { isTRACDCBinary = false; return(i); } } if (isTRACDCBinary) { if (binaryTRACDCPosition >= binaryTRACDCSize) { if (readBinaryTRACDCBlock(false)) return(-1); } int val = binaryTRACDCBuffer[binaryTRACDCPosition]; binaryTRACDCPosition++; return val&0xFF; } int i = dataInputStream.read(); updateProgressDialog(1); return i; } /** * Method to get the next 4-byte integer from the simulator. * @return the next integer. */ private int getHSpiceInt() throws IOException { StringBuffer line = new StringBuffer(); for(int j=0; j<4; j++) line.append((char)getByteFromFile()); return TextUtils.atoi(line.toString().trim(), 0, 10); } /** * Method to read the next floating point number from the HSpice file. * @return the next number. Sets the global "eofReached" true on EOF. */ private float getHSpiceFloat(boolean testEOFValue) throws IOException { if (!isTRACDCBinary) { StringBuffer line = new StringBuffer(); for(int j=0; j<11; j++) { int l = getByteFromFile(); if (l == -1) { eofReached = true; return 0; } line.append((char)l); if (l == '\n') j--; } String result = line.toString(); if (testEOFValue && result.equals("0.10000E+31")) { eofReached = true; return 0; } return (float)TextUtils.atof(result); } // binary format int fi0 = getByteFromFile(); int fi1 = getByteFromFile(); int fi2 = getByteFromFile(); int fi3 = getByteFromFile(); if (fi0 < 0 || fi1 < 0 || fi2 < 0 || fi3 < 0) { eofReached = true; return 0; } fi0 &= 0xFF; fi1 &= 0xFF; fi2 &= 0xFF; fi3 &= 0xFF; int fi = 0; if (isTRACDCBinarySwapped) { fi = (fi3 << 24) | (fi2 << 16) | (fi1 << 8) | fi0; } else { fi = (fi0 << 24) | (fi1 << 16) | (fi2 << 8) | fi3; } float f = Float.intBitsToFloat(fi); // the termination value (in hex) is 71 49 F2 CA if (testEOFValue && f > 1.00000000E30 && f < 1.00000002E30) { eofReached = true; return 0; } return f; }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -