matio: Matlab files IO

git-svn-id: svn://ultimatepp.org/upp/trunk@13328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
koldo 2019-05-19 18:29:21 +00:00
parent be65c2576c
commit 2ae72cfcea
27 changed files with 20563 additions and 0 deletions

View file

@ -0,0 +1,22 @@
Copyright (c) 1998, 2019, The U++ Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -0,0 +1,248 @@
/** @file endian.c
* @brief Functions to handle endian specifics
*/
/*
* Copyright (c) 2005-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "matio_private.h"
/** @brief swap the bytes @c a and @c b
* @ingroup mat_internal
*/
#define swap(a,b) a^=b;b^=a;a^=b
#ifdef HAVE_MAT_INT64_T
/** @brief swap the bytes of a 64-bit signed integer
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
mat_int64_t
Mat_int64Swap( mat_int64_t *a )
{
union {
mat_int8_t i1[8];
mat_int64_t i8;
} tmp;
tmp.i8 = *a;
swap( tmp.i1[0], tmp.i1[7] );
swap( tmp.i1[1], tmp.i1[6] );
swap( tmp.i1[2], tmp.i1[5] );
swap( tmp.i1[3], tmp.i1[4] );
*a = tmp.i8;
return *a;
}
#endif /* HAVE_MAT_INT64_T */
#ifdef HAVE_MAT_UINT64_T
/** @brief swap the bytes of a 64-bit unsigned integer
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
mat_uint64_t
Mat_uint64Swap( mat_uint64_t *a )
{
union {
mat_uint8_t i1[8];
mat_uint64_t i8;
} tmp;
tmp.i8 = *a;
swap( tmp.i1[0], tmp.i1[7] );
swap( tmp.i1[1], tmp.i1[6] );
swap( tmp.i1[2], tmp.i1[5] );
swap( tmp.i1[3], tmp.i1[4] );
*a = tmp.i8;
return *a;
}
#endif /* HAVE_MAT_UINT64_T */
/** @brief swap the bytes of a 32-bit signed integer
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
mat_int32_t
Mat_int32Swap( mat_int32_t *a )
{
union {
mat_int8_t i1[4];
mat_int32_t i4;
} tmp;
tmp.i4 = *a;
swap( tmp.i1[0], tmp.i1[3] );
swap( tmp.i1[1], tmp.i1[2] );
*a = tmp.i4;
return *a;
}
/** @brief swap the bytes of a 32-bit unsigned integer
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
mat_uint32_t
Mat_uint32Swap( mat_uint32_t *a )
{
union {
mat_uint8_t i1[4];
mat_uint32_t i4;
} tmp;
tmp.i4 = *a;
swap( tmp.i1[0], tmp.i1[3] );
swap( tmp.i1[1], tmp.i1[2] );
*a = tmp.i4;
return *a;
}
/** @brief swap the bytes of a 16-bit signed integer
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
mat_int16_t
Mat_int16Swap( mat_int16_t *a )
{
union {
mat_int8_t i1[2];
mat_int16_t i2;
} tmp;
tmp.i2 = *a;
swap( tmp.i1[0], tmp.i1[1] );
*a = tmp.i2;
return *a;
}
/** @brief swap the bytes of a 16-bit unsigned integer
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
mat_uint16_t
Mat_uint16Swap( mat_uint16_t *a )
{
union {
mat_uint8_t i1[2];
mat_uint16_t i2;
} tmp;
tmp.i2 = *a;
swap( tmp.i1[0], tmp.i1[1] );
*a = tmp.i2;
return *a;
}
/** @brief swap the bytes of a 4 byte single-precision float
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
float
Mat_floatSwap( float *a )
{
union {
char i1[4];
float r4;
} tmp;
tmp.r4 = *a;
swap( tmp.i1[0], tmp.i1[3] );
swap( tmp.i1[1], tmp.i1[2] );
*a = tmp.r4;
return *a;
}
/** @brief swap the bytes of a 4 or 8 byte double-precision float
* @ingroup mat_internal
* @param a pointer to integer to swap
* @return the swapped integer
*/
double
Mat_doubleSwap( double *a )
{
#ifndef SIZEOF_DOUBLE
#define SIZEOF_DOUBLE 8
#endif
union {
char a[SIZEOF_DOUBLE];
double b;
} tmp;
tmp.b = *a;
#if SIZEOF_DOUBLE == 4
swap( tmp.a[0], tmp.a[3] );
swap( tmp.a[1], tmp.a[2] );
#elif SIZEOF_DOUBLE == 8
swap( tmp.a[0], tmp.a[7] );
swap( tmp.a[1], tmp.a[6] );
swap( tmp.a[2], tmp.a[5] );
swap( tmp.a[3], tmp.a[4] );
#elif SIZEOF_DOUBLE == 16
swap( tmp.a[0], tmp.a[15] );
swap( tmp.a[1], tmp.a[14] );
swap( tmp.a[2], tmp.a[13] );
swap( tmp.a[3], tmp.a[12] );
swap( tmp.a[4], tmp.a[11] );
swap( tmp.a[5], tmp.a[10] );
swap( tmp.a[6], tmp.a[9] );
swap( tmp.a[7], tmp.a[8] );
#endif
*a = tmp.b;
return *a;
}

View file

@ -0,0 +1,229 @@
/* Exact-width integer types
* Portable Snippets - https://gitub.com/nemequ/portable-snippets
* Created by Evan Nemerson <evan@nemerson.com>
*
* To the extent possible under law, the authors have waived all
* copyright and related or neighboring rights to this code. For
* details, see the Creative Commons Zero 1.0 Universal license at
* https://creativecommons.org/publicdomain/zero/1.0/
*
* This header tries to define psnip_(u)int(8|16|32|64)_t to
* appropriate types given your system. For most systems this means
* including <stdint.h> and adding a few preprocessor definitions.
*
* If you prefer, you can define any necessary types yourself.
* Snippets in this repository which rely on these types will not
* attempt to include this header if you have already defined the
* types it uses.
*/
#if !defined(PSNIP_EXACT_INT_H)
# define PSNIP_EXACT_INT_H
# if !defined(PSNIP_EXACT_INT_HAVE_STDINT)
# if defined(_STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
# define PSNIP_EXACT_INT_HAVE_STDINT
# elif defined(__has_include)
# if __has_include(<stdint.h>)
# define PSNIP_EXACT_INT_HAVE_STDINT
# endif
# elif \
defined(HAVE_STDINT_H) || \
defined(_STDINT_H_INCLUDED) || \
defined(_STDINT_H) || \
defined(_STDINT_H_)
# define PSNIP_EXACT_INT_HAVE_STDINT
# elif \
(defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))) || \
(defined(_MSC_VER) && (_MSC_VER >= 1600)) || \
(defined(__SUNPRO_C) && (__SUNPRO_C >= 0x570)) || \
(defined(__WATCOMC__) && (__WATCOMC__ >= 1250))
# define PSNIP_EXACT_INT_HAVE_STDINT
# endif
# endif
# if \
defined(__INT8_TYPE__) && defined(__INT16_TYPE__) && defined(__INT32_TYPE__) && defined(__INT64_TYPE__) && \
defined(__UINT8_TYPE__) && defined(__UINT16_TYPE__) && defined(__UINT32_TYPE__) && defined(__UINT64_TYPE__)
# define psnip_int8_t __INT8_TYPE__
# define psnip_int16_t __INT16_TYPE__
# define psnip_int32_t __INT32_TYPE__
# define psnip_int64_t __INT64_TYPE__
# define psnip_uint8_t __UINT8_TYPE__
# define psnip_uint16_t __UINT16_TYPE__
# define psnip_uint32_t __UINT32_TYPE__
# define psnip_uint64_t __UINT64_TYPE__
# elif defined(PSNIP_EXACT_INT_HAVE_STDINT)
# include <stdint.h>
# if !defined(psnip_int8_t)
# define psnip_int8_t int8_t
# endif
# if !defined(psnip_uint8_t)
# define psnip_uint8_t uint8_t
# endif
# if !defined(psnip_int16_t)
# define psnip_int16_t int16_t
# endif
# if !defined(psnip_uint16_t)
# define psnip_uint16_t uint16_t
# endif
# if !defined(psnip_int32_t)
# define psnip_int32_t int32_t
# endif
# if !defined(psnip_uint32_t)
# define psnip_uint32_t uint32_t
# endif
# if !defined(psnip_int64_t)
# define psnip_int64_t int64_t
# endif
# if !defined(psnip_uint64_t)
# define psnip_uint64_t uint64_t
# endif
# elif defined(_MSC_VER)
# if !defined(psnip_int8_t)
# define psnip_int8_t __int8
# endif
# if !defined(psnip_uint8_t)
# define psnip_uint8_t unsigned __int8
# endif
# if !defined(psnip_int16_t)
# define psnip_int16_t __int16
# endif
# if !defined(psnip_uint16_t)
# define psnip_uint16_t unsigned __int16
# endif
# if !defined(psnip_int32_t)
# define psnip_int32_t __int32
# endif
# if !defined(psnip_uint32_t)
# define psnip_uint32_t unsigned __int32
# endif
# if !defined(psnip_int64_t)
# define psnip_int64_t __int64
# endif
# if !defined(psnip_uint64_t)
# define psnip_uint64_t unsigned __int64
# endif
# else
# include <limits.h>
# if !defined(psnip_int8_t)
# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-127-1)) && (CHAR_MAX == 127)
# define psnip_int8_t char
# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-127-1)) && (SHRT_MAX == 127)
# define psnip_int8_t short
# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-127-1)) && (INT_MAX == 127)
# define psnip_int8_t int
# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-127-1)) && (LONG_MAX == 127)
# define psnip_int8_t long
# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-127-1)) && (LLONG_MAX == 127)
# define psnip_int8_t long long
# else
# error Unable to locate 8-bit signed integer type.
# endif
# endif
# if !defined(psnip_uint8_t)
# if defined(UCHAR_MAX) && (UCHAR_MAX == 255)
# define psnip_uint8_t unsigned char
# elif defined(USHRT_MAX) && (USHRT_MAX == 255)
# define psnip_uint8_t unsigned short
# elif defined(UINT_MAX) && (UINT_MAX == 255)
# define psnip_uint8_t unsigned int
# elif defined(ULONG_MAX) && (ULONG_MAX == 255)
# define psnip_uint8_t unsigned long
# elif defined(ULLONG_MAX) && (ULLONG_MAX == 255)
# define psnip_uint8_t unsigned long long
# else
# error Unable to locate 8-bit unsigned integer type.
# endif
# endif
# if !defined(psnip_int16_t)
# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-32767-1)) && (CHAR_MAX == 32767)
# define psnip_int16_t char
# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-32767-1)) && (SHRT_MAX == 32767)
# define psnip_int16_t short
# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-32767-1)) && (INT_MAX == 32767)
# define psnip_int16_t int
# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-32767-1)) && (LONG_MAX == 32767)
# define psnip_int16_t long
# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-32767-1)) && (LLONG_MAX == 32767)
# define psnip_int16_t long long
# else
# error Unable to locate 16-bit signed integer type.
# endif
# endif
# if !defined(psnip_uint16_t)
# if defined(UCHAR_MAX) && (UCHAR_MAX == 65535)
# define psnip_uint16_t unsigned char
# elif defined(USHRT_MAX) && (USHRT_MAX == 65535)
# define psnip_uint16_t unsigned short
# elif defined(UINT_MAX) && (UINT_MAX == 65535)
# define psnip_uint16_t unsigned int
# elif defined(ULONG_MAX) && (ULONG_MAX == 65535)
# define psnip_uint16_t unsigned long
# elif defined(ULLONG_MAX) && (ULLONG_MAX == 65535)
# define psnip_uint16_t unsigned long long
# else
# error Unable to locate 16-bit unsigned integer type.
# endif
# endif
# if !defined(psnip_int32_t)
# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-2147483647-1)) && (CHAR_MAX == 2147483647)
# define psnip_int32_t char
# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-2147483647-1)) && (SHRT_MAX == 2147483647)
# define psnip_int32_t short
# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-2147483647-1)) && (INT_MAX == 2147483647)
# define psnip_int32_t int
# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-2147483647-1)) && (LONG_MAX == 2147483647)
# define psnip_int32_t long
# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-2147483647-1)) && (LLONG_MAX == 2147483647)
# define psnip_int32_t long long
# else
# error Unable to locate 32-bit signed integer type.
# endif
# endif
# if !defined(psnip_uint32_t)
# if defined(UCHAR_MAX) && (UCHAR_MAX == 4294967295)
# define psnip_uint32_t unsigned char
# elif defined(USHRT_MAX) && (USHRT_MAX == 4294967295)
# define psnip_uint32_t unsigned short
# elif defined(UINT_MAX) && (UINT_MAX == 4294967295)
# define psnip_uint32_t unsigned int
# elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295)
# define psnip_uint32_t unsigned long
# elif defined(ULLONG_MAX) && (ULLONG_MAX == 4294967295)
# define psnip_uint32_t unsigned long long
# else
# error Unable to locate 32-bit unsigned integer type.
# endif
# endif
# if !defined(psnip_int64_t)
# if defined(CHAR_MIN) && defined(CHAR_MAX) && (CHAR_MIN == (-9223372036854775807LL-1)) && (CHAR_MAX == 9223372036854775807LL)
# define psnip_int64_t char
# elif defined(SHRT_MIN) && defined(SHRT_MAX) && (SHRT_MIN == (-9223372036854775807LL-1)) && (SHRT_MAX == 9223372036854775807LL)
# define psnip_int64_t short
# elif defined(INT_MIN) && defined(INT_MAX) && (INT_MIN == (-9223372036854775807LL-1)) && (INT_MAX == 9223372036854775807LL)
# define psnip_int64_t int
# elif defined(LONG_MIN) && defined(LONG_MAX) && (LONG_MIN == (-9223372036854775807LL-1)) && (LONG_MAX == 9223372036854775807LL)
# define psnip_int64_t long
# elif defined(LLONG_MIN) && defined(LLONG_MAX) && (LLONG_MIN == (-9223372036854775807LL-1)) && (LLONG_MAX == 9223372036854775807LL)
# define psnip_int64_t long long
# else
# error Unable to locate 64-bit signed integer type.
# endif
# endif
# if !defined(psnip_uint64_t)
# if defined(UCHAR_MAX) && (UCHAR_MAX == 18446744073709551615ULL)
# define psnip_uint64_t unsigned char
# elif defined(USHRT_MAX) && (USHRT_MAX == 18446744073709551615ULL)
# define psnip_uint64_t unsigned short
# elif defined(UINT_MAX) && (UINT_MAX == 18446744073709551615ULL)
# define psnip_uint64_t unsigned int
# elif defined(ULONG_MAX) && (ULONG_MAX == 18446744073709551615ULL)
# define psnip_uint64_t unsigned long
# elif defined(ULLONG_MAX) && (ULLONG_MAX == 18446744073709551615ULL)
# define psnip_uint64_t unsigned long long
# else
# error Unable to locate 64-bit unsigned integer type.
# endif
# endif
# endif
#endif

View file

