Example usage for java.lang Float SIZE

List of usage examples for java.lang Float SIZE

Introduction

In this page you can find the example usage for java.lang Float SIZE.

Prototype

int SIZE

To view the source code for java.lang Float SIZE.

Click Source Link

Document

The number of bits used to represent a float value.

Usage

From source file:spectrogram.Spectrogram.java

private void readAddRawData() throws WebUtilException, NDSException {
    if (rawDataFilename != null && !rawDataFilename.isEmpty()) {
        rawDataFile = new File(rawDataFilename);
    }/* www  .  ja va2 s. c o  m*/
    if (rawDataFile == null || !rawDataFile.canRead()) {
        throw new WebUtilException("Request for raw data but file cannot be read, or not set.");
    }
    long nSamples = rawDataFile.length() / (Float.SIZE / 8) / 2;
    try {

        inStream = new SwappedDataInputStream(new FileInputStream(rawDataFile));
        int startPos = 0;
        int blen = (int) Math.min(nSamples, 1024 * 1024);
        double[] rawDataBuffer = new double[blen];

        for (long n = 0; n < nSamples; n += blen) {
            int dlen = blen;
            if (n + blen > nSamples) {
                dlen = (int) (nSamples - n);
            }
            for (int i = 0; i < dlen; i++) {
                Float t = inStream.readFloat();
                Float d = inStream.readFloat();
                rawDataBuffer[i] = d;
            }
            addBuf(rawDataBuffer, (int) n, dlen);
        }
    } catch (IOException ex) {
        throw new WebUtilException("Error reading raw data file", ex);
    }

}

From source file:spectrogram.Spectrogram.java

/**
 * For binary input files from our frame reader set up the input stream
 *
 * @return number of entries to read//w w w  . ja v  a2s.c  o m
 * @throws WebUtilException
 */
private long setupFileReads(String infilename) throws WebUtilException {
    setProgress("Scan input file for min/max GPS times.");
    File inFile = new File(infilename);
    long siz = inFile.length() / (Float.SIZE / 8) / 2; // convert bytes to # entries (time, val)
    if (!inFile.canRead()) {
        throw new WebUtilException("Can't open " + infilename + " for reading");
    }
    try {
        inStream = new SwappedDataInputStream(new FileInputStream(inFile));
        float minTime = Float.MAX_VALUE;
        float maxTime = -Float.MAX_VALUE;

        setProgress("Searhing for min/max time in input file.");
        int opct = 0;
        for (int i = 0; i < siz; i++) {
            int pct = (int) (100 * i / siz);
            if (pct > opct) {
                setProgress(pct, 100);
                opct = pct;
            }
            Float t = inStream.readFloat();
            Float d = inStream.readFloat();
            minTime = Math.min(minTime, t);
            maxTime = Math.max(maxTime, t);
        }
        startGPS = (int) (minTime);
        duration = (int) (maxTime - minTime);
        inStream.close();
        inStream = new SwappedDataInputStream(new FileInputStream(inFile));
    } catch (IOException ex) {
        throw new WebUtilException("Can't open " + infilename + " for reading");
    }

    return siz;
}

From source file:trendplot.TrendPlot.java

private void findMinMax(String datFileName) throws FileNotFoundException, IOException {
    File datFile = new File(datFileName);
    try (BufferedInputStream ins = new BufferedInputStream(new FileInputStream(datFile))) {
        boolean eof = false;
        min = Float.MAX_VALUE;//from   w  ww. ja  va2 s.com
        minMax = Float.MIN_VALUE;
        max = Float.MIN_VALUE;
        maxMin = Float.MAX_VALUE;
        tmin = Float.MAX_VALUE;
        tmax = Float.MIN_VALUE;
        byte[] b = new byte[Float.SIZE / 8];
        int count = 0;
        int nread;
        while (!eof) {
            try {
                nread = ins.read(b);
                float time = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                nread += ins.read(b);
                float inmin = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                nread += ins.read(b);
                float mean = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                nread += ins.read(b);
                float inmax = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                if (nread == Float.SIZE / 8 * 4) {
                    count++;
                    tmin = Math.min(tmin, time);
                    tmax = Math.max(tmax, time);
                    min = Math.min(min, inmin);
                    minMax = Math.max(minMax, inmin);
                    max = Math.max(max, inmax);
                    maxMin = Math.min(maxMin, inmax);
                } else {
                    eof = true;
                    ins.close();
                }
            } catch (EOFException ex) {
                eof = true;
                ins.close();
            } catch (IOException ex) {
                ins.close();
                throw ex;
            }
        }
    }
}

From source file:trendplot.TrendPlot.java

private void makeHistogram(String datFileName) throws FileNotFoundException, IOException {
    File datFile = new File(datFileName);
    try (BufferedInputStream ins = new BufferedInputStream(new FileInputStream(datFileName))) {
        boolean eof = false;
        minList = new ArrayList<>();
        maxList = new ArrayList<>();

        byte[] b = new byte[Float.SIZE / 8];
        int nread;
        while (!eof) {
            try {
                nread = ins.read(b);/*from   w  w  w  .j  a v  a 2s. c  o  m*/
                float time = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                nread += ins.read(b);
                float inmin = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                nread += ins.read(b);
                float mean = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                nread += ins.read(b);
                float inmax = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getFloat();
                if (nread == Float.SIZE / 8 * 4) {
                    minList.add(inmin);
                    maxList.add(inmax);
                } else {
                    eof = true;
                    ins.close();
                }
            } catch (EOFException ex) {
                eof = true;
                ins.close();
            } catch (IOException ex) {
                ins.close();
                throw ex;
            }
        }
    }
    Collections.sort(minList);
    Collections.sort(maxList);
}