Bug#556652: octave can't load files created by libmatio
Bas Zoetekouw
bas at debian.org
Tue Nov 17 12:48:43 UTC 2009
Package: libmatio0
Version: 1.3.3-5
Severity: normal
octave can't read compressed files written by libmatio. I'm not sure
if this is a problem in libmatio or in octave, so feel free to
reassign as necessary.
The following program uses libmatio to write a simple data structure
to a compressed mat file:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <matio.h>
#define NRSIGNALS 2
#define NRSAMPLES 100
int write_matfile( const char *fname )
{
mat_t *mat = NULL;
matvar_t **matchannels = NULL;
mat = Mat_Open( fname, 0 );
if ( mat==NULL )
{
fprintf( stderr, "Can't open file `%s' for output\n", fname );
return 0;
}
/* allocate memory for the channels */
matchannels = malloc( NRSIGNALS * sizeof(*matchannels) );
/* create a structure for each channel */
for ( int i = 0; i < NRSIGNALS; i++ )
{
int dims[2] = {1,1};
matvar_t ** matdata = malloc( 2 * sizeof(*matdata) );
matdata[0] = Mat_VarCreate( "channel", MAT_C_INT16, MAT_T_INT16, 2, dims, &i, 0 );
matdata[1] = NULL;
matchannels[i] = Mat_VarCreate( "", MAT_C_STRUCT, MAT_T_STRUCT, 2, dims, matdata, 0 );
}
/* the structures for the channels are combined into a single cell array */
int dims[2] = {1,NRSIGNALS};
matvar_t * matvar_cell = Mat_VarCreate("data",MAT_C_CELL,MAT_T_CELL,2,dims,matchannels,0);
/* write the file to disk */
Mat_VarWrite( mat, matvar_cell, COMPRESSION_ZLIB );
//Mat_VarWrite( mat, matvar_cell, 0 );
Mat_Close( mat );
return 1;
}
int main()
{
write_matfile( "/tmp/foo.mat" );
return(0);
}
Observe:
[bas at basbak2]/tmp> gcc edf2mat.c -std=c99 -lmatio && ./a.out
[bas at basbak2]/tmp> ls -la foo.mat
-rw-r--r-- 1 bas bas 215 nov 17 13:47 foo.mat
[bas at basbak2]/tmp> file foo.mat
foo.mat: Matlab v5 mat-file (little endian) version 0x0100
[bas at basbak2]/tmp> octave3.2 -q
octave3.2:1> load('foo.mat')
error: load: error uncompressing data element
The file loads fine in matlab. If the file is written without
compression, it also loads fine in octave.
-- System Information:
Debian Release: 5.0.3
APT prefers stable
APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.26-2-amd64 (SMP w/1 CPU core)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
More information about the debian-science-maintainers
mailing list