@ -0,0 +1,892 @@
/** @file inflate.c
* @brief Functions to inflate data/tags
* @ingroup MAT
*/
/*
* Copyright (c) 2005-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include "matio_private.h"
#if HAVE_ZLIB
/** @cond mat_devman */
/** @brief Inflate the data until @c nbytes of uncompressed data has been
* inflated
*
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param z zlib compression stream
* @param nbytes Number of uncompressed bytes to skip
* @return Number of bytes read from the file
*/
size_t
InflateSkip(mat_t *mat, z_streamp z, int nbytes)
{
mat_uint8_t comp_buf[512],uncomp_buf[512];
int n, err, cnt = 0;
size_t bytesread = 0;
if ( nbytes < 1 )
return 0;
n = (nbytes<512) ? nbytes : 512;
if ( !z->avail_in ) {
z->next_in = comp_buf;
z->avail_in += fread(comp_buf,1,n,(FILE*)mat->fp);
bytesread += z->avail_in;
}
z->avail_out = n;
z->next_out = uncomp_buf;
err = inflate(z,Z_FULL_FLUSH);
if ( err == Z_STREAM_END ) {
return bytesread;
} else if ( err != Z_OK ) {
Mat_Critical("InflateSkip: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
if ( !z->avail_out ) {
cnt += n;
n = ((nbytes-cnt)<512) ? nbytes-cnt : 512;
z->avail_out = n;
z->next_out = uncomp_buf;
}
while ( cnt < nbytes ) {
if ( !z->avail_in ) {
z->next_in = comp_buf;
z->avail_in += fread(comp_buf,1,n,(FILE*)mat->fp);
bytesread += z->avail_in;
}
err = inflate(z,Z_FULL_FLUSH);
if ( err == Z_STREAM_END ) {
break;
} else if ( err != Z_OK ) {
Mat_Critical("InflateSkip: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
break;
}
if ( !z->avail_out ) {
cnt += n;
n = ((nbytes-cnt)<512) ? nbytes-cnt : 512;
z->avail_out = n;
z->next_out = uncomp_buf;
}
}
if ( z->avail_in ) {
long offset = -(long)z->avail_in;
(void)fseek((FILE*)mat->fp,offset,SEEK_CUR);
bytesread -= z->avail_in;
z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflate the data until @c nbytes of compressed data has been
* inflated
*
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param z zlib compression stream
* @param nbytes Number of uncompressed bytes to skip
* @return Number of bytes read from the file
*/
size_t
InflateSkip2(mat_t *mat, matvar_t *matvar, int nbytes)
{
mat_uint8_t comp_buf[32],uncomp_buf[32];
int err, cnt = 0;
size_t bytesread = 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 1;
matvar->internal->z->next_out = uncomp_buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateSkip2: %s - inflate returned %s",matvar->name,zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
if ( !matvar->internal->z->avail_out ) {
matvar->internal->z->avail_out = 1;
matvar->internal->z->next_out = uncomp_buf;
}
while ( cnt < nbytes ) {
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
cnt++;
}
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateSkip2: %s - inflate returned %s",matvar->name,zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
if ( !matvar->internal->z->avail_out ) {
matvar->internal->z->avail_out = 1;
matvar->internal->z->next_out = uncomp_buf;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflate the data until @c len elements of compressed data with data
* type @c data_type has been inflated
*
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param z zlib compression stream
* @param data_type Data type (matio_types enumerations)
* @param len Number of elements of datatype @c data_type to skip
* @return Number of bytes read from the file
*/
size_t
InflateSkipData(mat_t *mat,z_streamp z,enum matio_types data_type,int len)
{
int data_size = 0;
if ( (mat == NULL) || (z == NULL) )
return 0;
else if ( len < 1 )
return 0;
switch ( data_type ) {
case MAT_T_DOUBLE:
data_size = sizeof(double);
break;
case MAT_T_SINGLE:
data_size = sizeof(float);
break;
#ifdef HAVE_MAT_INT64_T
case MAT_T_INT64:
data_size = sizeof(mat_int64_t);
break;
#endif /* HAVE_MAT_INT64_T */
#ifdef HAVE_MAT_UINT64_T
case MAT_T_UINT64:
data_size = sizeof(mat_uint64_t);
break;
#endif /* HAVE_MAT_UINT64_T */
case MAT_T_INT32:
data_size = sizeof(mat_int32_t);
break;
case MAT_T_UINT32:
data_size = sizeof(mat_uint32_t);
break;
case MAT_T_INT16:
data_size = sizeof(mat_int16_t);
break;
case MAT_T_UINT16:
data_size = sizeof(mat_uint16_t);
break;
case MAT_T_UINT8:
data_size = sizeof(mat_uint8_t);
break;
case MAT_T_INT8:
data_size = sizeof(mat_int8_t);
break;
default:
return 0;
}
InflateSkip(mat,z,len*data_size);
return len;
}
/** @brief Inflates the variable's tag.
*
* @c buf must hold at least 8 bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the 8-byte variable tag
* @return Number of bytes read from the file
*/
size_t
InflateVarTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 8;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the Array Flags Tag and the Array Flags data.
*
* @c buf must hold at least 16 bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the 16-byte array flags tag and data
* @return Number of bytes read from the file
*/
size_t
InflateArrayFlags(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 16;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateArrayFlags: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateArrayFlags: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the dimensions tag and the dimensions data
*
* @c buf must hold at least (8+4*rank) bytes where rank is the number of
* dimensions. If the end of the dimensions data is not aligned on an 8-byte
* boundary, this function eats up those bytes and stores then in @c buf.
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the dimensions flag and data
* @param nbytes Size of buf in bytes
* @param dims Output buffer to be allocated if (8+4*rank) > nbytes
* @return Number of bytes read from the file
*/
size_t
InflateRankDims(mat_t *mat, matvar_t *matvar, void *buf, size_t nbytes, mat_uint32_t** dims)
{
mat_uint8_t comp_buf[32];
mat_int32_t tag[2];
int err, rank, i;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 8;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
tag[0] = *(int *)buf;
tag[1] = *((int *)buf+1);
if ( mat->byteswap ) {
Mat_int32Swap(tag);
Mat_int32Swap(tag+1);
}
if ( (tag[0] & 0x0000ffff) != MAT_T_INT32 ) {
Mat_Critical("InflateRankDims: Reading dimensions expected type MAT_T_INT32");
return bytesread;
}
rank = tag[1];
if ( rank % 8 != 0 )
i = 8-(rank %8);
else
i = 0;
rank+=i;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = rank;
if ( sizeof(mat_uint32_t)*(rank + 2) <= nbytes ) {
matvar->internal->z->next_out = (Bytef*)((mat_int32_t *)buf+2);
} else {
/* Cannot use too small buf, but can allocate output buffer dims */
*dims = (mat_uint32_t*)calloc(rank, sizeof(mat_uint32_t));
if ( NULL != *dims ) {
matvar->internal->z->next_out = (Bytef*)*dims;
} else {
*((mat_int32_t *)buf+1) = 0;
Mat_Critical("Error allocating memory for dims");
return bytesread;
}
}
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
readresult = 1;
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateRankDims: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the variable name tag
*
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the variables name tag
* @return Number of bytes read from the file
*/
size_t
InflateVarNameTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 8;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarNameTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarNameTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the variable name
*
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the variables name
* @param N Number of characters in the name
* @return Number of bytes read from the file
*/
size_t
InflateVarName(mat_t *mat, matvar_t *matvar, void *buf, int N)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = N;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarName: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateVarName: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the data's tag
*
* buf must hold at least 8 bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the data tag
* @return Number of bytes read from the file
*/
size_t
InflateDataTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 8;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err == Z_STREAM_END ) {
return bytesread;
} else if ( err != Z_OK ) {
Mat_Critical("InflateDataTag: %s - inflate returned %s",matvar->name,zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err == Z_STREAM_END ) {
break;
} else if ( err != Z_OK ) {
Mat_Critical("InflateDataTag: %s - inflate returned %s",matvar->name,zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the data's type
*
* buf must hold at least 4 bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the data type
* @return Number of bytes read from the file
*/
size_t
InflateDataType(mat_t *mat, z_streamp z, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !z->avail_in ) {
z->avail_in = 1;
z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
z->avail_out = 4;
z->next_out = (Bytef*)buf;
err = inflate(z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateDataType: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( z->avail_out && !z->avail_in && 1 == readresult ) {
z->avail_in = 1;
z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateDataType: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)z->avail_in,SEEK_CUR);
bytesread -= z->avail_in;
z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the data
*
* buf must hold at least @c nBytes bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param z zlib compression stream
* @param buf Pointer to store the data type
* @param nBytes Number of bytes to inflate
* @return Number of bytes read from the file
*/
size_t
InflateData(mat_t *mat, z_streamp z, void *buf, unsigned int nBytes)
{
mat_uint8_t comp_buf[1024];
int err;
unsigned int bytesread = 0;
if ( buf == NULL )
return 0;
if ( nBytes == 0 ) {
return bytesread;
}
if ( !z->avail_in ) {
if ( nBytes > 1024 ) {
z->avail_in = fread(comp_buf,1,1024,(FILE*)mat->fp);
} else {
z->avail_in = fread(comp_buf,1,nBytes,(FILE*)mat->fp);
}
bytesread += z->avail_in;
z->next_in = comp_buf;
}
z->avail_out = nBytes;
z->next_out = (Bytef*)buf;
err = inflate(z,Z_FULL_FLUSH);
if ( err == Z_STREAM_END ) {
return bytesread;
} else if ( err != Z_OK ) {
Mat_Critical("InflateData: inflate returned %s",zError( err == Z_NEED_DICT ? Z_DATA_ERROR : err ));
return bytesread;
}
while ( z->avail_out && !z->avail_in ) {
if ( nBytes > 1024 + bytesread ) {
z->avail_in = fread(comp_buf,1,1024,(FILE*)mat->fp);
} else if ( nBytes < 1 + bytesread ) { /* Read a byte at a time */
z->avail_in = fread(comp_buf,1,1,(FILE*)mat->fp);
} else {
z->avail_in = fread(comp_buf,1,nBytes-bytesread,(FILE*)mat->fp);
}
bytesread += z->avail_in;
z->next_in = comp_buf;
err = inflate(z,Z_FULL_FLUSH);
if ( err == Z_STREAM_END ) {
break;
} else if ( err != Z_OK && err != Z_BUF_ERROR ) {
Mat_Critical("InflateData: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
break;
}
}
if ( z->avail_in ) {
long offset = -(long)z->avail_in;
(void)fseek((FILE*)mat->fp,offset,SEEK_CUR);
bytesread -= z->avail_in;
z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the structure's fieldname length
*
* buf must hold at least 8 bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the fieldname length
* @return Number of bytes read from the file
*/
size_t
InflateFieldNameLength(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 8;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNameLength: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNameLength: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @brief Inflates the structure's fieldname tag
*
* buf must hold at least 8 bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the fieldname tag
* @return Number of bytes read from the file
*/
size_t
InflateFieldNamesTag(mat_t *mat, matvar_t *matvar, void *buf)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = 8;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNamesTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNamesTag: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/*
* Inflates the structure's fieldname length. buf must hold at least
* nfields*fieldname_length bytes
*/
/** @brief Inflates the structure's fieldnames
*
* buf must hold at least @c nfields * @c fieldname_length bytes
* @ingroup mat_internal
* @param mat Pointer to the MAT file
* @param matvar Pointer to the MAT variable
* @param buf Pointer to store the fieldnames
* @param nfields Number of fields
* @param fieldname_length Maximum length in bytes of each field
* @param padding Number of padding bytes
* @return Number of bytes read from the file
*/
size_t
InflateFieldNames(mat_t *mat,matvar_t *matvar,void *buf,int nfields,
int fieldname_length,int padding)
{
mat_uint8_t comp_buf[32];
int err;
size_t bytesread = 0, readresult = 1;
if ( buf == NULL )
return 0;
if ( !matvar->internal->z->avail_in ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
bytesread += fread(comp_buf,1,1,(FILE*)mat->fp);
}
matvar->internal->z->avail_out = nfields*fieldname_length+padding;
matvar->internal->z->next_out = (Bytef*)buf;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNames: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
while ( matvar->internal->z->avail_out && !matvar->internal->z->avail_in && 1 == readresult ) {
matvar->internal->z->avail_in = 1;
matvar->internal->z->next_in = comp_buf;
readresult = fread(comp_buf,1,1,(FILE*)mat->fp);
bytesread += readresult;
err = inflate(matvar->internal->z,Z_NO_FLUSH);
if ( err != Z_OK ) {
Mat_Critical("InflateFieldNames: inflate returned %s",zError(err == Z_NEED_DICT ? Z_DATA_ERROR : err));
return bytesread;
}
}
if ( matvar->internal->z->avail_in ) {
(void)fseek((FILE*)mat->fp,-(int)matvar->internal->z->avail_in,SEEK_CUR);
bytesread -= matvar->internal->z->avail_in;
matvar->internal->z->avail_in = 0;
}
return bytesread;
}
/** @endcond */
#endif

View file

@ -0,0 +1,498 @@
/** @file io.c
* MAT File I/O Utility Functions
*/
/*
* Copyright (c) 2005-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "matio_private.h"
#if !defined(HAVE_VA_COPY) && defined(HAVE___VA_COPY)
# define va_copy(d,s) __va_copy(d,s)
#elif !defined(HAVE_VA_COPY)
# define va_copy(d,s) memcpy(&(d),&(s),sizeof(va_list))
#endif
static void (*logfunc)(int log_level, char *message ) = NULL;
static const char *progname = NULL;
/** @brief Allocates and prints to a new string
*
* @ingroup mat_util
* @param format format string
* @param ap variable argument list
* @return Newly allocated string with format printed to it
*/
char *
strdup_vprintf(const char* format, va_list ap)
{
va_list ap2;
int size;
char* buffer;
va_copy(ap2, ap);
size = mat_vsnprintf(NULL, 0, format, ap2)+1;
va_end(ap2);
buffer = (char*)malloc(size+1);
if ( !buffer )
return NULL;
mat_vsnprintf(buffer, size, format, ap);
return buffer;
}
/** @brief Allocates and prints to a new string using printf format
*
* @ingroup mat_util
* @param format format string
* @return Pointer to resulting string, or NULL if there was an error
*/
char *
strdup_printf(const char* format, ...)
{
char* buffer;
va_list ap;
va_start(ap, format);
buffer = strdup_vprintf(format, ap);
va_end(ap);
return buffer;
}
/** @brief Default logging function
*
* Prints the message to stderr/stdout and calls abort() if the
* log_level equals MATIO_LOG_LEVEL_ERROR.
* @ingroup mat_util
* @param log_level logging level
* @param message logging message
*/
static void
mat_logfunc( int log_level, char *message )
{
if ( progname ) {
if ( log_level & MATIO_LOG_LEVEL_CRITICAL) {
fprintf(stderr,"-E- %s: %s\n", progname, message);
fflush(stderr);
} else if ( log_level & MATIO_LOG_LEVEL_ERROR ) {
fprintf(stderr,"-E- %s: %s\n", progname, message);
fflush(stderr);
abort();
} else if ( log_level & MATIO_LOG_LEVEL_WARNING ) {
fprintf(stderr,"-W- %s: %s\n", progname, message);
fflush(stderr);
} else if ( log_level & MATIO_LOG_LEVEL_DEBUG ) {
fprintf(stderr,"-D- %s: %s\n", progname, message);
fflush(stderr);
} else if ( log_level & MATIO_LOG_LEVEL_MESSAGE ) {
fprintf(stdout,"%s\n", message);
fflush(stdout);
}
} else {
if ( log_level & MATIO_LOG_LEVEL_CRITICAL) {
fprintf(stderr,"-E- : %s\n", message);
fflush(stderr);
} else if ( log_level & MATIO_LOG_LEVEL_ERROR ) {
fprintf(stderr,"-E- : %s\n", message);
fflush(stderr);
abort();
} else if ( log_level & MATIO_LOG_LEVEL_WARNING ) {
fprintf(stderr,"-W- : %s\n", message);
fflush(stderr);
} else if ( log_level & MATIO_LOG_LEVEL_DEBUG ) {
fprintf(stderr,"-D- : %s\n", message);
fflush(stderr);
} else if ( log_level & MATIO_LOG_LEVEL_MESSAGE ) {
fprintf(stdout,"%s\n", message);
fflush(stdout);
}
}
}
/** @brief Logging function handler
*
* Calls either the default logging function @ref mat_logfunc
* set by @ref Mat_LogInit or a custom logging function set by
* @ref Mat_LogInitFunc.
* @ingroup mat_util
* @param loglevel log level
* @param format format string
* @param ap variable argument list
*/
static void
mat_log(int loglevel, const char *format, va_list ap)
{
char* buffer;
if ( !logfunc ) return;
buffer = strdup_vprintf(format, ap);
(*logfunc)(loglevel,buffer);
free(buffer);
return;
}
#if defined(MAT73) && MAT73
#define MSG_SIZE 1024
/** @brief HDF5 Error logging function
*
* @ingroup mat_util
* @param n indexed position of the error in the stack
* @param err_desc pointer to a data structure describing the error
* @param client_data pointer to client data
*/
static herr_t
mat_h5_log_func(unsigned n, const H5E_error_t *err_desc, void *client_data)
{
char maj[MSG_SIZE];
char min[MSG_SIZE];
char cls[MSG_SIZE];
if ( H5Eget_class_name(err_desc->cls_id, cls, MSG_SIZE) < 0 )
return -1;
if ( H5Eget_msg(err_desc->maj_num, NULL, maj, MSG_SIZE) < 0 )
return -1;
if ( H5Eget_msg(err_desc->min_num, NULL, min, MSG_SIZE) < 0 )
return -1;
Mat_Critical("%s error #%03u in %s()\n"
" file : %s:%u\n"
" major: %s\n"
" minor: %s",
cls, n, err_desc->func_name, err_desc->file_name, err_desc->line,
maj, min);
return 0;
}
/** @brief HDF5 Error logging function callback
*
* @ingroup mat_util
* @param estack error stack identifier
* @param client_data pointer to client data
*/
static herr_t
mat_h5_log_cb(hid_t estack, void *client_data)
{
hid_t estack_id = H5Eget_current_stack();
H5Ewalk(estack_id, H5E_WALK_DOWNWARD, mat_h5_log_func, client_data);
return H5Eclose_stack(estack_id);
}
#endif
/** @var debug
* @brief holds the debug level set in @ref Mat_SetDebug
* This variable is used to determine if information should be printed to
* the screen
* @ingroup mat_util
*/
static int debug = 0;
/** @var verbose
* @brief holds the verbose level set in @ref Mat_SetVerbose
* This variable is used to determine if information should be printed to
* the screen
* @ingroup mat_util
*/
static int verbose = 0;
/** @var silent
* @brief holds the silent level set in @ref Mat_SetVerbose
* If set, all output which is not an error is not displayed regardless
* of verbose level
* @ingroup mat_util
*/
static int silent = 0;
/** @brief Sets verbose parameters
*
* Sets the verbose level and silent level. These values are used by
* programs to determine what information should be printed to the screen
* @ingroup mat_util
* @param verb sets logging verbosity level
* @param s sets logging silent level
*/
int
Mat_SetVerbose( int verb, int s )
{
verbose = verb;
silent = s;
return 0;
}
/** @brief Set debug parameter
*
* Sets the debug level. This value is used by
* program to determine what information should be printed to the screen
* @ingroup mat_util
* @param d sets logging debug level
*/
int
Mat_SetDebug( int d )
{
debug = d;
return 0;
}
/** @brief Log a message unless silent
*
* Logs the message unless the silent option is set (See @ref Mat_SetVerbose).
* To log a message based on the verbose level, use @ref Mat_VerbMessage
* @ingroup mat_util
* @param format message format
*/
int Mat_Message( const char *format, ... )
{
va_list ap;
if ( silent ) return 0;
if ( !logfunc ) return 0;
va_start(ap, format );
mat_log(MATIO_LOG_LEVEL_MESSAGE, format, ap );
va_end(ap);
return 0;
}
/** @brief Log a message based on debug level
*
* If @e level is less than or equal to the set debug level, the message
* is printed. If the level is higher than the set debug level nothing
* is displayed.
* @ingroup mat_util
* @param level debug level
* @param format message format
*/
int Mat_DebugMessage( int level, const char *format, ... )
{
va_list ap;
if ( silent ) return 0;
if ( level > debug ) return 0;
va_start(ap, format );
mat_log(MATIO_LOG_LEVEL_DEBUG, format, ap );
va_end(ap);
return 0;
}
/** @brief Log a message based on verbose level
*
* If @e level is less than or equal to the set verbose level, the message
* is printed. If the level is higher than the set verbose level nothing
* is displayed.
* @ingroup mat_util
* @param level verbose level
* @param format message format
*/
int Mat_VerbMessage( int level, const char *format, ... )
{
va_list ap;
if ( silent ) return 0;
if ( level > verbose ) return 0;
va_start(ap, format );
mat_log(MATIO_LOG_LEVEL_MESSAGE, format, ap );
va_end(ap);
return 0;
}
/** @brief Logs a Critical message and returns to the user
*
* Logs a Critical message and returns to the user. If the program should
* stop running, use @ref Mat_Error
* @ingroup mat_util
* @param format format string identical to printf format
* @param ... arguments to the format string
*/
void Mat_Critical( const char *format, ... )
{
va_list ap;
va_start(ap, format );
mat_log(MATIO_LOG_LEVEL_CRITICAL, format, ap );
va_end(ap);
}
/** @brief Logs a Critical message and aborts the program
*
* Logs an Error message and aborts
* @ingroup mat_util
* @param format format string identical to printf format
* @param ... arguments to the format string
*/
void Mat_Error( const char *format, ... )
{
va_list ap;
va_start(ap, format );
mat_log( MATIO_LOG_LEVEL_ERROR, format, ap ); /* Shall never return to the calling function */
va_end(ap);
abort(); /* Always abort */
}
/** @brief Prints a helpstring to stdout and exits with status EXIT_SUCCESS (typically 0)
*
* Prints the array of strings to stdout and exits with status EXIT_SUCCESS. The array
* of strings should have NULL as its last element
* @code
* char *helpstr[] = {"My Help string line1","My help string line 2",NULL};
* Mat_Help(helpstr);
* @endcode
* @ingroup mat_util
* @param helpstr array of strings with NULL as its last element
*/
void Mat_Help( const char *helpstr[] )
{
int i;
for (i = 0; helpstr[i] != NULL; i++)
printf("%s\n",helpstr[i]);
exit(EXIT_SUCCESS);
}
/** @brief Closes the logging system
*
* @ingroup mat_util
* @retval 1
*/
int
Mat_LogClose( void )
{
logfunc = NULL;
#if defined(MAT73) && MAT73
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
#endif
return 1;
}
/** @brief Initializes the logging system
*
* @ingroup mat_util
* @param prog_name Name of the program initializing the logging functions
* @return 0 on success
*/
int
Mat_LogInit( const char *prog_name )
{
logfunc = &mat_logfunc;
#if defined(MAT73) && MAT73
H5Eset_auto(H5E_DEFAULT, mat_h5_log_cb, NULL);
#endif
verbose = 0;
silent = 0;
return 0;
}
/** @brief Initializes the logging system
*
* @ingroup mat_util
* @param prog_name Name of the program initializing the logging functions
* @param log_func pointer to the function to do the logging
* @return 0 on success
*/
int
Mat_LogInitFunc(const char *prog_name,
void (*log_func)(int log_level,char *message))
{
logfunc = log_func;
progname = prog_name;
#if defined(MAT73) && MAT73
H5Eset_auto(H5E_DEFAULT, mat_h5_log_cb, NULL);
#endif
verbose = 0;
silent = 0;
return 0;
}
/** @brief Prints a warning message to stdout
*
* Logs a warning message then returns
* @ingroup mat_util
* @param format format string identical to printf format
* @param ... arguments to the format string
*/
void
Mat_Warning( const char *format, ... )
{
va_list ap;
va_start(ap, format );
mat_log(MATIO_LOG_LEVEL_WARNING, format, ap );
va_end(ap);
}
/** @brief Calculate the size of MAT data types
*
* @ingroup mat_util
* @param data_type Data type enumeration
* @return size of the data type in bytes
*/
size_t
Mat_SizeOf(enum matio_types data_type)
{
switch (data_type) {
case MAT_T_DOUBLE:
return sizeof(double);
case MAT_T_SINGLE:
return sizeof(float);
#ifdef HAVE_MAT_INT64_T
case MAT_T_INT64:
return sizeof(mat_int64_t);
#endif
#ifdef HAVE_MAT_UINT64_T
case MAT_T_UINT64:
return sizeof(mat_uint64_t);
#endif
case MAT_T_INT32:
return sizeof(mat_int32_t);
case MAT_T_UINT32:
return sizeof(mat_uint32_t);
case MAT_T_INT16:
return sizeof(mat_int16_t);
case MAT_T_UINT16:
return sizeof(mat_uint16_t);
case MAT_T_INT8:
return sizeof(mat_int8_t);
case MAT_T_UINT8:
return sizeof(mat_uint8_t);
case MAT_T_UTF8:
return 1;
case MAT_T_UTF16:
return 2;
case MAT_T_UTF32:
return 4;
default:
return 0;
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,899 @@
/** @file mat4.c
* Matlab MAT version 4 file functions
* @ingroup MAT
*/
/*
* Copyright (c) 2005-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#if defined(__GLIBC__)
#include <endian.h>
#endif
#include "matio_private.h"
#include "mat4.h"
/** @if mat_devman
* @brief Creates a new Matlab MAT version 4 file
*
* Tries to create a new Matlab MAT file with the given name.
* @ingroup MAT
* @param matname Name of MAT file to create
* @return A pointer to the MAT file or NULL if it failed. This is not a
* simple FILE * and should not be used as one.
* @endif
*/
mat_t *
Mat_Create4(const char* matname)
{
FILE *fp;
mat_t *mat = NULL;
fp = fopen(matname,"w+b");
if ( !fp )
return NULL;
mat = (mat_t*)malloc(sizeof(*mat));
if ( NULL == mat ) {
fclose(fp);
Mat_Critical("Couldn't allocate memory for the MAT file");
return NULL;
}
mat->fp = fp;
mat->header = NULL;
mat->subsys_offset = NULL;
mat->filename = strdup_printf("%s",matname);
mat->version = MAT_FT_MAT4;
mat->byteswap = 0;
mat->mode = 0;
mat->bof = 0;
mat->next_index = 0;
mat->num_datasets = 0;
#if defined(MAT73) && MAT73
mat->refs_id = -1;
#endif
mat->dir = NULL;
Mat_Rewind(mat);
return mat;
}
/** @if mat_devman
* @brief Writes a matlab variable to a version 4 matlab file
*
* @ingroup mat_internal
* @param mat MAT file pointer
* @param matvar pointer to the mat variable
* @retval 0 on success
* @endif
*/
int
Mat_VarWrite4(mat_t *mat,matvar_t *matvar)
{
typedef struct {
mat_int32_t type;
mat_int32_t mrows;
mat_int32_t ncols;
mat_int32_t imagf;
mat_int32_t namelen;
} Fmatrix;
mat_int32_t nelems = 1, i;
Fmatrix x;
if ( NULL == mat || NULL == matvar || NULL == matvar->name || matvar->rank != 2 )
return -1;
switch ( matvar->data_type ) {
case MAT_T_DOUBLE:
x.type = 0;
break;
case MAT_T_SINGLE:
x.type = 10;
break;
case MAT_T_INT32:
x.type = 20;
break;
case MAT_T_INT16:
x.type = 30;
break;
case MAT_T_UINT16:
x.type = 40;
break;
case MAT_T_UINT8:
x.type = 50;
break;
default:
return 2;
}
#if defined(__GLIBC__)
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
#elif (__BYTE_ORDER == __BIG_ENDIAN)
x.type += 1000;
#else
return -1;
#endif
#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
x.type += 1000;
#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
#elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || \
defined(__ppc__) || defined(__hpux) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
x.type += 1000;
#elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || \
defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || \
defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || \
defined(_M_X64) || defined(__bfin__)
#else
return -1;
#endif
x.namelen = (mat_int32_t)strlen(matvar->name) + 1;
/* FIXME: SEEK_END is not Guaranteed by the C standard */
(void)fseek((FILE*)mat->fp,0,SEEK_END); /* Always write at end of file */
switch ( matvar->class_type ) {
case MAT_C_CHAR:
x.type++;
/* Fall through */
case MAT_C_DOUBLE:
case MAT_C_SINGLE:
case MAT_C_INT32:
case MAT_C_INT16:
case MAT_C_UINT16:
case MAT_C_UINT8:
for ( i = 0; i < matvar->rank; i++ ) {
mat_int32_t dim;
dim = (mat_int32_t)matvar->dims[i];
nelems *= dim;
}
x.mrows = (mat_int32_t)matvar->dims[0];
x.ncols = (mat_int32_t)matvar->dims[1];
x.imagf = matvar->isComplex ? 1 : 0;
fwrite(&x, sizeof(Fmatrix), 1, (FILE*)mat->fp);
fwrite(matvar->name, sizeof(char), x.namelen, (FILE*)mat->fp);
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data;
complex_data = (mat_complex_split_t*)matvar->data;
fwrite(complex_data->Re, matvar->data_size, nelems, (FILE*)mat->fp);
fwrite(complex_data->Im, matvar->data_size, nelems, (FILE*)mat->fp);
}
else {
fwrite(matvar->data, matvar->data_size, nelems, (FILE*)mat->fp);
}
break;
case MAT_C_SPARSE:
{
mat_sparse_t* sparse;
double tmp;
int j;
size_t stride = Mat_SizeOf(matvar->data_type);
#if !defined(EXTENDED_SPARSE)
if ( MAT_T_DOUBLE != matvar->data_type )
break;
#endif
sparse = (mat_sparse_t*)matvar->data;
x.type += 2;
x.mrows = sparse->njc > 0 ? sparse->jc[sparse->njc - 1] + 1 : 1;
x.ncols = matvar->isComplex ? 4 : 3;
x.imagf = 0;
fwrite(&x, sizeof(Fmatrix), 1, (FILE*)mat->fp);
fwrite(matvar->name, sizeof(char), x.namelen, (FILE*)mat->fp);
for ( i = 0; i < sparse->njc - 1; i++ ) {
for ( j = sparse->jc[i];
j < sparse->jc[i + 1] && j < sparse->ndata; j++ ) {
tmp = sparse->ir[j] + 1;
fwrite(&tmp, sizeof(double), 1, (FILE*)mat->fp);
}
}
tmp = matvar->dims[0];
fwrite(&tmp, sizeof(double), 1, (FILE*)mat->fp);
for ( i = 0; i < sparse->njc - 1; i++ ) {
for ( j = sparse->jc[i];
j < sparse->jc[i + 1] && j < sparse->ndata; j++ ) {
tmp = i + 1;
fwrite(&tmp, sizeof(double), 1, (FILE*)mat->fp);
}
}
tmp = matvar->dims[1];
fwrite(&tmp, sizeof(double), 1, (FILE*)mat->fp);
tmp = 0.;
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data;
char* re, *im;
complex_data = (mat_complex_split_t*)sparse->data;
re = (char*)complex_data->Re;
im = (char*)complex_data->Im;
for ( i = 0; i < sparse->njc - 1; i++ ) {
for ( j = sparse->jc[i];
j < sparse->jc[i + 1] && j < sparse->ndata; j++ ) {
fwrite(re + j*stride, stride, 1, (FILE*)mat->fp);
}
}
fwrite(&tmp, stride, 1, (FILE*)mat->fp);
for ( i = 0; i < sparse->njc - 1; i++ ) {
for ( j = sparse->jc[i];
j < sparse->jc[i + 1] && j < sparse->ndata; j++ ) {
fwrite(im + j*stride, stride, 1, (FILE*)mat->fp);
}
}
} else {
char *data = (char*)sparse->data;
for ( i = 0; i < sparse->njc - 1; i++ ) {
for ( j = sparse->jc[i];
j < sparse->jc[i + 1] && j < sparse->ndata; j++ ) {
fwrite(data + j*stride, stride, 1, (FILE*)mat->fp);
}
}
}
fwrite(&tmp, stride, 1, (FILE*)mat->fp);
break;
}
default:
break;
}
return 0;
}
/** @if mat_devman
* @brief Reads the data of a version 4 MAT file variable
*
* @ingroup mat_internal
* @param mat MAT file pointer
* @param matvar MAT variable pointer to read the data
* @endif
*/
void
Mat_VarRead4(mat_t *mat,matvar_t *matvar)
{
size_t nelems = 1;
SafeMulDims(matvar, &nelems);
(void)fseek((FILE*)mat->fp,matvar->internal->datapos,SEEK_SET);
switch ( matvar->class_type ) {
case MAT_C_DOUBLE:
matvar->data_size = sizeof(double);
SafeMul(&matvar->nbytes, nelems, matvar->data_size);
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data = ComplexMalloc(matvar->nbytes);
if ( NULL != complex_data ) {
matvar->data = complex_data;
ReadDoubleData(mat, (double*)complex_data->Re, matvar->data_type, nelems);
ReadDoubleData(mat, (double*)complex_data->Im, matvar->data_type, nelems);
}
else {
Mat_Critical("Couldn't allocate memory for the complex data");
}
} else {
matvar->data = malloc(matvar->nbytes);
if ( NULL != matvar->data ) {
ReadDoubleData(mat, (double*)matvar->data, matvar->data_type, nelems);
}
else {
Mat_Critical("Couldn't allocate memory for the data");
}
}
/* Update data type to match format of matvar->data */
matvar->data_type = MAT_T_DOUBLE;
break;
case MAT_C_CHAR:
matvar->data_size = 1;
matvar->nbytes = nelems;
matvar->data = malloc(matvar->nbytes);
if ( NULL != matvar->data ) {
ReadUInt8Data(mat, (mat_uint8_t*)matvar->data, matvar->data_type, nelems);
}
else {
Mat_Critical("Couldn't allocate memory for the data");
}
matvar->data_type = MAT_T_UINT8;
break;
case MAT_C_SPARSE:
matvar->data_size = sizeof(mat_sparse_t);
matvar->data = malloc(matvar->data_size);
if ( NULL != matvar->data ) {
double tmp;
int i;
mat_sparse_t* sparse;
long fpos;
enum matio_types data_type = MAT_T_DOUBLE;
/* matvar->dims[1] either is 3 for real or 4 for complex sparse */
matvar->isComplex = matvar->dims[1] == 4 ? 1 : 0;
sparse = (mat_sparse_t*)matvar->data;
sparse->nir = matvar->dims[0] - 1;
sparse->nzmax = sparse->nir;
sparse->ir = (mat_int32_t*)malloc(sparse->nir*sizeof(mat_int32_t));
if ( sparse->ir != NULL ) {
ReadInt32Data(mat, sparse->ir, data_type, sparse->nir);
for ( i = 0; i < sparse->nir; i++ )
sparse->ir[i] = sparse->ir[i] - 1;
} else {
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Couldn't allocate memory for the sparse row array");
return;
}
ReadDoubleData(mat, &tmp, data_type, 1);
matvar->dims[0] = (size_t)tmp;
fpos = ftell((FILE*)mat->fp);
if ( fpos == -1L ) {
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Couldn't determine file position");
return;
}
(void)fseek((FILE*)mat->fp,sparse->nir*Mat_SizeOf(data_type),
SEEK_CUR);
ReadDoubleData(mat, &tmp, data_type, 1);
if ( tmp > INT_MAX-1 || tmp < 0 ) {
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Invalid column dimension for sparse matrix");
return;
}
matvar->dims[1] = (size_t)tmp;
(void)fseek((FILE*)mat->fp,fpos,SEEK_SET);
if ( matvar->dims[1] > INT_MAX-1 ) {
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Invalid column dimension for sparse matrix");
return;
}
sparse->njc = (int)matvar->dims[1] + 1;
sparse->jc = (mat_int32_t*)malloc(sparse->njc*sizeof(mat_int32_t));
if ( sparse->jc != NULL ) {
mat_int32_t *jc;
jc = (mat_int32_t*)malloc(sparse->nir*sizeof(mat_int32_t));
if ( jc != NULL ) {
int j = 0;
sparse->jc[0] = 0;
ReadInt32Data(mat, jc, data_type, sparse->nir);
for ( i = 1; i < sparse->njc-1; i++ ) {
while ( j < sparse->nir && jc[j] <= i )
j++;
sparse->jc[i] = j;
}
free(jc);
/* terminating nnz */
sparse->jc[sparse->njc-1] = sparse->nir;
} else {
free(sparse->jc);
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Couldn't allocate memory for the sparse index array");
return;
}
} else {
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Couldn't allocate memory for the sparse index array");
return;
}
ReadDoubleData(mat, &tmp, data_type, 1);
sparse->ndata = sparse->nir;
data_type = matvar->data_type;
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data =
ComplexMalloc(sparse->ndata*Mat_SizeOf(data_type));
if ( NULL != complex_data ) {
sparse->data = complex_data;
#if defined(EXTENDED_SPARSE)
switch ( data_type ) {
case MAT_T_DOUBLE:
ReadDoubleData(mat, (double*)complex_data->Re,
data_type, sparse->ndata);
ReadDoubleData(mat, &tmp, data_type, 1);
ReadDoubleData(mat, (double*)complex_data->Im,
data_type, sparse->ndata);
ReadDoubleData(mat, &tmp, data_type, 1);
break;
case MAT_T_SINGLE:
{
float tmp2;
ReadSingleData(mat, (float*)complex_data->Re,
data_type, sparse->ndata);
ReadSingleData(mat, &tmp2, data_type, 1);
ReadSingleData(mat, (float*)complex_data->Im,
data_type, sparse->ndata);
ReadSingleData(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_INT32:
{
mat_int32_t tmp2;
ReadInt32Data(mat, (mat_int32_t*)complex_data->Re,
data_type, sparse->ndata);
ReadInt32Data(mat, &tmp2, data_type, 1);
ReadInt32Data(mat, (mat_int32_t*)complex_data->Im,
data_type, sparse->ndata);
ReadInt32Data(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_INT16:
{
mat_int16_t tmp2;
ReadInt16Data(mat, (mat_int16_t*)complex_data->Re,
data_type, sparse->ndata);
ReadInt16Data(mat, &tmp2, data_type, 1);
ReadInt16Data(mat, (mat_int16_t*)complex_data->Im,
data_type, sparse->ndata);
ReadInt16Data(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_UINT16:
{
mat_uint16_t tmp2;
ReadUInt16Data(mat, (mat_uint16_t*)complex_data->Re,
data_type, sparse->ndata);
ReadUInt16Data(mat, &tmp2, data_type, 1);
ReadUInt16Data(mat, (mat_uint16_t*)complex_data->Im,
data_type, sparse->ndata);
ReadUInt16Data(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_UINT8:
{
mat_uint8_t tmp2;
ReadUInt8Data(mat, (mat_uint8_t*)complex_data->Re,
data_type, sparse->ndata);
ReadUInt8Data(mat, &tmp2, data_type, 1);
ReadUInt8Data(mat, (mat_uint8_t*)complex_data->Im,
data_type, sparse->ndata);
ReadUInt8Data(mat, &tmp2, data_type, 1);
break;
}
default:
free(complex_data->Re);
free(complex_data->Im);
free(complex_data);
free(sparse->jc);
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Mat_VarRead4: %d is not a supported data type for "
"extended sparse", data_type);
return;
}
#else
ReadDoubleData(mat, (double*)complex_data->Re,
data_type, sparse->ndata);
ReadDoubleData(mat, &tmp, data_type, 1);
ReadDoubleData(mat, (double*)complex_data->Im,
data_type, sparse->ndata);
ReadDoubleData(mat, &tmp, data_type, 1);
#endif
}
else {
free(sparse->jc);
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Couldn't allocate memory for the complex sparse data");
return;
}
} else {
sparse->data = malloc(sparse->ndata*Mat_SizeOf(data_type));
if ( sparse->data != NULL ) {
#if defined(EXTENDED_SPARSE)
switch ( data_type ) {
case MAT_T_DOUBLE:
ReadDoubleData(mat, (double*)sparse->data,
data_type, sparse->ndata);
ReadDoubleData(mat, &tmp, data_type, 1);
break;
case MAT_T_SINGLE:
{
float tmp2;
ReadSingleData(mat, (float*)sparse->data,
data_type, sparse->ndata);
ReadSingleData(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_INT32:
{
mat_int32_t tmp2;
ReadInt32Data(mat, (mat_int32_t*)sparse->data,
data_type, sparse->ndata);
ReadInt32Data(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_INT16:
{
mat_int16_t tmp2;
ReadInt16Data(mat, (mat_int16_t*)sparse->data,
data_type, sparse->ndata);
ReadInt16Data(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_UINT16:
{
mat_uint16_t tmp2;
ReadUInt16Data(mat, (mat_uint16_t*)sparse->data,
data_type, sparse->ndata);
ReadUInt16Data(mat, &tmp2, data_type, 1);
break;
}
case MAT_T_UINT8:
{
mat_uint8_t tmp2;
ReadUInt8Data(mat, (mat_uint8_t*)sparse->data,
data_type, sparse->ndata);
ReadUInt8Data(mat, &tmp2, data_type, 1);
break;
}
default:
free(sparse->data);
free(sparse->jc);
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Mat_VarRead4: %d is not a supported data type for "
"extended sparse", data_type);
return;
}
#else
ReadDoubleData(mat, (double*)sparse->data, data_type, sparse->ndata);
ReadDoubleData(mat, &tmp, data_type, 1);
#endif
} else {
free(sparse->jc);
free(sparse->ir);
free(matvar->data);
matvar->data = NULL;
Mat_Critical("Couldn't allocate memory for the sparse data");
return;
}
}
break;
}
else {
Mat_Critical("Couldn't allocate memory for the data");
return;
}
default:
Mat_Critical("MAT V4 data type error");
return;
}
return;
}
/** @if mat_devman
* @brief Reads a slab of data from a version 4 MAT file for the @c matvar variable
*
* @ingroup mat_internal
* @param mat Version 4 MAT file pointer
* @param matvar pointer to the mat variable
* @param data pointer to store the read data in (must be of size
* edge[0]*...edge[rank-1]*Mat_SizeOfClass(matvar->class_type))
* @param start index to start reading data in each dimension
* @param stride write data every @c stride elements in each dimension
* @param edge number of elements to read in each dimension
* @retval 0 on success
* @endif
*/
int
Mat_VarReadData4(mat_t *mat,matvar_t *matvar,void *data,
int *start,int *stride,int *edge)
{
int err = 0;
(void)fseek((FILE*)mat->fp,matvar->internal->datapos,SEEK_SET);
switch( matvar->data_type ) {
case MAT_T_DOUBLE:
case MAT_T_SINGLE:
case MAT_T_INT32:
case MAT_T_INT16:
case MAT_T_UINT16:
case MAT_T_UINT8:
break;
default:
return 1;
}
if ( matvar->rank == 2 ) {
if ( (size_t)stride[0]*(edge[0]-1)+start[0]+1 > matvar->dims[0] )
err = 1;
else if ( (size_t)stride[1]*(edge[1]-1)+start[1]+1 > matvar->dims[1] )
err = 1;
if ( matvar->isComplex ) {
mat_complex_split_t *cdata = (mat_complex_split_t*)data;
size_t nbytes = Mat_SizeOf(matvar->data_type);
SafeMulDims(matvar, &nbytes);
ReadDataSlab2(mat,cdata->Re,matvar->class_type,matvar->data_type,
matvar->dims,start,stride,edge);
(void)fseek((FILE*)mat->fp,matvar->internal->datapos+nbytes,SEEK_SET);
ReadDataSlab2(mat,cdata->Im,matvar->class_type,
matvar->data_type,matvar->dims,start,stride,edge);
} else {
ReadDataSlab2(mat,data,matvar->class_type,matvar->data_type,
matvar->dims,start,stride,edge);
}
} else if ( matvar->isComplex ) {
mat_complex_split_t *cdata = (mat_complex_split_t*)data;
size_t nbytes = Mat_SizeOf(matvar->data_type);
SafeMulDims(matvar, &nbytes);
ReadDataSlabN(mat,cdata->Re,matvar->class_type,matvar->data_type,
matvar->rank,matvar->dims,start,stride,edge);
(void)fseek((FILE*)mat->fp,matvar->internal->datapos+nbytes,SEEK_SET);
ReadDataSlabN(mat,cdata->Im,matvar->class_type,matvar->data_type,
matvar->rank,matvar->dims,start,stride,edge);
} else {
ReadDataSlabN(mat,data,matvar->class_type,matvar->data_type,
matvar->rank,matvar->dims,start,stride,edge);
}
return err;
}
/** @brief Reads a subset of a MAT variable using a 1-D indexing
*
* Reads data from a MAT variable using a linear (1-D) indexing mode. The
* variable must have been read by Mat_VarReadInfo.
* @ingroup MAT
* @param mat MAT file to read data from
* @param matvar MAT variable information
* @param data pointer to store data in (must be pre-allocated)
* @param start starting index
* @param stride stride of data
* @param edge number of elements to read
* @retval 0 on success
*/
int
Mat_VarReadDataLinear4(mat_t *mat,matvar_t *matvar,void *data,int start,
int stride,int edge)
{
int err = 0;
size_t nelems = 1;
err = SafeMulDims(matvar, &nelems);
(void)fseek((FILE*)mat->fp,matvar->internal->datapos,SEEK_SET);
matvar->data_size = Mat_SizeOf(matvar->data_type);
if ( (size_t)stride*(edge-1)+start+1 > nelems ) {
return 1;
}
if ( matvar->isComplex ) {
mat_complex_split_t *complex_data = (mat_complex_split_t*)data;
long nbytes = nelems*matvar->data_size;
ReadDataSlab1(mat,complex_data->Re,matvar->class_type,
matvar->data_type,start,stride,edge);
(void)fseek((FILE*)mat->fp,matvar->internal->datapos+nbytes,SEEK_SET);
ReadDataSlab1(mat,complex_data->Im,matvar->class_type,
matvar->data_type,start,stride,edge);
} else {
ReadDataSlab1(mat,data,matvar->class_type,matvar->data_type,start,
stride,edge);
}
return err;
}
/** @if mat_devman
* @brief Reads the header information for the next MAT variable in a version 4 MAT file
*
* @ingroup mat_internal
* @param mat MAT file pointer
* @return pointer to the MAT variable or NULL
* @endif
*/
matvar_t *
Mat_VarReadNextInfo4(mat_t *mat)
{
int M,O,data_type,class_type;
mat_int32_t tmp;
long nBytes;
size_t err;
matvar_t *matvar = NULL;
union {
mat_uint32_t u;
mat_uint8_t c[4];
} endian;
if ( mat == NULL || mat->fp == NULL )
return NULL;
else if ( NULL == (matvar = Mat_VarCalloc()) )
return NULL;
err = fread(&tmp,sizeof(int),1,(FILE*)mat->fp);
if ( !err ) {
Mat_VarFree(matvar);
return NULL;
}
endian.u = 0x01020304;
/* See if MOPT may need byteswapping */
if ( tmp < 0 || tmp > 4052 ) {
if ( Mat_int32Swap(&tmp) > 4052 ) {
Mat_VarFree(matvar);
return NULL;
}
}
M = (int)floor(tmp / 1000.0);
tmp -= M*1000;
O = (int)floor(tmp / 100.0);
tmp -= O*100;
data_type = (int)floor(tmp / 10.0);
tmp -= data_type*10;
class_type = (int)floor(tmp / 1.0);
switch ( M ) {
case 0:
/* IEEE little endian */
mat->byteswap = (endian.c[0] != 4);
break;
case 1:
/* IEEE big endian */
mat->byteswap = (endian.c[0] != 1);
break;
default:
/* VAX, Cray, or bogus */
Mat_VarFree(matvar);
return NULL;
}
/* O must be zero */
if ( 0 != O ) {
Mat_VarFree(matvar);
return NULL;
}
/* Convert the V4 data type */
switch ( data_type ) {
case 0:
matvar->data_type = MAT_T_DOUBLE;
break;
case 1:
matvar->data_type = MAT_T_SINGLE;
break;
case 2:
matvar->data_type = MAT_T_INT32;
break;
case 3:
matvar->data_type = MAT_T_INT16;
break;
case 4:
matvar->data_type = MAT_T_UINT16;
break;
case 5:
matvar->data_type = MAT_T_UINT8;
break;
default:
Mat_VarFree(matvar);
return NULL;
}
switch ( class_type ) {
case 0:
matvar->class_type = MAT_C_DOUBLE;
break;
case 1:
matvar->class_type = MAT_C_CHAR;
break;
case 2:
matvar->class_type = MAT_C_SPARSE;
break;
default:
Mat_VarFree(matvar);
return NULL;
}
matvar->rank = 2;
matvar->dims = (size_t*)malloc(2*sizeof(*matvar->dims));
if ( NULL == matvar->dims ) {
Mat_VarFree(matvar);
return NULL;
}
err = fread(&tmp,sizeof(int),1,(FILE*)mat->fp);
if ( mat->byteswap )
Mat_int32Swap(&tmp);
matvar->dims[0] = tmp;
if ( !err ) {
Mat_VarFree(matvar);
return NULL;
}
err = fread(&tmp,sizeof(int),1,(FILE*)mat->fp);
if ( mat->byteswap )
Mat_int32Swap(&tmp);
matvar->dims[1] = tmp;
if ( !err ) {
Mat_VarFree(matvar);
return NULL;
}
err = fread(&(matvar->isComplex),sizeof(int),1,(FILE*)mat->fp);
if ( !err ) {
Mat_VarFree(matvar);
return NULL;
}
if ( matvar->isComplex && MAT_C_CHAR == matvar->class_type ) {
Mat_VarFree(matvar);
return NULL;
}
err = fread(&tmp,sizeof(int),1,(FILE*)mat->fp);
if ( !err ) {
Mat_VarFree(matvar);
return NULL;
}
if ( mat->byteswap )
Mat_int32Swap(&tmp);
/* Check that the length of the variable name is at least 1 */
if ( tmp < 1 ) {
Mat_VarFree(matvar);
return NULL;
}
matvar->name = (char*)malloc(tmp);
if ( NULL == matvar->name ) {
Mat_VarFree(matvar);
return NULL;
}
err = fread(matvar->name,1,tmp,(FILE*)mat->fp);
if ( !err ) {
Mat_VarFree(matvar);
return NULL;
}
matvar->internal->datapos = ftell((FILE*)mat->fp);
if ( matvar->internal->datapos == -1L ) {
Mat_VarFree(matvar);
Mat_Critical("Couldn't determine file position");
return NULL;
}
{
size_t tmp2 = Mat_SizeOf(matvar->data_type);
if ( matvar->isComplex )
tmp2 *= 2;
SafeMulDims(matvar, &tmp2);
nBytes = (long)tmp2;
}
(void)fseek((FILE*)mat->fp,nBytes,SEEK_CUR);
return matvar;
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2008-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MAT4_H
#define MAT4_H
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif
EXTERN mat_t *Mat_Create4(const char* matname);
EXTERN int Mat_VarWrite4(mat_t *mat,matvar_t *matvar);
EXTERN void Mat_VarRead4(mat_t *mat, matvar_t *matvar);
EXTERN int Mat_VarReadData4(mat_t *mat,matvar_t *matvar,void *data,
int *start,int *stride,int *edge);
EXTERN int Mat_VarReadDataLinear4(mat_t *mat,matvar_t *matvar,void *data,int start,
int stride,int edge);
EXTERN matvar_t *Mat_VarReadNextInfo4(mat_t *mat);
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2008-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MAT5_H
#define MAT5_H
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif
EXTERN mat_t *Mat_Create5(const char *matname,const char *hdr_str);
EXTERN matvar_t *Mat_VarReadNextInfo5( mat_t *mat );
EXTERN void Mat_VarRead5(mat_t *mat, matvar_t *matvar);
EXTERN int Mat_VarReadData5(mat_t *mat,matvar_t *matvar,void *data,
int *start,int *stride,int *edge);
EXTERN int Mat_VarReadDataLinear5(mat_t *mat,matvar_t *matvar,void *data,
int start,int stride,int edge);
EXTERN int Mat_VarWrite5(mat_t *mat,matvar_t *matvar,int compress);
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2005-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MAT73_H
#define MAT73_H
#include <hdf5.h>
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif
EXTERN mat_t *Mat_Create73(const char *matname,const char *hdr_str);
EXTERN void Mat_VarRead73(mat_t *mat,matvar_t *matvar);
EXTERN int Mat_VarReadData73(mat_t *mat,matvar_t *matvar,void *data,
int *start,int *stride,int *edge);
EXTERN int Mat_VarReadDataLinear73(mat_t *mat,matvar_t *matvar,void *data,
int start,int stride,int edge);
EXTERN matvar_t *Mat_VarReadNextInfo73(mat_t *mat);
EXTERN int Mat_VarWrite73(mat_t *mat,matvar_t *matvar,int compress);
EXTERN int Mat_VarWriteAppend73(mat_t *mat,matvar_t *matvar,int compress,
int dim);
#endif

View file

@ -0,0 +1,323 @@
/** @file matio.h
* LIBMATIO Header
* @ingroup MAT
*/
/*
* Copyright (c) 2005-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MATIO_H
#define MATIO_H
#include <stdlib.h>
#include <stdio.h>
#include "matio_pubconf.h"
#include <stdarg.h>
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif
/** @defgroup MAT Matlab MAT File I/O Library */
/** @defgroup mat_util MAT File I/O Utility Functions */
/** @if mat_devman @defgroup mat_internal Internal Functions @endif */
/** @brief MAT file access types
*
* @ingroup MAT
* MAT file access types
*/
enum mat_acc {
MAT_ACC_RDONLY = 0, /**< @brief Read only file access */
MAT_ACC_RDWR = 1 /**< @brief Read/Write file access */
};
/** @brief MAT file versions
*
* @ingroup MAT
* MAT file versions
*/
enum mat_ft {
MAT_FT_MAT73 = 0x0200, /**< @brief Matlab version 7.3 file */
MAT_FT_MAT5 = 0x0100, /**< @brief Matlab version 5 file */
MAT_FT_MAT4 = 0x0010, /**< @brief Matlab version 4 file */
MAT_FT_UNDEFINED = 0 /**< @brief Undefined version */
};
/** @brief Matlab data types
*
* @ingroup MAT
* Matlab data types
*/
enum matio_types {
MAT_T_UNKNOWN = 0, /**< @brief UNKNOWN data type */
MAT_T_INT8 = 1, /**< @brief 8-bit signed integer data type */
MAT_T_UINT8 = 2, /**< @brief 8-bit unsigned integer data type */
MAT_T_INT16 = 3, /**< @brief 16-bit signed integer data type */
MAT_T_UINT16 = 4, /**< @brief 16-bit unsigned integer data type */
MAT_T_INT32 = 5, /**< @brief 32-bit signed integer data type */
MAT_T_UINT32 = 6, /**< @brief 32-bit unsigned integer data type */
MAT_T_SINGLE = 7, /**< @brief IEEE 754 single precision data type */
MAT_T_DOUBLE = 9, /**< @brief IEEE 754 double precision data type */
MAT_T_INT64 = 12, /**< @brief 64-bit signed integer data type */
MAT_T_UINT64 = 13, /**< @brief 64-bit unsigned integer data type */
MAT_T_MATRIX = 14, /**< @brief matrix data type */
MAT_T_COMPRESSED = 15, /**< @brief compressed data type */
MAT_T_UTF8 = 16, /**< @brief 8-bit Unicode text data type */
MAT_T_UTF16 = 17, /**< @brief 16-bit Unicode text data type */
MAT_T_UTF32 = 18, /**< @brief 32-bit Unicode text data type */
MAT_T_STRING = 20, /**< @brief String data type */
MAT_T_CELL = 21, /**< @brief Cell array data type */
MAT_T_STRUCT = 22, /**< @brief Structure data type */
MAT_T_ARRAY = 23, /**< @brief Array data type */
MAT_T_FUNCTION = 24 /**< @brief Function data type */
};
/** @brief Matlab variable classes
*
* @ingroup MAT
* Matlab variable classes
*/
enum matio_classes {
MAT_C_EMPTY = 0, /**< @brief Empty array */
MAT_C_CELL = 1, /**< @brief Matlab cell array class */
MAT_C_STRUCT = 2, /**< @brief Matlab structure class */
MAT_C_OBJECT = 3, /**< @brief Matlab object class */
MAT_C_CHAR = 4, /**< @brief Matlab character array class */
MAT_C_SPARSE = 5, /**< @brief Matlab sparse array class */
MAT_C_DOUBLE = 6, /**< @brief Matlab double-precision class */
MAT_C_SINGLE = 7, /**< @brief Matlab single-precision class */
MAT_C_INT8 = 8, /**< @brief Matlab signed 8-bit integer class */
MAT_C_UINT8 = 9, /**< @brief Matlab unsigned 8-bit integer class */
MAT_C_INT16 = 10, /**< @brief Matlab signed 16-bit integer class */
MAT_C_UINT16 = 11, /**< @brief Matlab unsigned 16-bit integer class */
MAT_C_INT32 = 12, /**< @brief Matlab signed 32-bit integer class */
MAT_C_UINT32 = 13, /**< @brief Matlab unsigned 32-bit integer class */
MAT_C_INT64 = 14, /**< @brief Matlab signed 64-bit integer class */
MAT_C_UINT64 = 15, /**< @brief Matlab unsigned 64-bit integer class */
MAT_C_FUNCTION = 16, /**< @brief Matlab function class */
MAT_C_OPAQUE = 17 /**< @brief Matlab opaque class */
};
/** @brief Matlab array flags
*
* @ingroup MAT
* Matlab array flags
*/
enum matio_flags {
MAT_F_COMPLEX = 0x0800, /**< @brief Complex bit flag */
MAT_F_GLOBAL = 0x0400, /**< @brief Global bit flag */
MAT_F_LOGICAL = 0x0200, /**< @brief Logical bit flag */
MAT_F_DONT_COPY_DATA = 0x0001 /**< Don't copy data, use keep the pointer */
};
/** @brief MAT file compression options
*
* This option is only used on version 5 MAT files
* @ingroup MAT
*/
enum matio_compression {
MAT_COMPRESSION_NONE = 0, /**< @brief No compression */
MAT_COMPRESSION_ZLIB = 1 /**< @brief zlib compression */
};
/** @brief matio lookup type
*
* @ingroup MAT
* matio lookup type
*/
enum {
MAT_BY_NAME = 1, /**< Lookup by name */
MAT_BY_INDEX = 2 /**< Lookup by index */
};
/** @brief Complex data type using split storage
*
* Complex data type using split real/imaginary pointers
* @ingroup MAT
*/
typedef struct mat_complex_split_t {
void *Re; /**< Pointer to the real part */
void *Im; /**< Pointer to the imaginary part */
} mat_complex_split_t;
struct _mat_t;
/** @brief Matlab MAT File information
* Contains information about a Matlab MAT file
* @ingroup MAT
*/
typedef struct _mat_t mat_t;
/* Incomplete definition for private library data */
struct matvar_internal;
/** @brief Matlab variable information
*
* Contains information about a Matlab variable
* @ingroup MAT
*/
typedef struct matvar_t {
size_t nbytes; /**< Number of bytes for the MAT variable */
int rank; /**< Rank (Number of dimensions) of the data */
enum matio_types data_type; /**< Data type (MAT_T_*) */
int data_size; /**< Bytes / element for the data */
enum matio_classes class_type; /**< Class type in Matlab (MAT_C_DOUBLE, etc) */
int isComplex; /**< non-zero if the data is complex, 0 if real */
int isGlobal; /**< non-zero if the variable is global */
int isLogical; /**< non-zero if the variable is logical */
size_t *dims; /**< Array of lengths for each dimension */
char *name; /**< Name of the variable */
void *data; /**< Pointer to the data */
int mem_conserve; /**< 1 if Memory was conserved with data */
enum matio_compression compression; /**< Variable compression type */
struct matvar_internal *internal; /**< matio internal data */
} matvar_t;
/** @brief sparse data information
*
* Contains information and data for a sparse matrix
* @ingroup MAT
*/
typedef struct mat_sparse_t {
int nzmax; /**< Maximum number of non-zero elements */
mat_int32_t *ir; /**< Array of size nzmax where ir[k] is the row of
* data[k]. 0 <= k <= nzmax
*/
int nir; /**< number of elements in ir */
mat_int32_t *jc; /**< Array size N+1 (N is number of columns) with
* jc[k] being the index into ir/data of the
* first non-zero element for row k.
*/
int njc; /**< Number of elements in jc */
int ndata; /**< Number of complex/real data values */
void *data; /**< Array of data elements */
} mat_sparse_t;
/** @cond 0 */
#define MATIO_LOG_LEVEL_ERROR 1
#define MATIO_LOG_LEVEL_CRITICAL 1 << 1
#define MATIO_LOG_LEVEL_WARNING 1 << 2
#define MATIO_LOG_LEVEL_MESSAGE 1 << 3
#define MATIO_LOG_LEVEL_DEBUG 1 << 4
/** @endcond */
/* Library function */
EXTERN void Mat_GetLibraryVersion(int *major,int *minor,int *release);
/* io.c */
EXTERN char *strdup_vprintf(const char *format, va_list ap) MATIO_FORMATATTR_VPRINTF;
EXTERN char *strdup_printf(const char *format, ...) MATIO_FORMATATTR_PRINTF1;
EXTERN int Mat_SetVerbose(int verb, int s);
EXTERN int Mat_SetDebug(int d);
EXTERN void Mat_Critical(const char *format, ...) MATIO_FORMATATTR_PRINTF1;
EXTERN MATIO_NORETURN void Mat_Error(const char *format, ...) MATIO_NORETURNATTR MATIO_FORMATATTR_PRINTF1;
EXTERN void Mat_Help(const char *helpstr[]);
EXTERN int Mat_LogInit(const char *prog_name);
EXTERN int Mat_LogClose(void);
EXTERN int Mat_LogInitFunc(const char *prog_name,
void (*log_func)(int log_level, char *message));
EXTERN int Mat_Message(const char *format, ...) MATIO_FORMATATTR_PRINTF1;
EXTERN int Mat_DebugMessage(int level, const char *format, ...) MATIO_FORMATATTR_PRINTF2;
EXTERN int Mat_VerbMessage(int level, const char *format, ...) MATIO_FORMATATTR_PRINTF2;
EXTERN void Mat_Warning(const char *format, ...) MATIO_FORMATATTR_PRINTF1;
EXTERN size_t Mat_SizeOf(enum matio_types data_type);
EXTERN size_t Mat_SizeOfClass(int class_type);
/* MAT File functions */
/** Create new Matlab MAT file */
#define Mat_Create(a,b) Mat_CreateVer(a,b,MAT_FT_DEFAULT)
EXTERN mat_t *Mat_CreateVer(const char *matname,const char *hdr_str,
enum mat_ft mat_file_ver);
EXTERN int Mat_Close(mat_t *mat);
EXTERN mat_t *Mat_Open(const char *matname,int mode);
EXTERN const char *Mat_GetFilename(mat_t *mat);
EXTERN const char *Mat_GetHeader(mat_t *mat);
EXTERN enum mat_ft Mat_GetVersion(mat_t *mat);
EXTERN char **Mat_GetDir(mat_t *mat, size_t *n);
EXTERN int Mat_Rewind(mat_t *mat);
/* MAT variable functions */
EXTERN matvar_t *Mat_VarCalloc(void);
EXTERN matvar_t *Mat_VarCreate(const char *name,enum matio_classes class_type,
enum matio_types data_type,int rank,size_t *dims,
void *data,int opt);
EXTERN matvar_t *Mat_VarCreateStruct(const char *name,int rank,size_t *dims,
const char **fields,unsigned nfields);
EXTERN int Mat_VarDelete(mat_t *mat, const char *name);
EXTERN matvar_t *Mat_VarDuplicate(const matvar_t *in, int opt);
EXTERN void Mat_VarFree(matvar_t *matvar);
EXTERN matvar_t *Mat_VarGetCell(matvar_t *matvar,int index);
EXTERN matvar_t **Mat_VarGetCells(matvar_t *matvar,int *start,int *stride,
int *edge);
EXTERN matvar_t **Mat_VarGetCellsLinear(matvar_t *matvar,int start,int stride,
int edge);
EXTERN size_t Mat_VarGetSize(matvar_t *matvar);
EXTERN unsigned Mat_VarGetNumberOfFields(matvar_t *matvar);
EXTERN int Mat_VarAddStructField(matvar_t *matvar,const char *fieldname);
EXTERN char * const *Mat_VarGetStructFieldnames(const matvar_t *matvar);
EXTERN matvar_t *Mat_VarGetStructFieldByIndex(matvar_t *matvar,
size_t field_index,size_t index);
EXTERN matvar_t *Mat_VarGetStructFieldByName(matvar_t *matvar,
const char *field_name,size_t index);
EXTERN matvar_t *Mat_VarGetStructField(matvar_t *matvar,void *name_or_index,
int opt,int index);
EXTERN matvar_t *Mat_VarGetStructs(matvar_t *matvar,int *start,int *stride,
int *edge,int copy_fields);
EXTERN matvar_t *Mat_VarGetStructsLinear(matvar_t *matvar,int start,int stride,
int edge,int copy_fields);
EXTERN void Mat_VarPrint(matvar_t *matvar, int printdata);
EXTERN matvar_t *Mat_VarRead(mat_t *mat, const char *name);
EXTERN int Mat_VarReadData(mat_t *mat,matvar_t *matvar,void *data,
int *start,int *stride,int *edge);
EXTERN int Mat_VarReadDataAll(mat_t *mat,matvar_t *matvar);
EXTERN int Mat_VarReadDataLinear(mat_t *mat,matvar_t *matvar,void *data,
int start,int stride,int edge);
EXTERN matvar_t *Mat_VarReadInfo(mat_t *mat, const char *name);
EXTERN matvar_t *Mat_VarReadNext(mat_t *mat);
EXTERN matvar_t *Mat_VarReadNextInfo(mat_t *mat);
EXTERN matvar_t *Mat_VarSetCell(matvar_t *matvar,int index,matvar_t *cell);
EXTERN matvar_t *Mat_VarSetStructFieldByIndex(matvar_t *matvar,
size_t field_index,size_t index,matvar_t *field);
EXTERN matvar_t *Mat_VarSetStructFieldByName(matvar_t *matvar,
const char *field_name,size_t index,matvar_t *field);
EXTERN int Mat_VarWrite(mat_t *mat,matvar_t *matvar,
enum matio_compression compress);
EXTERN int Mat_VarWriteAppend(mat_t *mat,matvar_t *matvar,
enum matio_compression compress,int dim);
EXTERN int Mat_VarWriteInfo(mat_t *mat,matvar_t *matvar);
EXTERN int Mat_VarWriteData(mat_t *mat,matvar_t *matvar,void *data,
int *start,int *stride,int *edge);
/* Other functions */
EXTERN int Mat_CalcSingleSubscript(int rank,int *dims,int *subs);
EXTERN int Mat_CalcSingleSubscript2(int rank,size_t *dims,size_t *subs,size_t *index);
EXTERN int *Mat_CalcSubscripts(int rank,int *dims,int index);
EXTERN size_t *Mat_CalcSubscripts2(int rank,size_t *dims,size_t index);
#endif

View file

@ -0,0 +1,282 @@
/*
* Copyright (c) 2012-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Debug enabled */
#undef DEBUG
/* Extended sparse matrix data types */
#define EXTENDED_SPARSE 1
/* Define to dummy `main' function (if any) required to link to the Fortran
libraries. */
#undef FC_DUMMY_MAIN
/* Define if F77 and FC dummy `main' functions are identical. */
#undef FC_DUMMY_MAIN_EQ_F77
/* Define to a macro mangling the given C identifier (in lower and upper
case), which must not contain underscores, for linking with Fortran. */
#undef FC_FUNC
/* As FC_FUNC, but for C identifiers containing underscores. */
#undef FC_FUNC_
/* Define to 1 if you have the `asprintf' function. */
#undef HAVE_ASPRINTF
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if the system has the type `intmax_t'. */
#if defined(_MSC_VER) && _MSC_VER >= 1600
#define HAVE_INTMAX_T 1
#else
#undef HAVE_INTMAX_T
#endif
/* Define to 1 if you have the <inttypes.h> header file. */
#if defined(_MSC_VER) && _MSC_VER >= 1800
#define HAVE_INTTYPES_H 1
#else
#undef HAVE_INTTYPES_H
#endif
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM
/* Define to 1 if you have the `localeconv' function. */
#define HAVE_LOCALECONV 1
/* Define to 1 if you have the <locale.h> header file. */
#define HAVE_LOCALE_H 1
/* Define to 1 if the system has the type `long double'. */
#if defined(_MSC_VER) && _MSC_VER >= 1300
#define HAVE_LONG_DOUBLE 1
#else
#undef HAVE_LONG_DOUBLE
#endif
/* Define to 1 if the system has the type `long long int'. */
#if defined(_MSC_VER) && _MSC_VER >= 1300
#define HAVE_LONG_LONG_INT 1
#else
#undef HAVE_LONG_LONG_INT
#endif
/* Have MAT int16 */
#define HAVE_MAT_INT16_T 1
/* Have MAT int32 */
#define HAVE_MAT_INT32_T 1
/* Have MAT int64 */
#define HAVE_MAT_INT64_T 1
/* Have MAT int8 */
#define HAVE_MAT_INT8_T 1
/* Have MAT uint16 */
#define HAVE_MAT_UINT16_T 1
/* Have MAT uint32 */
#define HAVE_MAT_UINT32_T 1
/* Have MAT uint64 */
#define HAVE_MAT_UINT64_T 1
/* Have MAT uint8 */
#define HAVE_MAT_UINT8_T 1
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if the system has the type `ptrdiff_t'. */
#define HAVE_PTRDIFF_T 1
/* Define to 1 if you have a C99 compliant `snprintf' function. */
#if defined(_MSC_VER) && _MSC_VER >= 1900
#define HAVE_SNPRINTF 1
#else
#undef HAVE_SNPRINTF
#endif
/* Define to 1 if you have the <stdarg.h> header file. */
#define HAVE_STDARG_H 1
/* Define to 1 if you have the <stddef.h> header file. */
#define HAVE_STDDEF_H 1
/* Define to 1 if you have the <stdint.h> header file. */
#if defined(_MSC_VER) && _MSC_VER >= 1600
#define HAVE_STDINT_H 1
#else
#undef HAVE_STDINT_H
#endif
/* Have the <stdlib.h> header file */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if `decimal_point' is member of `struct lconv'. */
#define HAVE_STRUCT_LCONV_DECIMAL_POINT 1
/* Define to 1 if `thousands_sep' is member of `struct lconv'. */
#define HAVE_STRUCT_LCONV_THOUSANDS_SEP 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if the system has the type `uintmax_t'. */
#if defined(_MSC_VER) && _MSC_VER >= 1600
#define HAVE_UINTMAX_T 1
#else
#undef HAVE_UINTMAX_T
#endif
/* Define to 1 if the system has the type `uintptr_t'. */
#define HAVE_UINTPTR_T 1
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if the system has the type `unsigned long long int'. */
#if defined(_MSC_VER) && _MSC_VER >= 1300
#define HAVE_UNSIGNED_LONG_LONG_INT 1
#else
#undef HAVE_UNSIGNED_LONG_LONG_INT
#endif
/* Define to 1 if you have the <varargs.h> header file. */
#define HAVE_VARARGS_H 1
/* Define to 1 if you have the `vasprintf' function. */
#undef HAVE_VASPRINTF
/* Define to 1 if you have the `va_copy' function or macro. */
#if defined(_MSC_VER) && _MSC_VER >= 1800
#define HAVE_VA_COPY 1
#else
#undef HAVE_VA_COPY
#endif
/* Define to 1 if you have a C99 compliant `vsnprintf' function. */
#if defined(_MSC_VER) && _MSC_VER >= 1900
#define HAVE_VSNPRINTF 1
#else
#undef HAVE_VSNPRINTF
#endif
/* Define to 1 if you have the `__va_copy' function or macro. */
#undef HAVE___VA_COPY
/* OS is Linux */
#undef LINUX
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* Platform */
#if defined(_WIN64)
# define MATIO_PLATFORM "x86_64-pc-windows"
#elif defined(_WIN32)
# define MATIO_PLATFORM "i686-pc-windows"
#endif
/* Debug disabled */
#undef NODEBUG
/* Name of package */
#define PACKAGE "matio"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "t-beu@users.sourceforge.net"
/* Define to the full name of this package. */
#define PACKAGE_NAME "MATIO"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "MATIO 1.5.15"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "matio"
/* Define to the home page for this package. */
#define PACKAGE_URL "https://sourceforge.net/projects/matio"
/* Define to the version of this package. */
#define PACKAGE_VERSION "1.5.15"
/* The size of `char', as computed by sizeof. */
#define SIZEOF_CHAR 1
/* The size of `double', as computed by sizeof. */
#define SIZEOF_DOUBLE 8
/* The size of `float', as computed by sizeof. */
#define SIZEOF_FLOAT 4
/* The size of `int', as computed by sizeof. */
#define SIZEOF_INT 4
/* The size of `long', as computed by sizeof. */
#define SIZEOF_LONG 4
/* The size of `long long', as computed by sizeof. */
#define SIZEOF_LONG_LONG 8
/* The size of `short', as computed by sizeof. */
#define SIZEOF_SHORT 2
#if defined(_WIN64)
/* The size of `void *', as computed by sizeof. */
# define SIZEOF_VOID_P 8
/* The size of `size_t', as computed by sizeof. */
# define SIZEOF_SIZE_T 8
#elif defined(_WIN32)
/* The size of `void *', as computed by sizeof. */
# define SIZEOF_VOID_P 4
/* The size of `size_t', as computed by sizeof. */
# define SIZEOF_SIZE_T 4
#endif
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Version number of package */
#define VERSION "1.5.15"
/* Z prefix */
#undef Z_PREFIX

View file

@ -0,0 +1,244 @@
/*
* Copyright (c) 2012-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Debug enabled */
#undef DEBUG
/* Extended sparse matrix data types */
#undef EXTENDED_SPARSE
/* Define to dummy `main' function (if any) required to link to the Fortran
libraries. */
#undef FC_DUMMY_MAIN
/* Define if F77 and FC dummy `main' functions are identical. */
#undef FC_DUMMY_MAIN_EQ_F77
/* Define to a macro mangling the given C identifier (in lower and upper
case), which must not contain underscores, for linking with Fortran. */
#undef FC_FUNC
/* As FC_FUNC, but for C identifiers containing underscores. */
#undef FC_FUNC_
/* Define to 1 if you have the `asprintf' function. */
#undef HAVE_ASPRINTF
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Have HDF5 */
#undef HAVE_HDF5
/* Define to 1 if the system has the type `intmax_t'. */
#undef HAVE_INTMAX_T
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM
/* Define to 1 if you have the `localeconv' function. */
#undef HAVE_LOCALECONV
/* Define to 1 if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H
/* Define to 1 if the system has the type `long double'. */
#undef HAVE_LONG_DOUBLE
/* Define to 1 if the system has the type `long long int'. */
#undef HAVE_LONG_LONG_INT
/* Have MAT int16 */
#undef HAVE_MAT_INT16_T
/* Have MAT int32 */
#undef HAVE_MAT_INT32_T
/* Have MAT int64 */
#undef HAVE_MAT_INT64_T
/* Have MAT int8 */
#undef HAVE_MAT_INT8_T
/* Have MAT uint16 */
#undef HAVE_MAT_UINT16_T
/* Have MAT uint32 */
#undef HAVE_MAT_UINT32_T
/* Have MAT uint64 */
#undef HAVE_MAT_UINT64_T
/* Have MAT uint8 */
#undef HAVE_MAT_UINT8_T
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if the system has the type `ptrdiff_t'. */
#undef HAVE_PTRDIFF_T
/* Define to 1 if you have a C99 compliant `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define to 1 if you have the <stdarg.h> header file. */
#undef HAVE_STDARG_H
/* Define to 1 if you have the <stddef.h> header file. */
#undef HAVE_STDDEF_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if `decimal_point' is member of `struct lconv'. */
#undef HAVE_STRUCT_LCONV_DECIMAL_POINT
/* Define to 1 if `thousands_sep' is member of `struct lconv'. */
#undef HAVE_STRUCT_LCONV_THOUSANDS_SEP
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if the system has the type `uintmax_t'. */
#undef HAVE_UINTMAX_T
/* Define to 1 if the system has the type `uintptr_t'. */
#undef HAVE_UINTPTR_T
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if the system has the type `unsigned long long int'. */
#undef HAVE_UNSIGNED_LONG_LONG_INT
/* Define to 1 if you have the <varargs.h> header file. */
#undef HAVE_VARARGS_H
/* Define to 1 if you have the `vasprintf' function. */
#undef HAVE_VASPRINTF
/* Define to 1 if you have the `va_copy' function or macro. */
#undef HAVE_VA_COPY
/* Define to 1 if you have a C99 compliant `vsnprintf' function. */
#undef HAVE_VSNPRINTF
/* Have zlib */
#undef HAVE_ZLIB
/* Define to 1 if you have the `__va_copy' function or macro. */
#undef HAVE___VA_COPY
/* OS is Linux */
#undef LINUX
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* MAT v7.3 file support */
#undef MAT73
/* Platform */
#undef MATIO_PLATFORM
/* Debug disabled */
#undef NODEBUG
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `char', as computed by sizeof. */
#undef SIZEOF_CHAR
/* The size of `double', as computed by sizeof. */
#undef SIZEOF_DOUBLE
/* The size of `float', as computed by sizeof. */
#undef SIZEOF_FLOAT
/* The size of `int', as computed by sizeof. */
#undef SIZEOF_INT
/* The size of `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* The size of `size_t', as computed by sizeof. */
#undef SIZEOF_SIZE_T
/* The size of `void *', as computed by sizeof. */
#undef SIZEOF_VOID_P
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* OS is Solaris */
#undef SUN
/* Version number of package */
#undef VERSION
/* Z prefix */
#undef Z_PREFIX

View file

@ -0,0 +1,231 @@
/*
* Copyright (c) 2008-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MATIO_PRIVATE_H
#define MATIO_PRIVATE_H
#include "matioConfig.h"
#include "matio.h"
#if defined(HAVE_ZLIB)
# include <plugin/z/lib/zlib.h>
#endif
#if defined(MAT73) && MAT73
# include <hdf5.h>
#endif
#ifndef EXTERN
# ifdef __cplusplus
# define EXTERN extern "C"
# else
# define EXTERN extern
# endif
#endif
#if defined(HAVE_ZLIB) && HAVE_ZLIB
# define ZLIB_BYTE_PTR(a) ((Bytef *)(a))
#endif
/** @if mat_devman
* @brief Matlab MAT File information
*
* Contains information about a Matlab MAT file
* @ingroup mat_internal
* @endif
*/
struct _mat_t {
void *fp; /**< File pointer for the MAT file */
char *header; /**< MAT file header string */
char *subsys_offset; /**< Offset */
char *filename; /**< Filename of the MAT file */
int version; /**< MAT file version */
int byteswap; /**< 1 if byte swapping is required, 0 otherwise */
int mode; /**< Access mode */
long bof; /**< Beginning of file not including any header */
size_t next_index; /**< Index/File position of next variable to read */
size_t num_datasets; /**< Number of datasets in the file */
#if defined(MAT73) && MAT73
hid_t refs_id; /**< Id of the /#refs# group in HDF5 */
#endif
char **dir; /**< Names of the datasets in the file */
};
/** @if mat_devman
* @brief internal structure for MAT variables
* @ingroup mat_internal
* @endif
*/
struct matvar_internal {
#if defined(MAT73) && MAT73
char *hdf5_name; /**< Name */
hobj_ref_t hdf5_ref; /**< Reference */
hid_t id; /**< Id */
#endif
long datapos; /**< Offset from the beginning of the MAT file to the data */
unsigned num_fields; /**< Number of fields */
char **fieldnames; /**< Pointer to fieldnames */
#if defined(HAVE_ZLIB)
z_streamp z; /**< zlib compression state */
void *data; /**< Inflated data array */
#endif
};
/* snprintf.c */
#if !HAVE_VSNPRINTF
int rpl_vsnprintf(char *, size_t, const char *, va_list);
#define mat_vsnprintf rpl_vsnprintf
#else
#define mat_vsnprintf vsnprintf
#endif /* !HAVE_VSNPRINTF */
#if !HAVE_SNPRINTF
int rpl_snprintf(char *, size_t, const char *, ...);
#define mat_snprintf rpl_snprintf
#else
#define mat_snprintf snprintf
#endif /* !HAVE_SNPRINTF */
#if !HAVE_VASPRINTF
int rpl_vasprintf(char **, const char *, va_list);
#define mat_vasprintf rpl_vasprintf
#else
#define mat_vasprintf vasprintf
#endif /* !HAVE_VASPRINTF */
#if !HAVE_ASPRINTF
int rpl_asprintf(char **, const char *, ...);
#define mat_asprintf rpl_asprintf
#else
#define mat_asprintf asprintf
#endif /* !HAVE_ASPRINTF */
/* endian.c */
EXTERN double Mat_doubleSwap(double *a);
EXTERN float Mat_floatSwap(float *a);
#ifdef HAVE_MAT_INT64_T
EXTERN mat_int64_t Mat_int64Swap(mat_int64_t *a);
#endif /* HAVE_MAT_INT64_T */
#ifdef HAVE_MAT_UINT64_T
EXTERN mat_uint64_t Mat_uint64Swap(mat_uint64_t *a);
#endif /* HAVE_MAT_UINT64_T */
EXTERN mat_int32_t Mat_int32Swap(mat_int32_t *a);
EXTERN mat_uint32_t Mat_uint32Swap(mat_uint32_t *a);
EXTERN mat_int16_t Mat_int16Swap(mat_int16_t *a);
EXTERN mat_uint16_t Mat_uint16Swap(mat_uint16_t *a);
/* read_data.c */
EXTERN int ReadDoubleData(mat_t *mat,double *data,enum matio_types data_type,
int len);
EXTERN int ReadSingleData(mat_t *mat,float *data,enum matio_types data_type,
int len);
#ifdef HAVE_MAT_INT64_T
EXTERN int ReadInt64Data (mat_t *mat,mat_int64_t *data,
enum matio_types data_type,int len);
#endif /* HAVE_MAT_INT64_T */
#ifdef HAVE_MAT_UINT64_T
EXTERN int ReadUInt64Data(mat_t *mat,mat_uint64_t *data,
enum matio_types data_type,int len);
#endif /* HAVE_MAT_UINT64_T */
EXTERN int ReadInt32Data (mat_t *mat,mat_int32_t *data,
enum matio_types data_type,int len);
EXTERN int ReadUInt32Data(mat_t *mat,mat_uint32_t *data,
enum matio_types data_type,int len);
EXTERN int ReadInt16Data (mat_t *mat,mat_int16_t *data,
enum matio_types data_type,int len);
EXTERN int ReadUInt16Data(mat_t *mat,mat_uint16_t *data,
enum matio_types data_type,int len);
EXTERN int ReadInt8Data (mat_t *mat,mat_int8_t *data,
enum matio_types data_type,int len);
EXTERN int ReadUInt8Data (mat_t *mat,mat_uint8_t *data,
enum matio_types data_type,int len);
EXTERN int ReadCharData (mat_t *mat,char *data,enum matio_types data_type,
int len);
EXTERN int ReadDataSlab1(mat_t *mat,void *data,enum matio_classes class_type,
enum matio_types data_type,int start,int stride,int edge);
EXTERN int ReadDataSlab2(mat_t *mat,void *data,enum matio_classes class_type,
enum matio_types data_type,size_t *dims,int *start,int *stride,
int *edge);
EXTERN int ReadDataSlabN(mat_t *mat,void *data,enum matio_classes class_type,
enum matio_types data_type,int rank,size_t *dims,int *start,
int *stride,int *edge);
#if defined(HAVE_ZLIB)
EXTERN int ReadCompressedDoubleData(mat_t *mat,z_streamp z,double *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedSingleData(mat_t *mat,z_streamp z,float *data,
enum matio_types data_type,int len);
#ifdef HAVE_MAT_INT64_T
EXTERN int ReadCompressedInt64Data(mat_t *mat,z_streamp z,mat_int64_t *data,
enum matio_types data_type,int len);
#endif /* HAVE_MAT_INT64_T */
#ifdef HAVE_MAT_UINT64_T
EXTERN int ReadCompressedUInt64Data(mat_t *mat,z_streamp z,mat_uint64_t *data,
enum matio_types data_type,int len);
#endif /* HAVE_MAT_UINT64_T */
EXTERN int ReadCompressedInt32Data(mat_t *mat,z_streamp z,mat_int32_t *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedUInt32Data(mat_t *mat,z_streamp z,mat_uint32_t *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedInt16Data(mat_t *mat,z_streamp z,mat_int16_t *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedUInt16Data(mat_t *mat,z_streamp z,mat_uint16_t *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedInt8Data(mat_t *mat,z_streamp z,mat_int8_t *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedUInt8Data(mat_t *mat,z_streamp z,mat_uint8_t *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedCharData(mat_t *mat,z_streamp z,char *data,
enum matio_types data_type,int len);
EXTERN int ReadCompressedDataSlab1(mat_t *mat,z_streamp z,void *data,
enum matio_classes class_type,enum matio_types data_type,
int start,int stride,int edge);
EXTERN int ReadCompressedDataSlab2(mat_t *mat,z_streamp z,void *data,
enum matio_classes class_type,enum matio_types data_type,
size_t *dims,int *start,int *stride,int *edge);
EXTERN int ReadCompressedDataSlabN(mat_t *mat,z_streamp z,void *data,
enum matio_classes class_type,enum matio_types data_type,
int rank,size_t *dims,int *start,int *stride,int *edge);
/* inflate.c */
EXTERN size_t InflateSkip(mat_t *mat, z_streamp z, int nbytes);
EXTERN size_t InflateSkip2(mat_t *mat, matvar_t *matvar, int nbytes);
EXTERN size_t InflateSkipData(mat_t *mat,z_streamp z,enum matio_types data_type,int len);
EXTERN size_t InflateVarTag(mat_t *mat, matvar_t *matvar, void *buf);
EXTERN size_t InflateArrayFlags(mat_t *mat, matvar_t *matvar, void *buf);
EXTERN size_t InflateRankDims(mat_t *mat, matvar_t *matvar, void *buf, size_t nbytes, mat_uint32_t** dims);
EXTERN size_t InflateVarNameTag(mat_t *mat, matvar_t *matvar, void *buf);
EXTERN size_t InflateVarName(mat_t *mat,matvar_t *matvar,void *buf,int N);
EXTERN size_t InflateDataTag(mat_t *mat, matvar_t *matvar, void *buf);
EXTERN size_t InflateDataType(mat_t *mat, z_stream *z, void *buf);
EXTERN size_t InflateData(mat_t *mat, z_streamp z, void *buf, unsigned int nBytes);
EXTERN size_t InflateFieldNameLength(mat_t *mat,matvar_t *matvar,void *buf);
EXTERN size_t InflateFieldNamesTag(mat_t *mat,matvar_t *matvar,void *buf);
EXTERN size_t InflateFieldNames(mat_t *mat,matvar_t *matvar,void *buf,int nfields,
int fieldname_length,int padding);
#endif
/* mat.c */
EXTERN mat_complex_split_t *ComplexMalloc(size_t nbytes);
EXTERN enum matio_types ClassType2DataType(enum matio_classes class_type);
EXTERN int SafeMul(size_t* res, size_t a, size_t b);
EXTERN int SafeMulDims(const matvar_t *matvar, size_t* nelems);
#endif

View file

@ -0,0 +1,178 @@
/*
* Copyright (c) 2010-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MATIO_PUBCONF_H
#define MATIO_PUBCONF_H 1
/* Matio major version number */
#define MATIO_MAJOR_VERSION 1
/* Matio minor version number */
#define MATIO_MINOR_VERSION 5
/* Matio release level number */
#define MATIO_RELEASE_LEVEL 15
/* Matio version number */
#define MATIO_VERSION 1515
/* Matio version string */
#define MATIO_VERSION_STR "1.5.15"
/* Default file format */
#define MAT_FT_DEFAULT MAT_FT_MAT5
/* Define to 1 if you have the <stdint.h> header file. */
#if defined(_MSC_VER) && _MSC_VER >= 1600
#define MATIO_HAVE_STDINT_H 1
#else
#undef MATIO_HAVE_STDINT_H
#endif
/* Define to 1 if you have the <inttypes.h> header file. */
#if defined(_MSC_VER) && _MSC_VER >= 1800
#define MATIO_HAVE_INTTYPES_H 1
#else
#undef MATIO_HAVE_INTTYPES_H
#endif
#if MATIO_HAVE_STDINT_H
/* int16 type */
#define _mat_int16_t int16_t
/* int32 type */
#define _mat_int32_t int32_t
/* int64 type */
#define _mat_int64_t int64_t
/* int8 type */
#define _mat_int8_t int8_t
/* uint16 type */
#define _mat_uint16_t uint16_t
/* uint32 type */
#define _mat_uint32_t uint32_t
/* uint64 type */
#define _mat_uint64_t uint64_t
/* uint8 type */
#define _mat_uint8_t uint8_t
#else
/* int16 type */
#define _mat_int16_t short
/* int32 type */
#define _mat_int32_t int
/* int64 type */
#if defined(_MSC_VER) && _MSC_VER < 1300
#define _mat_int64_t __int64
#else
#define _mat_int64_t long long
#endif
/* int8 type */
#define _mat_int8_t signed char
/* uint16 type */
#define _mat_uint16_t unsigned short
/* uint32 type */
#define _mat_uint32_t unsigned
/* uint64 type */
#if defined(_MSC_VER) && _MSC_VER < 1300
#define _mat_uint64_t unsigned __int64
#else
#define _mat_uint64_t unsigned long long
#endif
/* uint8 type */
#define _mat_uint8_t unsigned char
#endif
#if MATIO_HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#if MATIO_HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef _mat_int64_t
typedef _mat_int64_t mat_int64_t;
#endif
#ifdef _mat_uint64_t
typedef _mat_uint64_t mat_uint64_t;
#endif
#ifdef _mat_int32_t
typedef _mat_int32_t mat_int32_t;
#endif
#ifdef _mat_uint32_t
typedef _mat_uint32_t mat_uint32_t;
#endif
#ifdef _mat_int16_t
typedef _mat_int16_t mat_int16_t;
#endif
#ifdef _mat_uint16_t
typedef _mat_uint16_t mat_uint16_t;
#endif
#ifdef _mat_int8_t
typedef _mat_int8_t mat_int8_t;
#endif
#ifdef _mat_uint8_t
typedef _mat_uint8_t mat_uint8_t;
#endif
/*
The following macros handle noreturn attributes according to the latest
C11/C++11 standard with fallback to the MSVC extension if using an older
compiler.
*/
#define MATIO_NORETURNATTR
#if __STDC_VERSION__ >= 201112L
#define MATIO_NORETURN _Noreturn
#elif __cplusplus >= 201103L
#define MATIO_NORETURN [[noreturn]]
#elif defined(_MSC_VER) && _MSC_VER >= 1200
#define MATIO_NORETURN __declspec(noreturn)
#else
#define MATIO_NORETURN
#endif
/*
The following macros handle format attributes for type-checks against a
format string.
*/
#define MATIO_FORMATATTR_PRINTF1
#define MATIO_FORMATATTR_PRINTF2
#define MATIO_FORMATATTR_VPRINTF
#endif /* MATIO_PUBCONF_H */

View file

@ -0,0 +1,182 @@
/*
* Copyright (c) 2010-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MATIO_PUBCONF_H
#define MATIO_PUBCONF_H 1
/* Matio major version number */
#undef MATIO_MAJOR_VERSION
/* Matio minor version number */
#undef MATIO_MINOR_VERSION
/* Matio release level number */
#undef MATIO_RELEASE_LEVEL
/* Matio version number */
#undef MATIO_VERSION
/* Matio version string */
#undef MATIO_VERSION_STR
/* Default file format */
#undef MAT_FT_DEFAULT
/* Define to 1 if you have the <stdint.h> header file. */
#undef MATIO_HAVE_STDINT_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef MATIO_HAVE_INTTYPES_H
/* int16 type */
#undef _mat_int16_t
/* int32 type */
#undef _mat_int32_t
/* int64 type */
#undef _mat_int64_t
/* int8 type */
#undef _mat_int8_t
/* uint16 type */
#undef _mat_uint16_t
/* uint32 type */
#undef _mat_uint32_t
/* uint64 type */
#undef _mat_uint64_t
/* uint8 type */
#undef _mat_uint8_t
#if MATIO_HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#if MATIO_HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef _mat_int64_t
typedef _mat_int64_t mat_int64_t;
#endif
#ifdef _mat_uint64_t
typedef _mat_uint64_t mat_uint64_t;
#endif
#ifdef _mat_int32_t
typedef _mat_int32_t mat_int32_t;
#endif
#ifdef _mat_uint32_t
typedef _mat_uint32_t mat_uint32_t;
#endif
#ifdef _mat_int16_t
typedef _mat_int16_t mat_int16_t;
#endif
#ifdef _mat_uint16_t
typedef _mat_uint16_t mat_uint16_t;
#endif
#ifdef _mat_int8_t
typedef _mat_int8_t mat_int8_t;
#endif
#ifdef _mat_uint8_t
typedef _mat_uint8_t mat_uint8_t;
#endif
/*
The following macros handle noreturn attributes according to the latest
C11/C++11 standard with fallback to GNU, Clang or MSVC extensions if using
an older compiler.
*/
#if __STDC_VERSION__ >= 201112L
#define MATIO_NORETURN _Noreturn
#define MATIO_NORETURNATTR
#elif __cplusplus >= 201103L
#if (defined(__GNUC__) && __GNUC__ >= 5) || \
(defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 4 && __GNUC_MINOR__ >= 8)
#define MATIO_NORETURN [[noreturn]]
#define MATIO_NORETURNATTR
#elif (defined(__GNUC__) && __GNUC__ >= 3) || \
(defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 2 && __GNUC_MINOR__ >= 8)
#define MATIO_NORETURN
#define MATIO_NORETURNATTR __attribute__((noreturn))
#elif defined(__GNUC__)
#define MATIO_NORETURN
#define MATIO_NORETURNATTR
#else
#define MATIO_NORETURN [[noreturn]]
#define MATIO_NORETURNATTR
#endif
#elif defined(__clang__)
#if __has_attribute(noreturn)
#define MATIO_NORETURN
#define MATIO_NORETURNATTR __attribute__((noreturn))
#else
#define MATIO_NORETURN
#define MATIO_NORETURNATTR
#endif
#elif (defined(__GNUC__) && __GNUC__ >= 3) || \
(defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ == 2 && __GNUC_MINOR__ >= 8) || \
(defined(__SUNPRO_C) && __SUNPRO_C >= 0x5110)
#define MATIO_NORETURN
#define MATIO_NORETURNATTR __attribute__((noreturn))
#elif (defined(_MSC_VER) && _MSC_VER >= 1200) || \
defined(__BORLANDC__)
#define MATIO_NORETURN __declspec(noreturn)
#define MATIO_NORETURNATTR
#else
#define MATIO_NORETURN
#define MATIO_NORETURNATTR
#endif
/*
The following macros handle format attributes for type-checks against a
format string.
*/
#if defined(__GNUC__) && __GNUC__ >= 3
#define MATIO_FORMATATTR_PRINTF1 __attribute__((format(printf, 1, 2)))
#define MATIO_FORMATATTR_PRINTF2 __attribute__((format(printf, 2, 3)))
#define MATIO_FORMATATTR_VPRINTF __attribute__((format(printf, 1, 0)))
#elif defined(__clang__)
#if __has_attribute(format)
#define MATIO_FORMATATTR_PRINTF1 __attribute__((format(printf, 1, 2)))
#define MATIO_FORMATATTR_PRINTF2 __attribute__((format(printf, 2, 3)))
#define MATIO_FORMATATTR_VPRINTF __attribute__((format(printf, 1, 0)))
#else
#define MATIO_FORMATATTR_PRINTF1
#define MATIO_FORMATATTR_PRINTF2
#define MATIO_FORMATATTR_VPRINTF
#endif
#else
#define MATIO_FORMATATTR_PRINTF1
#define MATIO_FORMATATTR_PRINTF2
#define MATIO_FORMATATTR_VPRINTF
#endif
#endif /* MATIO_PUBCONF_H */

View file

@ -0,0 +1,183 @@
/*
* Copyright (c) 2012-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#include "matio_private.h"
/** @brief Returns a pointer to the Cell array at a specific index
*
* Returns a pointer to the Cell Array Field at the given 1-relative index.
* MAT file must be a version 5 matlab file.
* @ingroup MAT
* @param matvar Pointer to the Cell Array MAT variable
* @param index linear index of cell to return
* @return Pointer to the Cell Array Field on success, NULL on error
*/
matvar_t *
Mat_VarGetCell(matvar_t *matvar,int index)
{
size_t nelems = 1;
matvar_t *cell = NULL;
if ( matvar == NULL )
return NULL;
SafeMulDims(matvar, &nelems);
if ( 0 <= index && index < nelems )
cell = *((matvar_t **)matvar->data + index);
return cell;
}
/** @brief Indexes a cell array
*
* Finds cells of a cell array given a start, stride, and edge for each.
* dimension. The cells are placed in a pointer array. The cells should not
* be freed, but the array of pointers should be. If copies are needed,
* use Mat_VarDuplicate on each cell.
*
* Note that this function is limited to structure arrays with a rank less than
* 10.
*
* @ingroup MAT
* @param matvar Cell Array matlab variable
* @param start vector of length rank with 0-relative starting coordinates for
* each dimension.
* @param stride vector of length rank with strides for each dimension.
* @param edge vector of length rank with the number of elements to read in
* each dimension.
* @returns an array of pointers to the cells
*/
matvar_t **
Mat_VarGetCells(matvar_t *matvar,int *start,int *stride,int *edge)
{
int i, j, N, I;
size_t idx[10] = {0,}, cnt[10] = {0,}, dimp[10] = {0,};
matvar_t **cells;
if ( (matvar == NULL) || (start == NULL) || (stride == NULL) ||
(edge == NULL) ) {
return NULL;
} else if ( matvar->rank > 9 ) {
return NULL;
}
dimp[0] = matvar->dims[0];
N = edge[0];
I = start[0];
idx[0] = start[0];
for ( i = 1; i < matvar->rank; i++ ) {
idx[i] = start[i];
dimp[i] = dimp[i-1]*matvar->dims[i];
N *= edge[i];
I += start[i]*dimp[i-1];
}
cells = (matvar_t**)malloc(N*sizeof(matvar_t *));
for ( i = 0; i < N; i+=edge[0] ) {
for ( j = 0; j < edge[0]; j++ ) {
cells[i+j] = *((matvar_t **)matvar->data + I);
I += stride[0];
}
idx[0] = start[0];
I = idx[0];
cnt[1]++;
idx[1] += stride[1];
for ( j = 1; j < matvar->rank; j++ ) {
if ( cnt[j] == edge[j] ) {
cnt[j] = 0;
idx[j] = start[j];
if ( j < matvar->rank - 1 ) {
cnt[j+1]++;
idx[j+1] += stride[j+1];
}
}
I += idx[j]*dimp[j-1];
}
}
return cells;
}
/** @brief Indexes a cell array
*
* Finds cells of a cell array given a linear indexed start, stride, and edge.
* The cells are placed in a pointer array. The cells themself should not
* be freed as they are part of the original cell array, but the pointer array
* should be. If copies are needed, use Mat_VarDuplicate on each of the cells.
* MAT file version must be 5.
* @ingroup MAT
* @param matvar Cell Array matlab variable
* @param start starting index
* @param stride stride
* @param edge Number of cells to get
* @returns an array of pointers to the cells
*/
matvar_t **
Mat_VarGetCellsLinear(matvar_t *matvar,int start,int stride,int edge)
{
matvar_t **cells = NULL;
if ( matvar != NULL ) {
int i, I;
cells = (matvar_t**)malloc(edge*sizeof(matvar_t *));
I = start;
for ( i = 0; i < edge; i++ ) {
cells[i] = *((matvar_t **)matvar->data + I);
I += stride;
}
}
return cells;
}
/** @brief Sets the element of the cell array at the specific index
*
* Sets the element of the cell array at the given 0-relative index to @c cell.
* @ingroup MAT
* @param matvar Pointer to the cell array variable
* @param index 0-relative linear index of the cell to set
* @param cell Pointer to the cell to set
* @return Pointer to the previous cell element, or NULL if there was no
* previous cell element or error.
*/
matvar_t *
Mat_VarSetCell(matvar_t *matvar,int index,matvar_t *cell)
{
size_t nelems = 1;
matvar_t **cells, *old_cell = NULL;
if ( matvar == NULL || matvar->rank < 1 )
return NULL;
SafeMulDims(matvar, &nelems);
cells = (matvar_t**)matvar->data;
if ( 0 <= index && index < nelems ) {
old_cell = cells[index];
cells[index] = cell;
}
return old_cell;
}

View file

@ -0,0 +1,555 @@
/*
* Copyright (c) 2012-2019, Christopher C. Hulbert
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdlib.h>
#include <string.h>
#if defined(_MSC_VER) || defined(__MINGW32__)
# define strdup _strdup
#endif
#include "matio_private.h"
/** @brief Creates a structure MATLAB variable with the given name and fields
*
* @ingroup MAT
* @param name Name of the structure variable to create
* @param rank Rank of the variable
* @param dims array of dimensions of the variable of size rank
* @param fields Array of @c nfields fieldnames
* @param nfields Number of fields in the structure
* @return Pointer to the new structure MATLAB variable on success, NULL on error
*/
matvar_t *
Mat_VarCreateStruct(const char *name,int rank,size_t *dims,const char **fields,
unsigned nfields)
{
size_t nelems = 1;
int j;
matvar_t *matvar;
if ( NULL == dims )
return NULL;
matvar = Mat_VarCalloc();
if ( NULL == matvar )
return NULL;
matvar->compression = MAT_COMPRESSION_NONE;
if ( NULL != name )
matvar->name = strdup(name);
matvar->rank = rank;
matvar->dims = (size_t*)malloc(matvar->rank*sizeof(*matvar->dims));
for ( j = 0; j < matvar->rank; j++ ) {
matvar->dims[j] = dims[j];
nelems *= dims[j];
}
matvar->class_type = MAT_C_STRUCT;
matvar->data_type = MAT_T_STRUCT;
matvar->data_size = sizeof(matvar_t *);
if ( nfields ) {
matvar->internal->num_fields = nfields;
matvar->internal->fieldnames =
(char**)malloc(nfields*sizeof(*matvar->internal->fieldnames));
if ( NULL == matvar->internal->fieldnames ) {
Mat_VarFree(matvar);
matvar = NULL;
} else {
size_t i;
for ( i = 0; i < nfields; i++ ) {
if ( NULL == fields[i] ) {
Mat_VarFree(matvar);
matvar = NULL;
break;
} else {
matvar->internal->fieldnames[i] = strdup(fields[i]);
}
}
}
if ( NULL != matvar && nelems > 0 ) {
size_t nelems_x_nfields;
SafeMul(&nelems_x_nfields, nelems, nfields);
SafeMul(&matvar->nbytes, nelems_x_nfields, matvar->data_size);
matvar->data = calloc(nelems_x_nfields, matvar->data_size);
}
}
return matvar;
}
/** @brief Adds a field to a structure
*
* Adds the given field to the structure. fields should be an array of matvar_t
* pointers of the same size as the structure (i.e. 1 field per structure
* element).
* @ingroup MAT
* @param matvar Pointer to the Structure MAT variable
* @param fieldname Name of field to be added
* @retval 0 on success
*/
int
Mat_VarAddStructField(matvar_t *matvar,const char *fieldname)
{
int cnt = 0;
size_t i, nfields, nelems = 1;
matvar_t **new_data, **old_data;
char **fieldnames;
if ( matvar == NULL || fieldname == NULL )
return -1;
SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields+1;
matvar->internal->num_fields = nfields;
fieldnames = (char**)realloc(matvar->internal->fieldnames,
nfields*sizeof(*matvar->internal->fieldnames));
if ( NULL == fieldnames )
return -1;
matvar->internal->fieldnames = fieldnames;
matvar->internal->fieldnames[nfields-1] = strdup(fieldname);
{
size_t nelems_x_nfields;
SafeMul(&nelems_x_nfields, nelems, nfields);
SafeMul(&matvar->nbytes, nelems_x_nfields, sizeof(*new_data));
}
new_data = (matvar_t**)malloc(matvar->nbytes);
if ( new_data == NULL ) {
matvar->nbytes = 0;
return -1;
}
old_data = (matvar_t**)matvar->data;
for ( i = 0; i < nelems; i++ ) {
size_t f;
for ( f = 0; f < nfields-1; f++ )
new_data[cnt++] = old_data[i*(nfields-1)+f];
new_data[cnt++] = NULL;
}
free(matvar->data);
matvar->data = new_data;
return 0;
}
/** @brief Returns the number of fields in a structure variable
*
* Returns the number of fields in the given structure.
* @ingroup MAT
* @param matvar Structure matlab variable
* @returns Number of fields
*/
unsigned
Mat_VarGetNumberOfFields(matvar_t *matvar)
{
int nfields;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
NULL == matvar->internal ) {
nfields = 0;
} else {
nfields = matvar->internal->num_fields;
}
return nfields;
}
/** @brief Returns the fieldnames of a structure variable
*
* Returns the fieldnames for the given structure. The returned pointers are
* internal to the structure and should not be free'd.
* @ingroup MAT
* @param matvar Structure matlab variable
* @returns Array of fieldnames
*/
char * const *
Mat_VarGetStructFieldnames(const matvar_t *matvar)
{
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
NULL == matvar->internal ) {
return NULL;
} else {
return matvar->internal->fieldnames;
}
}
/** @brief Finds a field of a structure by the field's index
*
* Returns a pointer to the structure field at the given 0-relative index.
* @ingroup MAT
* @param matvar Pointer to the Structure MAT variable
* @param field_index 0-relative index of the field.
* @param index linear index of the structure array
* @return Pointer to the structure field on success, NULL on error
*/
matvar_t *
Mat_VarGetStructFieldByIndex(matvar_t *matvar,size_t field_index,size_t index)
{
matvar_t *field = NULL;
size_t nelems = 1, nfields;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data_size == 0 )
return field;
SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
if ( nelems > 0 && index >= nelems ) {
Mat_Critical("Mat_VarGetStructField: structure index out of bounds");
} else if ( nfields > 0 ) {
if ( field_index > nfields ) {
Mat_Critical("Mat_VarGetStructField: field index out of bounds");
} else {
field = *((matvar_t **)matvar->data+index*nfields+field_index);
}
}
return field;
}
/** @brief Finds a field of a structure by the field's name
*
* Returns a pointer to the structure field at the given 0-relative index.
* @ingroup MAT
* @param matvar Pointer to the Structure MAT variable
* @param field_name Name of the structure field
* @param index linear index of the structure array
* @return Pointer to the structure field on success, NULL on error
*/
matvar_t *
Mat_VarGetStructFieldByName(matvar_t *matvar,const char *field_name,
size_t index)
{
int i, nfields, field_index;
matvar_t *field = NULL;
size_t nelems = 1;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data_size == 0 )
return field;
SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
field_index = -1;
for ( i = 0; i < nfields; i++ ) {
if ( !strcmp(matvar->internal->fieldnames[i],field_name) ) {
field_index = i;
break;
}
}
if ( index >= nelems ) {
Mat_Critical("Mat_VarGetStructField: structure index out of bounds");
} else if ( field_index >= 0 ) {
field = *((matvar_t **)matvar->data+index*nfields+field_index);
}
return field;
}
/** @brief Finds a field of a structure
*
* Returns a pointer to the structure field at the given 0-relative index.
* @ingroup MAT
* @param matvar Pointer to the Structure MAT variable
* @param name_or_index Name of the field, or the 1-relative index of the field
* If the index is used, it should be the address of an integer variable whose
* value is the index number.
* @param opt MAT_BY_NAME if the name_or_index is the name or MAT_BY_INDEX if
* the index was passed.
* @param index linear index of the structure to find the field of
* @return Pointer to the Structure Field on success, NULL on error
*/
matvar_t *
Mat_VarGetStructField(matvar_t *matvar,void *name_or_index,int opt,int index)
{
int err = 0, nfields;
matvar_t *field = NULL;
size_t nelems = 1;
SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
if ( index < 0 || (nelems > 0 && index >= nelems ))
err = 1;
else if ( nfields < 1 )
err = 1;
if ( !err && (opt == MAT_BY_INDEX) ) {
size_t field_index = *(int *)name_or_index;
if ( field_index > 0 )
field = Mat_VarGetStructFieldByIndex(matvar,field_index-1,index);
} else if ( !err && (opt == MAT_BY_NAME) ) {
field = Mat_VarGetStructFieldByName(matvar,(const char*)name_or_index,index);
}
return field;
}
/** @brief Indexes a structure
*
* Finds structures of a structure array given a start, stride, and edge for
* each dimension. The structures are placed in a new structure array. If
* copy_fields is non-zero, the indexed structures are copied and should be
* freed, but if copy_fields is zero, the indexed structures are pointers to
* the original, but should still be freed. The structures have a flag set
* so that the structure fields are not freed.
*
* Note that this function is limited to structure arrays with a rank less than
* 10.
*
* @ingroup MAT
* @param matvar Structure matlab variable
* @param start vector of length rank with 0-relative starting coordinates for
* each dimension.
* @param stride vector of length rank with strides for each dimension.
* @param edge vector of length rank with the number of elements to read in
* each dimension.
* @param copy_fields 1 to copy the fields, 0 to just set pointers to them.
* @returns A new structure array with fields indexed from @c matvar.
*/
matvar_t *
Mat_VarGetStructs(matvar_t *matvar,int *start,int *stride,int *edge,
int copy_fields)
{
size_t i,N,I,nfields,field,idx[10] = {0,},cnt[10] = {0,},dimp[10] = {0,};
matvar_t **fields, *struct_slab;
int j;
if ( (matvar == NULL) || (start == NULL) || (stride == NULL) ||
(edge == NULL) ) {
return NULL;
} else if ( matvar->rank > 9 ) {
return NULL;
} else if ( matvar->class_type != MAT_C_STRUCT ) {
return NULL;
}
struct_slab = Mat_VarDuplicate(matvar,0);
if ( !copy_fields )
struct_slab->mem_conserve = 1;
nfields = matvar->internal->num_fields;
dimp[0] = matvar->dims[0];
N = edge[0];
I = start[0];
struct_slab->dims[0] = edge[0];
idx[0] = start[0];
for ( j = 1; j < matvar->rank; j++ ) {
idx[j] = start[j];
dimp[j] = dimp[j-1]*matvar->dims[j];
N *= edge[j];
I += start[j]*dimp[j-1];
struct_slab->dims[j] = edge[j];
}
I *= nfields;
struct_slab->nbytes = N*nfields*sizeof(matvar_t *);
struct_slab->data = malloc(struct_slab->nbytes);
if ( struct_slab->data == NULL ) {
Mat_VarFree(struct_slab);
return NULL;
}
fields = (matvar_t**)struct_slab->data;
for ( i = 0; i < N; i+=edge[0] ) {
for ( j = 0; j < edge[0]; j++ ) {
for ( field = 0; field < nfields; field++ ) {
if ( copy_fields )
fields[(i+j)*nfields+field] =
Mat_VarDuplicate(*((matvar_t **)matvar->data + I),1);
else
fields[(i+j)*nfields+field] =
*((matvar_t **)matvar->data + I);
I++;
}
I += (stride[0]-1)*nfields;
}
idx[0] = start[0];
I = idx[0];
cnt[1]++;
idx[1] += stride[1];
for ( j = 1; j < matvar->rank; j++ ) {
if ( cnt[j] == edge[j] ) {
cnt[j] = 0;
idx[j] = start[j];
if ( j < matvar->rank - 1 ) {
cnt[j+1]++;
idx[j+1] += stride[j+1];
}
}
I += idx[j]*dimp[j-1];
}
I *= nfields;
}
return struct_slab;
}
/** @brief Indexes a structure
*
* Finds structures of a structure array given a single (linear)start, stride,
* and edge. The structures are placed in a new structure array. If
* copy_fields is non-zero, the indexed structures are copied and should be
* freed, but if copy_fields is zero, the indexed structures are pointers to
* the original, but should still be freed since the mem_conserve flag is set
* so that the structures are not freed.
* MAT file version must be 5.
* @ingroup MAT
* @param matvar Structure matlab variable
* @param start starting index (0-relative)
* @param stride stride (1 reads consecutive elements)
* @param edge Number of elements to read
* @param copy_fields 1 to copy the fields, 0 to just set pointers to them.
* @returns A new structure with fields indexed from matvar
*/
matvar_t *
Mat_VarGetStructsLinear(matvar_t *matvar,int start,int stride,int edge,
int copy_fields)
{
matvar_t *struct_slab;
if ( matvar == NULL || matvar->rank > 10 ) {
struct_slab = NULL;
} else {
int i, I, field, nfields;
matvar_t **fields;
struct_slab = Mat_VarDuplicate(matvar,0);
if ( !copy_fields )
struct_slab->mem_conserve = 1;
nfields = matvar->internal->num_fields;
struct_slab->nbytes = (size_t)edge*nfields*sizeof(matvar_t *);
struct_slab->data = malloc(struct_slab->nbytes);
if ( struct_slab->data == NULL ) {
Mat_VarFree(struct_slab);
return NULL;
}
struct_slab->dims[0] = edge;
struct_slab->dims[1] = 1;
fields = (matvar_t**)struct_slab->data;
I = start*nfields;
for ( i = 0; i < edge; i++ ) {
if ( copy_fields ) {
for ( field = 0; field < nfields; field++ ) {
fields[i*nfields+field] =
Mat_VarDuplicate(*((matvar_t **)matvar->data+I),1);
I++;
}
} else {
for ( field = 0; field < nfields; field++ ) {
fields[i*nfields+field] = *((matvar_t **)matvar->data + I);
I++;
}
}
I += (stride-1)*nfields;
}
}
return struct_slab;
}
/** @brief Sets the structure field to the given variable
*
* Sets the structure field specified by the 0-relative field index
* @c field_index for the given 0-relative structure index @c index to
* @c field.
* @ingroup MAT
* @param matvar Pointer to the structure MAT variable
* @param field_index 0-relative index of the field.
* @param index linear index of the structure array
* @param field New field variable
* @return Pointer to the previous field (NULL if no previous field)
*/
matvar_t *
Mat_VarSetStructFieldByIndex(matvar_t *matvar,size_t field_index,size_t index,
matvar_t *field)
{
matvar_t *old_field = NULL;
size_t nelems = 1, nfields;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data == NULL )
return old_field;
SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
if ( index < nelems && field_index < nfields ) {
matvar_t **fields = (matvar_t**)matvar->data;
old_field = fields[index*nfields+field_index];
fields[index*nfields+field_index] = field;
if ( NULL != field->name ) {
free(field->name);
}
field->name = strdup(matvar->internal->fieldnames[field_index]);
}
return old_field;
}
/** @brief Sets the structure field to the given variable
*
* Sets the specified structure fieldname at the given 0-relative @c index to
* @c field.
* @ingroup MAT
* @param matvar Pointer to the Structure MAT variable
* @param field_name Name of the structure field
* @param index linear index of the structure array
* @param field New field variable
* @return Pointer to the previous field (NULL if no previous field)
*/
matvar_t *
Mat_VarSetStructFieldByName(matvar_t *matvar,const char *field_name,
size_t index,matvar_t *field)
{
int i, nfields, field_index;
matvar_t *old_field = NULL;
size_t nelems = 1;
if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT ||
matvar->data == NULL )
return old_field;
SafeMulDims(matvar, &nelems);
nfields = matvar->internal->num_fields;
field_index = -1;
for ( i = 0; i < nfields; i++ ) {
if ( !strcmp(matvar->internal->fieldnames[i],field_name) ) {
field_index = i;
break;
}
}
if ( index < nelems && field_index >= 0 ) {
matvar_t **fields = (matvar_t**)matvar->data;
old_field = fields[index*nfields+field_index];
fields[index*nfields+field_index] = field;
if ( NULL != field->name ) {
free(field->name);
}
field->name = strdup(matvar->internal->fieldnames[field_index]);
}
return old_field;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,64 @@
#include <Core/Core.h>
using namespace Upp;
#include "matio.h"
#include "lib/matioConfig.h"
MatFile::MatStatic MatFile::cons;
MatVar::~MatVar() {
if (var != NULL)
Mat_VarFree(var);
}
MatVar::MatVar(mat_t *mat, String name) {
ASSERT(mat != NULL);
var = Mat_VarReadInfo(mat, name);
if (var == NULL)
return;
}
const char* MatVar::GetTypeString() {
ASSERT(var != NULL);
const char *class_type_desc[18] = {"Undefined","Cell Array","Structure",
"Object","Character Array","Sparse Array","Double Precision Array",
"Single Precision Array", "8-bit, signed integer array",
"8-bit, unsigned integer array","16-bit, signed integer array",
"16-bit, unsigned integer array","32-bit, signed integer array",
"32-bit, unsigned integer array","64-bit, signed integer array",
"64-bit, unsigned integer array","Function","Opaque"};
return class_type_desc[var->class_type];
}
int MatVar::GetCount() {
ASSERT(var != NULL);
int ret = GetDimCount(0);
for (int i = 1; i < GetDimCount(); ++i)
ret *= GetDimCount(i);
return ret;
}
MatFile::~MatFile() {
if (mat != NULL)
Mat_Close(mat);
}
bool MatFile::Create(String fileName, mat_ft version) {
if (mat != NULL)
Mat_Close(mat);
time_t t = time(NULL);
String header = Format("MATLAB 5.0 MAT-file, Platform: %s, "
"Created by: libmatio v%d.%d.%d on %s. U++ wrapper Bazaar/plugin/matio <https://www.ultimatepp.org/>", MATIO_PLATFORM,
MATIO_MAJOR_VERSION, MATIO_MINOR_VERSION, MATIO_RELEASE_LEVEL,
ctime(&t));
mat = Mat_CreateVer(fileName, header, version);
return !!mat;
}

259
bazaar/plugin/matio/matio.h Normal file
View file

@ -0,0 +1,259 @@
#ifndef _plugin_matio_matio_h_
#define _plugin_matio_matio_h_
#include "./lib/matio.h"
template <class T>
class MatMatrix {
public:
MatMatrix() : rows(0), cols(0) {}
void Alloc(int size) {
data.Alloc(size);
this->rows = size;
this->cols = 1;
}
void Alloc(int rows, int cols) {
data.Alloc(rows*cols);
this->rows = rows;
this->cols = cols;
}
void Clear() {data.Clear();}
T &operator()(int r) {return data[r];}
T &operator()(int r, int c) {return data[c*rows + r];}
const T &operator()(int r) const {return data[r];}
const T &operator()(int r, int c) const {return data[c*rows + r];}
operator T*() { return data; }
operator const T*() const { return data; }
int GetCount() {return rows*cols;}
int GetRows() {return rows;}
int GetCols() {return cols;}
private:
Buffer<T> data;
int rows, cols;
};
class MatVar {
public:
MatVar() : var(NULL) {}
~MatVar();
MatVar(mat_t *mat, String name);
const char *GetName() {ASSERT(var != NULL); return var->name;}
enum matio_types GetType() {ASSERT(var != NULL); return var->data_type;}
const char* GetTypeString();
int GetDimCount() {ASSERT(var != NULL); return var->rank;}
int GetDimCount(int dim) {ASSERT(var != NULL); return (int)var->dims[dim];}
int GetCount();
private:
matvar_t *var;
friend class MatFile;
};
class MatFile {
public:
MatFile() : mat(NULL), listVar(NULL), numVar(0) {}
~MatFile();
bool Create(String fileName, mat_ft version = MAT_FT_MAT5);
bool OpenRead(String fileName) {return Open(fileName, MAT_ACC_RDONLY);}
bool OpenWrite(String fileName) {return Open(fileName, MAT_ACC_RDWR);}
bool IsOpen() {return !!mat;}
mat_ft GetVersion() {
ASSERT(mat != NULL);
return Mat_GetVersion(mat);
}
String GetVersionName() {
mat_ft ver = GetVersion();
switch (ver) {
case MAT_FT_MAT4: return "4";
case MAT_FT_MAT5: return "5";
case MAT_FT_MAT73: return "7.3";
case MAT_FT_UNDEFINED: return "unknown";
}
return "unknown";
}
int GetVarCount() {
GetVarList();
return (int)numVar;
}
String GetVarName(int id) {
GetVarList();
if (listVar == NULL)
return Null;
if (id >= (int)numVar)
return Null;
return listVar[id];
}
bool VarExists(String name) {
GetVarList();
if (listVar == NULL)
return false;
for (int i = 0; i < (int)numVar; ++i) {
if (listVar[i] == name)
return true;
}
return false;
}
bool VarDelete(String name) {
ASSERT(mat != NULL);
return 0 == Mat_VarDelete(mat, name);
}
MatVar GetVar(String name) {return MatVar(mat, name);}
template <class T>
MatMatrix<T> VarRead(MatVar &var) {
ASSERT(mat != NULL);
MatMatrix<T> ret;
int numDim = var.GetDimCount();
if (numDim > 2)
return ret;
Buffer<int> start(numDim, 0);
Buffer<int> stride(numDim, 1);
Buffer<int> edge(numDim);
for (int i = 0; i < numDim; ++i)
edge[i] = var.GetDimCount(i);
ret.Alloc((int)var.GetDimCount(0), (int)var.GetDimCount(1));
if (0 != Mat_VarReadData(mat, var.var, ret, start, stride, edge)) {
ret.Clear();
return ret;
}
return ret;
}
template <class T>
MatMatrix<T> VarRead(String name) {
MatVar var = GetVar(name);
return VarRead<T>(var);
}
template<class T> void inline GetTypeCode(enum matio_classes &class_type, enum matio_types &data_type) const {
NEVER_("Unsupported type in matio");
}
template <class T>
bool VarWrite(String name, MatMatrix<T> &data, bool compression = true) {
Buffer<size_t> dims(2);
dims[0] = data.GetRows();
dims[1] = data.GetCols();
enum matio_classes class_type;
enum matio_types data_type;
GetTypeCode<T>(class_type, data_type);
if (VarExists(name))
if (0 != Mat_VarDelete(mat, name))
return false;
matvar_t *var = Mat_VarCreate(name, class_type, data_type, 2, dims, data, MAT_F_DONT_COPY_DATA);
if (var == NULL)
return false;
if (0 != Mat_VarWrite(mat, var, MAT_COMPRESSION_NONE))
return false;
return true;
}
template <class T>
bool VarWrite(String name, T data, bool compression = true) {
Buffer<size_t> dims(1);
dims[0] = 1;
enum matio_classes class_type;
enum matio_types data_type;
GetTypeCode<T>(class_type, data_type);
if (VarExists(name))
Mat_VarDelete(mat, name);
matvar_t *var = Mat_VarCreate(name, class_type, data_type, 1, dims, &data, MAT_F_DONT_COPY_DATA);
if (var == NULL)
return false;
if (0 != Mat_VarWrite(mat, var, MAT_COMPRESSION_NONE))
return false;
return true;
}
static String GetLastError() {return cons.lastError;}
struct MatStatic {
MatStatic() {
Mat_LogInitFunc("Matio", LogFunc);
}
int logLevel;
String lastError;
};
private:
mat_t *mat;
char **listVar;
size_t numVar;
bool Open(String fileName, int mode) {
if (mat != NULL)
Mat_Close(mat);
mat = Mat_Open(fileName, mode);
return !!mat;
}
void GetVarList() {
ASSERT(mat != NULL);
if (listVar == NULL) {
numVar = 0;
listVar = Mat_GetDir(mat, &numVar);
}
}
static MatStatic cons;
static void LogFunc(int log_level, char *message) {
cons.logLevel = log_level;
cons.lastError = message;
}
};
template<> void inline MatFile::GetTypeCode<double> (enum matio_classes &class_type, enum matio_types &data_type) const {
class_type = MAT_C_DOUBLE;
data_type = MAT_T_DOUBLE;
}
template<> void inline MatFile::GetTypeCode<float> (enum matio_classes &class_type, enum matio_types &data_type) const {
class_type = MAT_C_SINGLE;
data_type = MAT_T_SINGLE;
}
template<> void inline MatFile::GetTypeCode<int> (enum matio_classes &class_type, enum matio_types &data_type) const {
class_type = MAT_C_INT64;
data_type = MAT_T_INT64;
}
#endif

View file

@ -0,0 +1,32 @@
topic "Tutorial";
[l288;i1120;a17;O9;~~~.1408;2 $$1,0#10431211400427159095818037425705:param]
[a83;*R6 $$2,5#31310162474203024125188417583966:caption]
[H4;b83;*4 $$3,5#07864147445237544204411237157677:title]
[i288;O9;C2 $$4,6#40027414424643823182269349404212:item]
[b42;a42;2 $$5,5#45413000475342174754091244180557:text]
[l288;b17;a17;2 $$6,6#27521748481378242620020725143825:desc]
[l321;C@5;1 $$7,7#20902679421464641399138805415013:code]
[b2503;2 $$8,0#65142375456100023862071332075487:separator]
[*@(0.0.255)2 $$9,0#83433469410354161042741608181528:base]
[C2 $$10,0#37138531426314131251341829483380:class]
[l288;a17;*1 $$11,11#70004532496200323422659154056402:requirement]
[i417;b42;a42;O9;~~~.416;2 $$12,12#10566046415157235020018451313112:tparam]
[b167;C2 $$13,13#92430459443460461911108080531343:item1]
[i288;a42;O9;C2 $$14,14#77422149456609303542238260500223:item2]
[*@2$(0.128.128)2 $$15,15#34511555403152284025741354420178:NewsDate]
[l321;*C$7;2 $$16,16#03451589433145915344929335295360:result]
[l321;b83;a83;*C$7;2 $$17,17#07531550463529505371228428965313:result`-line]
[l160;*C+117 $$18,5#88603949442205825958800053222425:package`-title]
[2 $$19,0#53580023442335529039900623488521:gap]
[C2 $$20,20#70211524482531209251820423858195:class`-nested]
[b50;2 $$21,21#03324558446220344731010354752573:Par]
[2 $$0,0#00000000000000000000000000000000:Default]
[{_}%EN-US
[s2; [+184 MatIO]&]
[s2; [*A^https`:`/`/github`.com`/tbeu`/matio^2 Matio ][*A2 is an open`-source
C library for reading and writing binary ][*A^https`:`/`/www`.mathworks`.com`/products`/matlab`.html^2 M
ATLAB ][*A2 MAT files. This library is designed for use by programs/libraries
that do not have access or do not want to rely on MATLAB`'s shared
libraries.]&]
[s0; Matio U`+`+ wrapper is a basic C`+`+ wrapper for Matio.&]
[s0; A simple sample is included in Bazaar/MatIO`_demo package.]]

View file

@ -0,0 +1,34 @@
description "MATLAB MAT file I/O library\3770,128,128";
uses
Core;
options
-DHAVE_ZLIB;
file
matio.cpp,
matio.h,
matio.tpp,
lib\mat.c,
lib\matio.h,
lib\endian.c,
lib\exact-int.h,
lib\inflate.c,
lib\io.c,
lib\mat4.c,
lib\mat4.h,
lib\mat5.c,
lib\mat5.h,
lib\mat73.c,
lib\mat73.h,
lib\matio_private.h,
lib\matvar_cell.c,
lib\matvar_struct.c,
lib\read_data.c,
lib\safe-math.h,
lib\snprintf.c,
lib\matio_pubconf.h,
lib\matioConfig.h,
Copying;