1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 extern "C"
17 {
18 #include "gw_hdf5.h"
19 #include "Scierror.h"
20 #include "api_scilab.h"
21 #include "localization.h"
22 }
23 
24 #include "HDF5Scilab.hxx"
25 #include "H5File.hxx"
26 
27 using namespace org_modules_hdf5;
28 
29 /*
30   Flush the file containing the object
31   Scilab prototype:
32   - h5flush(obj)
33   - h5flush(obj, local)
34 */
35 
36 /*--------------------------------------------------------------------------*/
sci_h5flush(char * fname,int * pvApiCtx)37 int sci_h5flush(char *fname, int* pvApiCtx)
38 {
39     H5Object * hobj = 0;
40     SciErr err;
41     int * addr = 0;
42     int local;
43     bool _local = true;
44     const int nbIn = nbInputArgument(pvApiCtx);
45 
46     CheckOutputArgument(pvApiCtx, 0, 1);
47     CheckInputArgument(pvApiCtx, 1, 2);
48 
49     err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
50     if (err.iErr)
51     {
52         printError(&err, 0);
53         Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
54         return 0;
55     }
56 
57     if (HDF5Scilab::isH5Object(addr, pvApiCtx))
58     {
59         hobj = HDF5Scilab::getH5Object(addr, pvApiCtx);
60         if (!hobj)
61         {
62             Scierror(999, _("%s: Invalid H5Object.\n"), fname);
63             return 0;
64         }
65     }
66     else
67     {
68         Scierror(999, _("%s: Wrong type for input argument #%d: A HDF5 object expected.\n"), fname, 1);
69         return 0;
70     }
71 
72     if (nbIn == 2)
73     {
74         err = getVarAddressFromPosition(pvApiCtx, 2, &addr);
75         if (err.iErr)
76         {
77             printError(&err, 0);
78             Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
79             return 0;
80         }
81 
82         if (!isBooleanType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1))
83         {
84             Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
85             return 0;
86         }
87 
88         if (getScalarBoolean(pvApiCtx, addr, &local) != 0)
89         {
90             Scierror(999, _("%s: No more memory.\n"), fname);
91             return 0;
92         }
93 
94         local = _local != 0;
95     }
96 
97     try
98     {
99         hobj->getFile().flush(_local);
100     }
101     catch (const std::exception & e)
102     {
103         Scierror(999, _("%s: %s\n"), fname, e.what());
104         return 0;
105     }
106 
107     AssignOutputVariable(pvApiCtx, 1) = 0;
108     ReturnArguments(pvApiCtx);
109 
110     return 0;
111 }
112