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 #include "expandPathVariable.h"
23 }
24
25 #include "HDF5Scilab.hxx"
26 #include "H5File.hxx"
27
28 using namespace org_modules_hdf5;
29
30 /*
31 Mount a file on a group.
32 Scilab prototype:
33 - h5mount(obj, location, fileobj)
34 */
35
36 /*--------------------------------------------------------------------------*/
sci_h5mount(char * fname,int * pvApiCtx)37 int sci_h5mount(char *fname, int* pvApiCtx)
38 {
39 SciErr err;
40 H5Object * sobj = 0;
41 H5Object * dobj = 0;
42 int * addr = 0;
43 char * str = 0;
44 std::string sloc;
45
46 CheckOutputArgument(pvApiCtx, 0, 1);
47 CheckInputArgument(pvApiCtx, 3, 3);
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 sobj = HDF5Scilab::getH5Object(addr, pvApiCtx);
60 if (!sobj)
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 H5Object expected.\n"), fname, 1);
69 return 0;
70 }
71
72 err = getVarAddressFromPosition(pvApiCtx, 2, &addr);
73 if (err.iErr)
74 {
75 printError(&err, 0);
76 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2);
77 return 0;
78 }
79
80 if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1))
81 {
82 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
83 return 0;
84 }
85
86 if (getAllocatedSingleString(pvApiCtx, addr, &str) != 0)
87 {
88 Scierror(999, _("%s: No more memory.\n"), fname);
89 return 0;
90 }
91
92 sloc = std::string(str);
93 freeAllocatedSingleString(str);
94
95 err = getVarAddressFromPosition(pvApiCtx, 3, &addr);
96 if (err.iErr)
97 {
98 printError(&err, 0);
99 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3);
100 return 0;
101 }
102
103 if (HDF5Scilab::isH5Object(addr, pvApiCtx))
104 {
105 dobj = HDF5Scilab::getH5Object(addr, pvApiCtx);
106 if (!dobj)
107 {
108 Scierror(999, _("%s: Invalid H5Object.\n"), fname);
109 return 0;
110 }
111 }
112 else
113 {
114 Scierror(999, _("%s: Wrong type for input argument #%d: A H5Object expected.\n"), fname, 3);
115 return 0;
116 }
117
118 try
119 {
120 HDF5Scilab::mount(*sobj, sloc, *dobj);
121 }
122 catch (const std::exception & e)
123 {
124 Scierror(999, _("%s: %s\n"), fname, e.what());
125 return 0;
126 }
127
128 AssignOutputVariable(pvApiCtx, 1) = 0;
129 ReturnArguments(pvApiCtx);
130
131 return 0;
132 }
133