getFloat() public method

public getFloat ( ) : float
return float
Beispiel #1
0
 public FloatBuffer get(float[] dst)
 {
     for (int i = 0; i < bytebuffer.remaining(); ++i)
     {
         dst[i] = bytebuffer.getFloat();
     }
     return(this);
 }
Beispiel #2
0
        public static object getObject(int type, int numel, ByteBuffer buf)
        {
            switch(type) {
                case CHAR:
                    byte[] strBytes = new byte[numel];
                    buf.get(ref strBytes);
                    System.Text.Encoding encoding = buf.encoding();
                    string val = encoding.GetString(strBytes, 0, strBytes.Length);
                    return val;

                case INT8:
                    goto case UINT8;
                case UINT8:
                    byte[] int8array = new byte[numel];
                    buf.get(ref int8array);
                    return (object)int8array;

                case INT16:
                    goto case UINT16;
                case UINT16:
                    short[] int16array = new short[numel];
                    // The following would be faster, but DOES NOT
                    // increment the position of the original ByteBuffer!!!
                    // buf.asShortBuffer().get(int16array);
                    for (int i=0;i<numel;i++) int16array[i] = buf.getShort();
                    return (object)int16array;

                case INT32:
                 goto case UINT32;
                case UINT32:
                    int[] int32array = new int[numel];
                    for (int i=0;i<numel;i++) int32array[i] = buf.getInt();
                    return (object)int32array;

                case INT64:
                    goto case UINT64;
                case UINT64:
                    long[] int64array = new long[numel];
                    for (int i=0;i<numel;i++) int64array[i] = buf.getLong();
                    return (object)int64array;

                case FLOAT32:
                    float[] float32array = new float[numel];
                    for (int i=0;i<numel;i++) float32array[i] = buf.getFloat();
                    return (object)float32array;

                case FLOAT64:
                    double[] float64array = new double[numel];
                    for (int i=0;i<numel;i++) float64array[i] = buf.getDouble();
                    return (object)float64array;

                default:
                    return null;
            }
        }
Beispiel #3
0
        public Header(ByteBuffer buf)
        {
            nChans   = buf.getInt();
            nSamples = buf.getInt();
            nEvents  = buf.getInt();
            fSample  = buf.getFloat();
            dataType = buf.getInt();
            int size = buf.getInt();

            labels = new string[nChans];

            while (size > 0)
            {
                int    chunkType = buf.getInt();
                int    chunkSize = buf.getInt();
                byte[] bs        = new byte[chunkSize];
                buf.get(ref bs);

                if (chunkType == CHUNK_CHANNEL_NAMES)
                {
                    int n = 0, len = 0, index = 0;
                    for (int pos = 0; pos < chunkSize; pos++)
                    {
                        if (bs[pos] == 0)
                        {
                            if (len > 0)
                            {
                                labels[n] = System.Text.Encoding.Default.GetString(bs, index, len);
                                index     = pos + 1;
                            }
                            len = 0;
                            if (++n == nChans)
                            {
                                break;
                            }
                        }
                        else
                        {
                            len++;
                        }
                    }
                }
                else
                {
                    // ignore all other chunks for now
                }
                size -= 8 + chunkSize;
            }
        }
Beispiel #4
0
        public Header(ByteBuffer buf)
        {
            nChans   = buf.getInt();
            nSamples = buf.getInt();
            nEvents  = buf.getInt();
            fSample  = buf.getFloat();
            dataType = buf.getInt();
            int size = buf.getInt();
            labels   = new string[nChans];

            while (size > 0) {
                int chunkType = buf.getInt();
                int chunkSize = buf.getInt();
                byte[] bs = new byte[chunkSize];
                buf.get(ref bs);

                if (chunkType == CHUNK_CHANNEL_NAMES) {
                    int n = 0, len = 0, index =0;
                    for (int pos = 0;pos<chunkSize;pos++) {
                        if (bs[pos]==0) {
                            if (len>0) {
                                labels[n] =System.Text.Encoding.Default.GetString(bs, index, len);
                                index = pos +1;
                            }
                            len = 0;
                            if (++n == nChans) break;
                        } else {
                            len++;
                        }
                    }
                } else {
                    // ignore all other chunks for now
                }
                size -= 8 + chunkSize;
            }
        }
Beispiel #5
0
        public double[,] getDoubleData(int first, int last)
        {
            DataDescription dd  = new DataDescription();
            ByteBuffer      buf = getRawData(first, last, dd);

            int nSamples = dd.nSamples;
            int nChans   = dd.nChans;

            double[,] data = new double[nSamples, nChans];

            switch (dd.dataType)
            {
            case DataType.INT8:
                for (int i = 0; i < nSamples; i++)
                {
                    //data[i] = new double[nChans];
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (double)buf.get();
                    }
                }
                break;

            case DataType.INT16:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (double)buf.getShort();
                    }
                }
                break;

            case DataType.INT32:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (double)buf.getInt();
                    }
                }
                break;

            case DataType.INT64:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (double)buf.getLong();
                    }
                }
                break;

            case DataType.FLOAT32:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = buf.getFloat();
                    }
                }
                break;

            case DataType.FLOAT64:
                DoubleBuffer dBuf = buf.asDoubleBuffer();
                double[]     rowData;
                for (int n = 0; n < nSamples; n++)
                {
                    rowData = getRow <double>(data, n);
                    dBuf.get(rowData);
                }
                break;

            default:
                throw new IOException("Not supported yet - returning zeros.");
                break;
            }

            return(data);
        }
Beispiel #6
0
        public float[,] getFloatData(int first, int last)
        {
            DataDescription dd  = new DataDescription();
            ByteBuffer      buf = getRawData(first, last, dd);

            int nSamples = dd.nSamples;
            int nChans   = dd.nChans;

            float[,] data = new float[nSamples, nChans];

            switch (dd.dataType)
            {
            case DataType.INT8:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (float)buf.get();
                    }
                }
                break;

            case DataType.INT16:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (float)buf.getShort();
                    }
                }
                break;

            case DataType.INT32:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (float)buf.getInt();
                    }
                }
                break;

            case DataType.FLOAT32:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (float)buf.getFloat();
                    }
                }
                break;

            case DataType.FLOAT64:
                for (int i = 0; i < nSamples; i++)
                {
                    for (int j = 0; j < nChans; j++)
                    {
                        data[i, j] = (float)buf.getDouble();
                    }
                }
                break;

            default:
                throw new IOException("Not supported yet - returning zeros.");
                break;
            }

            return(data);
        }
Beispiel #7
0
        public static object getObject(int type, int numel, ByteBuffer buf)
        {
            switch (type)
            {
            case CHAR:
                byte[] strBytes = new byte[numel];
                buf.get(ref strBytes);
                System.Text.Encoding encoding = buf.encoding();
                string val = encoding.GetString(strBytes, 0, strBytes.Length);
                return(val);

            case INT8:
                goto case UINT8;

            case UINT8:
                byte[] int8array = new byte[numel];
                buf.get(ref int8array);
                return((object)int8array);

            case INT16:
                goto case UINT16;

            case UINT16:
                short[] int16array = new short[numel];
                // The following would be faster, but DOES NOT
                // increment the position of the original ByteBuffer!!!
                // buf.asShortBuffer().get(int16array);
                for (int i = 0; i < numel; i++)
                {
                    int16array[i] = buf.getShort();
                }
                return((object)int16array);

            case INT32:
                goto case UINT32;

            case UINT32:
                int[] int32array = new int[numel];
                for (int i = 0; i < numel; i++)
                {
                    int32array[i] = buf.getInt();
                }
                return((object)int32array);

            case INT64:
                goto case UINT64;

            case UINT64:
                long[] int64array = new long[numel];
                for (int i = 0; i < numel; i++)
                {
                    int64array[i] = buf.getLong();
                }
                return((object)int64array);

            case FLOAT32:
                float[] float32array = new float[numel];
                for (int i = 0; i < numel; i++)
                {
                    float32array[i] = buf.getFloat();
                }
                return((object)float32array);

            case FLOAT64:
                double[] float64array = new double[numel];
                for (int i = 0; i < numel; i++)
                {
                    float64array[i] = buf.getDouble();
                }
                return((object)float64array);

            default:
                return(null);
            }
        }