Here you can find the source of UnpackFloatBuffer(byte[] buffer, long bytes_read, long num_loaded, float[] list)
Parameter | Description |
---|---|
buffer | The array of bytes as read in one segment from the float data file. |
bytes_read | The number of bytes that were read in from the file and are to be extracted and placed in the list[] array. |
num_loaded | The number of floats that have already been loaded. This provides the position where the floats from the buffer should be stored. |
list | The list being filled with integers from the file. |
public static void UnpackFloatBuffer(byte[] buffer, long bytes_read, long num_loaded, float[] list)
//package com.java2s; /* /* w w w . j a v a 2 s . com*/ * File: FileUtil.java * * Copyright (C) 2010, Dennis Mikkelson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * Contact : Dennis Mikkelson <mikkelsond@uwstout.edu> * Department of Mathematics, Statistics and Computer Science * University of Wisconsin-Stout * Menomonie, WI 54751, USA * * This work was supported by the Spallation Neutron Source Division * of Oak Ridge National Laboratory, Oak Ridge, TN, USA. * * Last Modified: * * $Author:$ * $Date:$ * $Revision:$ */ public class Main { /** * Get the float values stored in the input file buffer and put the * values into the proper positions in the list[] array. * * @param buffer The array of bytes as read in one segment from the * float data file. * @param bytes_read The number of bytes that were read in from the file * and are to be extracted and placed in the list[] * array. * @param num_loaded The number of floats that have already been loaded. * This provides the position where the floats from * the buffer should be stored. * @param list The list being filled with integers from the file. */ public static void UnpackFloatBuffer(byte[] buffer, long bytes_read, long num_loaded, float[] list) { int index = (int) (num_loaded); for (int i = 0; i < bytes_read; i += 4) list[index++] = getFloat_32(buffer, i); } /** * Decode the float value stored in a sequence of four bytes in * the buffer. The four bytes determining the float value are * stored in the file and buffer in the sequence: b0,...,b3, with * the lowest order byte, b0, first and the the highest order byte, * b3, last. * NOTE: This method reverses the action of setFloat_32. * * @param i The index of the first byte in the buffer * * @return The float value represented by four successive bytes from * the file. */ public static float getFloat_32(byte[] buffer, int i) { int int_val = 0; for (int shift = 0; shift < 32; shift += 8) int_val |= ((int) buffer[i++] & 0xFF) << shift; return Float.intBitsToFloat(int_val); } }