1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) ???? - INRIA - Serge STEER
3 // Copyright (C) 2009 - DIGITEO - Vincent COUVERT
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution. The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11 function matfile2sci(mat_file_path,result_file_path)
12 // Translate a Matlab MAT file into a Scilab file
14 // mat_file_path : path of the Matlab MAT file
15 // result_file_path : path of the generated Scilab file
17 //This function has been developped following the "MAT-File Format" description:
18 //www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/matfile_format.pdf
20 if ~with_module("matio") then
21 error(msprintf(gettext("%s: %s module is not installed.\n"), "matfile2sci", "matio"));
26 error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"matfile2sci",2)),
30 fdi=matfile_open(pathconvert(mat_file_path, %F, %T), "r");
31 fdo=pathconvert(result_file_path, %F, %T);
33 //-- Read first variable
34 ierr = execstr("[Name, Matrix, Class] = matfile_varreadnext(fdi);", "errcatch");
37 //--loop on the stored variables
38 while Name<>"" & ierr==0 & ierrsave==0
39 ierrsave = execstr(Name + " = Matrix; export_to_hdf5(fdo, ""-append"", """+Name+""")", "errcatch")
41 //-- Read next variable
42 ierr = execstr("[Name, Matrix, Class] = matfile_varreadnext(fdi);", "errcatch");