Skip to content

Commit

Permalink
Make use of Mat_SizeOf
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Nov 15, 2016
1 parent 59294ec commit 218be18
Showing 1 changed file with 7 additions and 32 deletions.
39 changes: 7 additions & 32 deletions src/mat5.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,13 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
if ( (mat == NULL) || (mat->fp == NULL) )
return 0;

data_size = Mat_SizeOf(data_type);

switch ( data_type ) {
case MAT_T_DOUBLE:
{
double d = 0.0;

data_size = sizeof(double);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -918,7 +919,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
float f = 0.0;

data_size = sizeof(float);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -930,7 +930,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_int8_t i8 = 0;

data_size = sizeof(mat_int8_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -942,7 +941,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_uint8_t ui8 = 0;

data_size = sizeof(mat_uint8_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -954,7 +952,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_int16_t i16 = 0;

data_size = sizeof(mat_int16_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -966,7 +963,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_uint16_t ui16 = 0;

data_size = sizeof(mat_uint16_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -978,7 +974,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_int32_t i32 = 0;

data_size = sizeof(mat_int32_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -990,7 +985,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_uint32_t ui32 = 0;

data_size = sizeof(mat_uint32_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1003,7 +997,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_int64_t i64 = 0;

data_size = sizeof(mat_int64_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1017,7 +1010,6 @@ WriteEmptyData(mat_t *mat,int N,enum matio_types data_type)
{
mat_uint64_t ui64 = 0;

data_size = sizeof(mat_uint64_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1043,14 +1035,15 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
if ( (mat == NULL) || (mat->fp == NULL) )
return 0;

data_size = Mat_SizeOf(data_type);

switch ( data_type ) {
case MAT_T_DOUBLE:
{
mat_uint32_t uncomp_buf[32] = {0,};
mat_uint32_t comp_buf[32] = {0,};
double data_uncomp_buf[4] = {0.0,};

data_size = sizeof(double);
nBytes = N*data_size;
uncomp_buf[0] = data_type;
uncomp_buf[1] = 0;
Expand Down Expand Up @@ -1078,7 +1071,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
float f = 0.0;

data_size = sizeof(float);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1090,7 +1082,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_int8_t i8 = 0;

data_size = sizeof(mat_int8_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1102,7 +1093,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_uint8_t ui8 = 0;

data_size = sizeof(mat_uint8_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1114,7 +1104,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_int16_t i16 = 0;

data_size = sizeof(mat_int16_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1126,7 +1115,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_uint16_t ui16 = 0;

data_size = sizeof(mat_uint16_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1138,7 +1126,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_int32_t i32 = 0;

data_size = sizeof(mat_int32_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1150,7 +1137,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_uint32_t ui32 = 0;

data_size = sizeof(mat_uint32_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1163,7 +1149,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_int64_t i64 = 0;

data_size = sizeof(mat_int64_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand All @@ -1177,7 +1162,6 @@ WriteCompressedEmptyData(mat_t *mat,z_streamp z,int N,
{
mat_uint64_t ui64 = 0;

data_size = sizeof(mat_uint64_t);
nBytes = N*data_size;
fwrite(&data_type,4,1,(FILE*)mat->fp);
fwrite(&nBytes,4,1,(FILE*)mat->fp);
Expand Down Expand Up @@ -1220,12 +1204,13 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
return 0;
}

data_size = Mat_SizeOf(data_type);

switch ( data_type ) {
case MAT_T_DOUBLE:
{
double *ptr;

data_size = sizeof(double);
ptr = (double *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1256,7 +1241,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
float *ptr;

data_size = sizeof(float);
ptr = (float *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1288,7 +1272,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_int64_t *ptr;

data_size = sizeof(mat_int64_t);
ptr = (mat_int64_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1321,7 +1304,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_uint64_t *ptr;

data_size = sizeof(mat_uint64_t);
ptr = (mat_uint64_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1353,7 +1335,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_int32_t *ptr;

data_size = sizeof(mat_int32_t);
ptr = (mat_int32_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1384,7 +1365,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_uint32_t *ptr;

data_size = sizeof(mat_uint32_t);
ptr = (mat_uint32_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1415,7 +1395,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_int16_t *ptr;

data_size = sizeof(mat_int16_t);
ptr = (mat_int16_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1446,7 +1425,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_uint16_t *ptr;

data_size = sizeof(mat_uint16_t);
ptr = (mat_uint16_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1477,7 +1455,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_int8_t *ptr;

data_size = sizeof(mat_int8_t);
ptr = (mat_int8_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1508,7 +1485,6 @@ WriteDataSlab2(mat_t *mat,void *data,enum matio_types data_type,size_t *dims,
{
mat_uint8_t *ptr;

data_size = sizeof(mat_uint8_t);
ptr = (mat_uint8_t *)data;
row_stride = (stride[0]-1)*data_size;
col_stride = stride[1]*dims[0]*data_size;
Expand Down Expand Up @@ -1716,8 +1692,7 @@ WriteCompressedData(mat_t *mat,z_streamp z,void *data,int N,
if ((mat == NULL) || (mat->fp == NULL))
return 0;

data_size = Mat_SizeOf(data_type);

data_size = Mat_SizeOf(data_type);
data_tag[0] = data_type;
data_tag[1] = data_size*N;
z->next_in = ZLIB_BYTE_PTR(data_tag);
Expand Down

0 comments on commit 218be18

Please sign in to comment.