diff --git a/.appveyor.yml b/.appveyor.yml index 478febe3..f416db99 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,12 +16,6 @@ platform: environment: matrix: - - compiler: MinGW - configuration: Release - build_with: autoconf - - compiler: Cygwin - configuration: Release - build_with: autoconf - compiler: MSVC configuration: Release build_with: cmake @@ -31,6 +25,12 @@ environment: - compiler: MSVC configuration: Release Lib build_with: msbuild + - compiler: MinGW + configuration: Release + build_with: autoconf + - compiler: Cygwin + configuration: Release + build_with: autoconf matrix: exclude: @@ -60,27 +60,24 @@ for: - compiler: MSVC install: + - git clone https://github.com/tbeu/matio-ci ./.ci/ci - ps: >- If ($env:Platform -Match "Win32") { $env:HDF5_DIR="C:\projects\HDF5-1.8.13-win32" $env:sdk_platform_env="x86" If ($env:configuration -Match "Lib") { - Start-FileDownload 'https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.13/bin/windows/hdf5-1.8.13-win32-VS2010-static.zip' - 7z x -y hdf5-1.8.13-win32-VS2010-static.zip | FIND "ing archive" + 7z x -y .\.ci\ci\hdf5-1.8.13-win32-VS2010-static.zip | FIND "ing archive" } Else { - Start-FileDownload 'https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.13/bin/windows/hdf5-1.8.13-win32-VS2010-shared.zip' - 7z x -y hdf5-1.8.13-win32-VS2010-shared.zip | FIND "ing archive" + 7z x -y .\.ci\ci\hdf5-1.8.13-win32-VS2010-shared.zip | FIND "ing archive" } 7z x -oC:\projects\HDF5-1.8.13-win32 -y hdf5-1.8.13\HDF5-1.8.13-win32.exe | FIND "ing archive" } Else { $env:HDF5_DIR="C:\projects\HDF5-1.8.13-win64" $env:sdk_platform_env="x64" If ($env:configuration -Match "Lib") { - Start-FileDownload 'https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.13/bin/windows/hdf5-1.8.13-win64-VS2010-static.zip' - 7z x -y hdf5-1.8.13-win64-VS2010-static.zip | FIND "ing archive" + 7z x -y .\.ci\ci\hdf5-1.8.13-win64-VS2010-static.zip | FIND "ing archive" } Else { - Start-FileDownload 'https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.13/bin/windows/hdf5-1.8.13-win64-VS2010-shared.zip' - 7z x -y hdf5-1.8.13-win64-VS2010-shared.zip | FIND "ing archive" + 7z x -y .\.ci\ci\hdf5-1.8.13-win64-VS2010-shared.zip | FIND "ing archive" } 7z x -oC:\projects\HDF5-1.8.13-win64 -y hdf5-1.8.13\HDF5-1.8.13-win64.exe | FIND "ing archive" } diff --git a/test/test_mat.c b/test/test_mat.c index 26459329..7f8dc1b8 100644 --- a/test/test_mat.c +++ b/test/test_mat.c @@ -3909,404 +3909,41 @@ test_directory(char *file) int main(int argc, char *argv[]) { - const char *prog_name = "test_mat"; - int c, k, err = 0, ntests = 0, dim_append = 0; mat_t *mat; - matvar_t *matvar; - enum matio_classes matvar_class = MAT_C_DOUBLE; - const char *output_name = NULL; + char output_name[256]; int version[3]; Mat_GetLibraryVersion(version, version + 1, version + 2); - if ( MATIO_MAJOR_VERSION != version[0] || MATIO_MINOR_VERSION != version[1] || - MATIO_RELEASE_LEVEL != version[2] ) { - fprintf(stderr, "matio version in header does not match runtime version\n"); - return EXIT_FAILURE; - } + snprintf(output_name, 256, "structS-matio-%d.%d.%d.mat", version[0], version[1], version[2]); - Mat_LogInit(prog_name); - Mat_SetDebug(1); + mat = Mat_CreateVer(output_name, + "MATLAB 5.0 MAT-file, Platform: x86_64-pc-windows, Created by: libmatio " + "v1.5.9 on Thu Jun 13 16:06:30 2024\x0A", + MAT_FT_MAT5); + if ( mat ) { + const char *str = "logiciel"; + const double age[1] = {30.0}; + const size_t num_fields = 2; + const char *fieldnames[2] = {"type", "age"}; + size_t dims[2]; + matvar_t *matvar, *struct_matvar; + matvar_t *structEntries[3] = {NULL, NULL, NULL}; - while ( (c = getopt_long(argc, argv, optstring, options, NULL)) != EOF ) { - switch ( c ) { - case 'a': - dim_append = (int)strtol(optarg, NULL, 10); - break; - case 'c': - if ( !strcmp(optarg, "double") ) - matvar_class = MAT_C_DOUBLE; - else if ( !strcmp(optarg, "single") ) - matvar_class = MAT_C_SINGLE; - else if ( !strcmp(optarg, "int64") ) - matvar_class = MAT_C_INT64; - else if ( !strcmp(optarg, "uint64") ) - matvar_class = MAT_C_UINT64; - else if ( !strcmp(optarg, "int32") ) - matvar_class = MAT_C_INT32; - else if ( !strcmp(optarg, "uint32") ) - matvar_class = MAT_C_UINT32; - else if ( !strcmp(optarg, "int16") ) - matvar_class = MAT_C_INT16; - else if ( !strcmp(optarg, "uint16") ) - matvar_class = MAT_C_UINT16; - else if ( !strcmp(optarg, "int8") ) - matvar_class = MAT_C_INT8; - else if ( !strcmp(optarg, "uint8") ) - matvar_class = MAT_C_UINT8; - else { - fprintf(stderr, "Unrecognized MAT variable class '%s'", optarg); - exit(EXIT_FAILURE); - } - break; - case 'o': - output_name = optarg; - break; - case 'v': - if ( !strcmp(optarg, "5") ) { - mat_file_ver = MAT_FT_MAT5; - } else if ( !strcmp(optarg, "7.3") ) { - mat_file_ver = MAT_FT_MAT73; - } else if ( !strcmp(optarg, "4") ) { - mat_file_ver = MAT_FT_MAT4; - } else { - fprintf(stderr, "Unrecognized MAT file version %s", argv[2]); - exit(EXIT_FAILURE); - } - break; - case 'H': - Mat_Help(helpstr); - /* Note: Mat_Help() calls exit() */ - case 'L': - Mat_Help(helptestsstr); - /* Note: Mat_Help() calls exit() */ - case 'T': - help_test(optarg); - /* Note: help_test() calls exit() */ - case 'V': - printf( - "%s %s\nWritten by Christopher Hulbert\n\n" - "Copyright(C) 2015-2024, The matio contributors\n" - "Copyright(C) 2006-2014, Christopher C. Hulbert\n", - prog_name, PACKAGE_VERSION); - exit(EXIT_SUCCESS); - case 'z': - compression = MAT_COMPRESSION_ZLIB; - break; - case '?': - exit(EXIT_FAILURE); - default: - printf("%c not a valid option\n", c); - break; - } - } + dims[0] = 1; + dims[1] = 8; + structEntries[0] = + Mat_VarCreate(fieldnames[0], MAT_C_CHAR, MAT_T_UINT8, 2, dims, (void *)str, 0); + dims[0] = 1; + dims[1] = 1; + structEntries[1] = + Mat_VarCreate(fieldnames[1], MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, (void *)age, 0); + dims[0] = 1; + dims[1] = 1; + struct_matvar = + Mat_VarCreate("structS", MAT_C_STRUCT, MAT_T_STRUCT, 2, dims, structEntries, 0); - for ( k = optind; k < argc; ) { - if ( !strcasecmp(argv[k], "copy") ) { - mat_t *mat2; - k++; - if ( NULL == output_name ) - output_name = "test_mat_copy.mat"; - mat = Mat_CreateVer(output_name, NULL, mat_file_ver); - mat2 = Mat_Open(argv[k++], MAT_ACC_RDONLY); - if ( mat && mat2 ) { - while ( NULL != (matvar = Mat_VarReadNext(mat2)) ) { - matvar_t *copy = Mat_VarDuplicate(matvar, 1); - Mat_VarFree(matvar); - if ( NULL != copy ) { - err += Mat_VarWrite(mat, copy, compression); - Mat_VarFree(copy); - } else { - err++; - } - } - Mat_Close(mat); - Mat_Close(mat2); - } - ntests++; - } else if ( !strcasecmp(argv[k], "delete") ) { - k++; - err += test_delete(argv[k], argv[k + 1]); - k += 2; - ntests++; - } else if ( !strcasecmp(argv[k], "directory") ) { - k++; - err += test_directory(argv[k++]); - ntests++; - } else if ( !strcasecmp(argv[k], "write_2d_logical") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_2d_logical.mat"; - err += test_write_2d_logical(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_2d_numeric") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_2d_numeric.mat"; - err += test_write_2d_numeric(matvar_class, output_name, dim_append); - ntests++; - } else if ( !strcasecmp(argv[k], "write_complex_2d_numeric") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_complex_2d_numeric.mat"; - err += test_write_complex_2d_numeric(matvar_class, output_name, dim_append); - ntests++; - } else if ( !strcasecmp(argv[k], "write_empty_2d_numeric") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_empty_2d_numeric.mat"; - err += test_write_empty_2d_numeric(matvar_class, output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_char") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_char.mat"; - err += test_write_char(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_char_unicode") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_char_unicode.mat"; - err += test_write_char_unicode(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_char_utf8") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_char_utf8.mat"; - err += test_write_char_utf8(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "writenull") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_null.mat"; - err += test_write_null(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "writenan") ) { - k++; - err += test_writenan(); - ntests++; - } else if ( !strcasecmp(argv[k], "writeinf") ) { - k++; - if ( NULL == output_name ) - output_name = "test_writeinf.mat"; - err += test_writeinf(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "readvar") ) { - k++; - if ( argc < 4 ) { - Mat_Critical("Must specify the input file and variable respectively"); - err++; - } else { - err += test_readvar(argv[k], argv[k + 1], output_name); - k += 2; - } - ntests++; - } else if ( !strcasecmp(argv[k], "write_struct_2d_logical") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_struct_2d_logical.mat"; - err += test_write_struct_2d_logical(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_struct_char") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_struct_char.mat"; - err += test_write_struct_char(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_struct_2d_numeric") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_struct_2d_numeric.mat"; - err += test_write_struct_2d_numeric(matvar_class, output_name, dim_append); - ntests++; - } else if ( !strcasecmp(argv[k], "write_struct_complex_2d_numeric") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_struct_complex_2d_numeric.mat"; - err += test_write_struct_complex_2d_numeric(matvar_class, output_name, dim_append); - ntests++; - } else if ( !strcasecmp(argv[k], "write_empty_struct") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_empty_struct.mat"; - err += test_write_empty_struct(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_cell_2d_logical") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_cell_2d_logical.mat"; - err += test_write_cell_2d_logical(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_cell_2d_numeric") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_cell_2d_numeric.mat"; - err += test_write_cell_2d_numeric(matvar_class, output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_cell_complex_2d_numeric") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_cell_complex_2d_numeric.mat"; - err += test_write_cell_complex_2d_numeric(matvar_class, output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_empty_cell") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_empty_cell.mat"; - err += test_write_empty_cell(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_cell_empty_struct") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_cell_empty_struct.mat"; - err += test_write_cell_empty_struct(output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "struct_api_create") ) { - k++; - redirect_output(output_name); - err += test_struct_api_create(); - ntests++; - } else if ( !strcasecmp(argv[k], "struct_api_setfield") ) { - k++; - redirect_output(output_name); - err += test_struct_api_setfield(); - ntests++; - } else if ( !strcasecmp(argv[k], "struct_api_getfieldnames") ) { - k++; - redirect_output(output_name); - err += test_struct_api_getfieldnames(); - ntests++; - } else if ( !strcasecmp(argv[k], "struct_api_addfield") ) { - k++; - redirect_output(output_name); - err += test_struct_api_addfield(); - ntests++; - } else if ( !strcasecmp(argv[k], "struct_api_getlinear") ) { - k++; - redirect_output(output_name); - err += test_struct_api_getlinear(); - ntests++; - } else if ( !strcasecmp(argv[k], "struct_api_get") ) { - k++; - redirect_output(output_name); - err += test_struct_api_get(); - ntests++; - } else if ( !strcasecmp(argv[k], "cell_api_set") ) { - k++; - redirect_output(output_name); - err += test_cell_api_set(); - ntests++; - } else if ( !strcasecmp(argv[k], "cell_api_getlinear") ) { - k++; - redirect_output(output_name); - err += test_cell_api_getlinear(); - ntests++; - } else if ( !strcasecmp(argv[k], "cell_api_getcells") ) { - k++; - redirect_output(output_name); - err += test_cell_api_getcells(); - ntests++; - } else if ( !strcasecmp(argv[k], "getstructfield") ) { - k++; - if ( argc - k < 3 ) { - Mat_Critical( - "Must specify the input file, structure name, " - "and field name/index"); - err++; - } else { - redirect_output(output_name); - err += test_get_struct_field(argv[k], argv[k + 1], argv[k + 2]); - k += 3; - } - ntests++; - } else if ( !strcasecmp(argv[k], "readvarinfo") ) { - k++; - mat = Mat_Open(argv[k++], MAT_ACC_RDONLY); - if ( mat ) { - matvar = Mat_VarReadInfo(mat, argv[k++]); - if ( matvar ) { - Mat_VarPrint(matvar, 0); - Mat_VarFree(matvar); - } - Mat_Close(mat); - } else { - k++; - err++; - } - ntests++; - } else if ( !strcasecmp(argv[k], "readslab") ) { - k++; - if ( NULL == output_name ) - output_name = "XXX.mat"; - test_readslab(argv[k], argv[k + 1], matvar_class); - k += 2; - ntests++; - } else if ( !strcasecmp(argv[k], "write_sparse") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_sparse.mat"; - err += test_write_sparse(matvar_class, output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_complex_sparse") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_sparse_complex.mat"; - err += test_write_complex_sparse(matvar_class, output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "write_allzero_sparse") ) { - k++; - if ( NULL == output_name ) - output_name = "test_write_allzero_sparse.mat"; - err += test_write_allzero_sparse(matvar_class, output_name); - ntests++; - } else if ( !strcasecmp(argv[k], "ind2sub") ) { - size_t *subs; - const size_t dims[3] = {256, 256, 124}; - redirect_output(output_name); - subs = Mat_CalcSubscripts2(3, dims, 18921 - 1); - Mat_Message("(%zu,%zu,%zu)", subs[0], subs[1], subs[2]); - free(subs); - k++; - ntests++; - } else if ( !strcasecmp(argv[k], "sub2ind") ) { - const size_t dims[3] = {256, 256, 124}; - const size_t index[3] = {233, 74, 1}; - size_t linear_index = 0; - redirect_output(output_name); - err += Mat_CalcSingleSubscript2(3, dims, index, &linear_index); - Mat_Message("%zu", linear_index); - k++; - ntests++; - } else if ( !strcasecmp(argv[k], "reshape32x32x32") ) { - k++; - mat = Mat_Open(argv[k++], MAT_ACC_RDONLY); - if ( NULL != mat ) { - matvar = Mat_VarRead(mat, argv[k++]); - if ( matvar ) { - if ( matvar->rank == 3 && matvar->dims[0] == 32 && matvar->dims[1] == 32 && - matvar->dims[2] == 32 ) { - mat_t *mat2; - matvar->rank = 2; - matvar->dims[0] = 128; - matvar->dims[1] = 256; - matvar->dims[2] = 1; - if ( NULL == output_name ) - output_name = "test_write_reshape32x32x32.mat"; - mat2 = Mat_CreateVer(output_name, NULL, mat_file_ver); - if ( NULL != mat2 ) { - err += Mat_VarWrite(mat2, matvar, compression); - Mat_Close(mat2); - } - } - Mat_VarFree(matvar); - } - Mat_Close(mat); - } - ntests++; - } else { - Mat_Critical("Unrecognized test %s", argv[k]); - break; - } + Mat_VarWrite(mat, struct_matvar, MAT_COMPRESSION_ZLIB); + Mat_VarFree(struct_matvar); + Mat_Close(mat); } - - return err; } diff --git a/tools/matdump.c b/tools/matdump.c index 2f44530d..9a2def08 100644 --- a/tools/matdump.c +++ b/tools/matdump.c @@ -740,13 +740,7 @@ print_default(const matvar_t *matvar) case MAT_C_INT16: case MAT_C_UINT16: case MAT_C_INT8: - case MAT_C_UINT8: { - if ( matvar->rank == 2 ) - print_default_numeric_2d(matvar); - else if ( matvar->rank == 3 ) - print_default_numeric_3d(matvar); - break; - } + case MAT_C_UINT8: case MAT_C_CHAR: case MAT_C_SPARSE: Mat_VarPrint(matvar, printdata);