2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA - Allan CORNET
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
15 #include "api_scilab.h"
16 #include "localization.h"
18 #include "warningmode.h"
19 /*--------------------------------------------------------------------------*/
20 extern int C2F(intsave)(); /* fortran subroutine */
21 /*--------------------------------------------------------------------------*/
22 int sci_save(char *fname, unsigned long fname_len)
34 //filename or file descriptor
35 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
38 printError(&sciErr, 0);
42 sciErr = getVarType(pvApiCtx, piAddr1, &iType1);
45 printError(&sciErr, 0);
49 if (iType1 == sci_strings)
61 for (i = 2 ; i <= Rhs ; i++)
63 sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrI);
66 printError(&sciErr, 0);
70 sciErr = getVarType(pvApiCtx, piAddrI, &iTypeI);
73 printError(&sciErr, 0);
77 if (iTypeI != sci_strings)
83 sciErr = getVarDimension(pvApiCtx, piAddrI, &iRowsI, &iColsI);
86 printError(&sciErr, 0);
90 if (iRowsI != 1 || iColsI != 1)
96 if (getAllocatedSingleString(pvApiCtx, piAddrI, &pstVarI))
101 if(strcmp(pstVarI, "-append") != 0)
103 //try to get variable by name
104 sciErr = getVarAddressFromName(pvApiCtx, pstVarI, &piAddrI2);
107 // Try old save because here the input variable can be of type "string" but not a variable name
108 // Ex: a=""; save(filename, a);
120 freeAllocatedSingleString(pstVarI);
133 //new save to sod format
134 if(iOldSave == FALSE)
137 //call "overload" to prepare data to export_to_hdf5 function.
138 C2F(overload) (&lw, "save", (unsigned long)strlen("save"));
144 {//show warning only for variable save, not for environment.
145 if (getWarningMode() && Rhs > 1)
147 sciprint(_("%s: Scilab 6 will not support the file format used.\n"), _("Warning"));
148 sciprint(_("%s: Please quote the variable declaration. Example, save('myData.sod',a) becomes save('myData.sod','a').\n"), _("Warning"));
149 sciprint(_("%s: See help('save') for the rational.\n"), _("Warning"));
156 /*--------------------------------------------------------------------------*/