⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plot.java

📁 Differential Evolution(JAVA)
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if (_debug > 8) {            System.out.println("Plot: _parseBinaryStream _connected = "+                    _connected);        }        try {            c = in.readByte();            if ( c != 'd') {                // Assume that the data is one data set, consisting                // of 4 byte floats.  None of the Ptolemy pxgraph                // binary format extensions apply.                // Note that the binary format is bigendian, or network                // order.  Little-endian machines, like x86 will not                // be able to write binary data directly.                // Read 3 more bytes, create the x float.                int bits = c;                bits = bits << 8;                bits += in.readByte();                bits = bits << 8;                bits += in.readByte();                bits = bits << 8;                bits += in.readByte();                x = Float.intBitsToFloat(bits);                y = in.readFloat();                connected = _addLegendIfNecessary(connected);                addPoint(_currentdataset, x, y, connected);                if (_connected) connected = true;                while (true) {                    x = in.readFloat();                    y = in.readFloat();                    connected = _addLegendIfNecessary(connected);                    addPoint(_currentdataset, x, y, connected);                    if (_connected) connected = true;                }            } else {                // Assume that the data is in the pxgraph binary format.                while (true) {                    // For speed reasons, the Ptolemy group extended                     // pxgraph to read binary format data.                    // The format consists of a command character,                    // followed by optional arguments                    // d <4byte float> <4byte float> - Draw a X,Y point                    // e                             - End of a data set                    // n <chars> \n                  - New set name, ends in \n                    // m                             - Move to a point                    switch (c) {                    case 'd':                        {                            // Data point.                            if (byteSwapped) {                                in.readFully(input);                                x = Float.intBitsToFloat(                                    (( input[3] & 0xFF ) << 24) |                                     (( input[2] & 0xFF ) << 16) |                                    (( input[1] & 0xFF ) << 8) |                                    ( input[0] & 0xFF ));                                in.readFully(input);                                y = Float.intBitsToFloat(                                    (( input[3] & 0xFF ) << 24) |                                     (( input[2] & 0xFF ) << 16) |                                    (( input[1] & 0xFF ) << 8) |                                    ( input[0] & 0xFF ));                            } else {                                x = in.readFloat();                                y = in.readFloat();                            }                            pointCount++;                            connected = _addLegendIfNecessary(connected);                            addPoint(_currentdataset, x, y, connected);                            if (_connected) connected = true;                        }                        break;                    case 'e':                        // End of set name.                        connected = false;                        break;                    case 'n':                        {                            StringBuffer datasetname = new StringBuffer();                            _firstinset = true;                            _sawfirstdataset = true;                            // FIXME: we allow more than _numsets datasets here                            _currentdataset++;                            if (_currentdataset >= _MAX_MARKS)                                _currentdataset = 0;                            // New set name, ends in \n.                            while (c != '\n')                                datasetname.append(in.readChar());                            addLegend(_currentdataset, datasetname.toString());                            setConnected(true);                        }                        break;                    case 'm':                        // a disconnected point                        connected = false;                        break;                    default:                        throw new PlotDataException("Don't understand `" +                                 (char)c + "' character " +                                "(decimal value = " + c +                                ") in binary file.  Last point was (" + x +                                "," + y + ").\nProcessed " + pointCount +                            " points sucessfully");                    }                    c = in.readByte();                }            }         } catch (EOFException e) {}             }    /**     * Parse a line that gives plotting information. Return true if     * the line is recognized.  Lines with syntax errors are ignored.     */    protected boolean _parseLine (String line) {        boolean connected = false;        if (_debug> 8) System.out.println("Plot: _parseLine " + line);        if (_connected) connected = true;        // parse only if the super class does not recognize the line.        if (super._parseLine(line)) {            // We saw a non-pxgraph file directive, so blank lines             // no longer mean new datasets.            _pxgraphBlankLineMode = false;            return true;        } else {            // We convert the line to lower case so that the command            // names are case insensitive            String lcLine = new String(line.toLowerCase());            if (lcLine.startsWith("marks:")) {                String style = (line.substring(6)).trim();                setMarksStyle(style);                _pxgraphBlankLineMode = false;                return true;            } else if (lcLine.startsWith("numsets:")) {                String num = (line.substring(8)).trim();                try {                    setNumSets(Integer.parseInt(num));                }                catch (NumberFormatException e) {                    // ignore bogons                }                _pxgraphBlankLineMode = false;                return true;            } else if (lcLine.startsWith("reusedatasets:")) {                if (lcLine.indexOf("off", 16) >= 0) {                    _reusedatasets = false;                } else {                    _reusedatasets = true;                }                return true;            } else if (lcLine.startsWith("dataset:")                    || (_pxgraphBlankLineMode && lcLine.length() == 0)) {                if (_reusedatasets && lcLine.length() > 0) {                    String tlegend = (line.substring(8)).trim();                    _currentdataset = -1;                    int i;                    for ( i = 0; i <= _maxdataset; i++) {                        if (getLegend(i).compareTo(tlegend) == 0) {                            _currentdataset = i;                        }                    }                    if (_currentdataset != -1) {                        return true;                    } else {                        _currentdataset = _maxdataset;                    }                }                // new data set                // If we have not yet seen a non-pxgraph file directive,                // and the line is blank, then this is a new data set.                _firstinset = true;                _sawfirstdataset = true;                if (!_datasetoverflow)                    _currentdataset++;                // If we provide more data than _numsets, ignore it.                if (_currentdataset >= _numsets || _datasetoverflow) {                    // We need _datasetoverflow to stop from reading more                    // datasets.  If we don't have it then we skip reading                    // only one dataset, and then start reading again.                    _datasetoverflow = true;                    _currentdataset = -1;                }                if (lcLine.length() > 0) {                    String legend = (line.substring(8)).trim();                    addLegend(_currentdataset, legend);                    _pxgraphBlankLineMode = false;                }                _maxdataset = _currentdataset;                return true;            } else if (lcLine.startsWith("lines:")) {                if (lcLine.indexOf("off",6) >= 0) {                    setConnected(false);                } else {                    setConnected(true);                }                _pxgraphBlankLineMode = false;                return true;            } else if (lcLine.startsWith("impulses:")) {                if (lcLine.indexOf("off",9) >= 0) {                    setImpulses(false);                } else {                    setImpulses(true);                }                _pxgraphBlankLineMode = false;                return true;            } else if (lcLine.startsWith("bars:")) {                if (lcLine.indexOf("off",5) >= 0) {                    setBars(false);                } else {                    setBars(true);                    if (! _yRangeGiven) {                        _yBottom = 0;                    }                    int comma = line.indexOf(",", 5);                    String barwidth;                    String baroffset = null;                    if (comma > 0) {                        barwidth = (line.substring(5, comma)).trim();                        baroffset = (line.substring(comma+1)).trim();                    } else {                        barwidth = (line.substring(5)).trim();                    }                    try {                        Double bwidth = new Double(barwidth);                        double boffset = _baroffset;                        if (baroffset != null) {                            boffset = (new Double(baroffset)).                                doubleValue();                        }                        setBars(bwidth.doubleValue(), boffset);                    } catch (NumberFormatException e) {                        // ignore if format is bogus.                    }                }                _pxgraphBlankLineMode = false;                return true;            } else if (line.startsWith("move:")) {                // a disconnected point                connected = false;                // deal with 'move: 1 2' and 'move:2 2'                line = line.substring(5, line.length()).trim();            } else if (line.startsWith("move")) {                // a disconnected point                connected = false;                // deal with 'move 1 2' and 'move2 2'                line = line.substring(4, line.length()).trim();            } else if (line.startsWith("draw:")) {                // a connected point, if connect is enabled.                line = line.substring(5, line.length()).trim();            } else if (line.startsWith("draw")) {                // a connected point, if connect is enabled.                line = line.substring(4, line.length()).trim();            }            line = line.trim();            // We can't use StreamTokenizer here because it can't            // process numbers like 1E-01.              // This code is somewhat optimized for speed, since            // most data consists of two data points, we want            // to handle that case as efficiently as possible.            int fieldsplit = line.indexOf(",");            if (fieldsplit == -1) {                fieldsplit = line.indexOf(" ");            }            if (fieldsplit == -1) {                fieldsplit = line.indexOf(" ");  // a tab            }            if (fieldsplit > 0) {                String x = (line.substring(0, fieldsplit)).trim();                String y = (line.substring(fieldsplit+1)).trim();                // Any more separators?                int fieldsplit2 = y.indexOf(",");                if (fieldsplit2 == -1) {                    fieldsplit2 = y.indexOf(" ");                }                if (fieldsplit2 == -1) {                    fieldsplit2 = y.indexOf(" ");  // a tab                }                if (fieldsplit2 > 0) {                    line = (y.substring(fieldsplit2+1)).trim();                    y = (y.substring(0,fieldsplit2)).trim();                }                try {                    Double xpt = new Double(x);                    Double ypt = new Double(y);                    if (fieldsplit2 > 0) {                        // There was one separator after the y value, now                        // look for another separator.                        int fieldsplit3 = line.indexOf(",");                        if (fieldsplit3 == -1) {                            fieldsplit3 = line.indexOf(" ");                        }                        if (fieldsplit3 == -1) {                            fieldsplit2 = line.indexOf(" ");  // a tab                        }                        if (fieldsplit3 > 0) {                            // We have more numbers, assume that this is                            // an error bar                            String yl = (line.substring(0,                                    fieldsplit3)).trim();                            String yh = (line.substring(fieldsplit3+1)).trim();                     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -