Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "io_eegtools.h"
00022 #include <stdlib.h>
00023 #include <stdint.h>
00024
00025
00026
00037 Array* array_from_file( FILE *in ){
00038 uint16_t dtype;
00039 uint16_t size_dtype;
00040 uint16_t ndim;
00041 uint16_t size;
00042 uint32_t nbytes;
00043 uint *dims;
00044 int i;
00045
00046 ffread( &dtype, 2, 1, in );
00047 ffread( &size_dtype, 2, 1, in );
00048 ffread( &ndim, 2, 1, in );
00049 MALLOC( dims, ndim, uint );
00050 for( i=0; i<ndim; i++ ){
00051 ffread( &size, 2, 1, in );
00052 dims[i]=(uint)size;
00053 }
00054 Array *a=array_new( dtype, ndim, dims );
00055 ffread( &nbytes, 4, 1, in );
00056 if( nbytes!=a->nbytes ){
00057 errprintf("Wrong number of bytes, continuing (probably dieing)\n");
00058 }
00059 ffread( a->data, 1, nbytes, in );
00060
00061 free( dims );
00062
00063 return a;
00064 }
00065
00066
00067
00078 void array_to_file( FILE *out, const Array *a ){
00079 uint8_t ui8;
00080 uint16_t ui16;
00081 uint32_t ui32;
00082 int i;
00083
00084 ui16=(uint16_t)a->dtype;
00085 ffwrite( &ui16, 2, 1, out );
00086 ui16=(uint16_t)a->dtype_size;
00087 ffwrite( &ui16, 2, 1, out );
00088 ui16=(uint16_t)a->ndim;
00089 ffwrite( &ui16, 2, 1, out );
00090 for( i=0; i<a->ndim; i++ ){
00091 ui16=(uint16_t)a->size[i];
00092 ffwrite( &ui16, 2, 1, out );
00093 }
00094 ui32=(uint32_t)a->nbytes;
00095 ffwrite( &ui32, 4, 1, out );
00096
00097 ffwrite( a->data, 1, a->nbytes, out );
00098 }