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 #include <set>
17 #include <string>
18 
19 extern "C"
20 {
21 #include "gw_hdf5.h"
22 #include "Scierror.h"
23 #include "api_scilab.h"
24 #include "localization.h"
25 }
26 
27 #include "HDF5Scilab.hxx"
28 
29 using namespace org_modules_hdf5;
30 
31 /*--------------------------------------------------------------------------*/
sci_h5isfoo(const HDF5Scilab::H5ObjectType type,char * fname,int * pvApiCtx)32 inline static int sci_h5isfoo(const HDF5Scilab::H5ObjectType type, char * fname, int* pvApiCtx)
33 {
34     H5Object * hobj = 0;
35     SciErr err;
36     int * addr = 0;
37     bool ok = false;
38     const int nbIn = nbInputArgument(pvApiCtx);
39 
40     CheckOutputArgument(pvApiCtx, 0, 1);
41     CheckInputArgument(pvApiCtx, 1, 1);
42 
43     err = getVarAddressFromPosition(pvApiCtx, 1, &addr);
44     if (err.iErr)
45     {
46         printError(&err, 0);
47         Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
48         return 0;
49     }
50 
51     if (HDF5Scilab::isH5Object(addr, pvApiCtx))
52     {
53         hobj = HDF5Scilab::getH5Object(addr, pvApiCtx);
54         if (!hobj)
55         {
56             goto finish;
57         }
58     }
59     else
60     {
61         goto finish;
62     }
63 
64     try
65     {
66         ok = HDF5Scilab::checkType(*hobj, type);
67     }
68     catch (const std::exception & /*e*/)
69     {
70 
71     }
72 
73 finish:
74 
75     if (createScalarBoolean(pvApiCtx, nbIn + 1, ok ? 1 : 0))
76     {
77         Scierror(999, _("%s: Can not create output argument.\n"), fname);
78         return 0;
79     }
80 
81     AssignOutputVariable(pvApiCtx, 1) = nbIn + 1;
82     ReturnArguments(pvApiCtx);
83 
84     return 0;
85 }
86 /*--------------------------------------------------------------------------*/
87 
sci_h5isFile(char * fname,int * pvApiCtx)88 int sci_h5isFile(char * fname, int* pvApiCtx)
89 {
90     return sci_h5isfoo(HDF5Scilab::H5FILE, fname, pvApiCtx);
91 }
92 /*--------------------------------------------------------------------------*/
93 
sci_h5isGroup(char * fname,int * pvApiCtx)94 int sci_h5isGroup(char * fname, int* pvApiCtx)
95 {
96     return sci_h5isfoo(HDF5Scilab::H5GROUP, fname, pvApiCtx);
97 }
98 /*--------------------------------------------------------------------------*/
99 
sci_h5isSet(char * fname,int * pvApiCtx)100 int sci_h5isSet(char * fname, int* pvApiCtx)
101 {
102     return sci_h5isfoo(HDF5Scilab::H5DATASET, fname, pvApiCtx);
103 }
104 /*--------------------------------------------------------------------------*/
105 
sci_h5isAttr(char * fname,int * pvApiCtx)106 int sci_h5isAttr(char * fname, int* pvApiCtx)
107 {
108     return sci_h5isfoo(HDF5Scilab::H5ATTRIBUTE, fname, pvApiCtx);
109 }
110 /*--------------------------------------------------------------------------*/
111 
sci_h5isSpace(char * fname,int * pvApiCtx)112 int sci_h5isSpace(char * fname, int* pvApiCtx)
113 {
114     return sci_h5isfoo(HDF5Scilab::H5SPACE, fname, pvApiCtx);
115 }
116 /*--------------------------------------------------------------------------*/
117 
sci_h5isType(char * fname,int * pvApiCtx)118 int sci_h5isType(char * fname, int* pvApiCtx)
119 {
120     return sci_h5isfoo(HDF5Scilab::H5TYPE, fname, pvApiCtx);
121 }
122 /*--------------------------------------------------------------------------*/
123 
sci_h5isRef(char * fname,int * pvApiCtx)124 int sci_h5isRef(char * fname, int* pvApiCtx)
125 {
126     return sci_h5isfoo(HDF5Scilab::H5REFERENCE, fname, pvApiCtx);
127 }
128 /*--------------------------------------------------------------------------*/
sci_h5isList(char * fname,int * pvApiCtx)129 int sci_h5isList(char * fname, int* pvApiCtx)
130 {
131     return sci_h5isfoo(HDF5Scilab::H5LIST, fname, pvApiCtx);
132 }
133 /*--------------------------------------------------------------------------*/
sci_h5isCompound(char * fname,int * pvApiCtx)134 int sci_h5isCompound(char * fname, int* pvApiCtx)
135 {
136     return sci_h5isfoo(HDF5Scilab::H5COMPOUND, fname, pvApiCtx);
137 }
138 /*--------------------------------------------------------------------------*/
sci_h5isArray(char * fname,int * pvApiCtx)139 int sci_h5isArray(char * fname, int* pvApiCtx)
140 {
141     return sci_h5isfoo(HDF5Scilab::H5ARRAY, fname, pvApiCtx);
142 }
143 /*--------------------------------------------------------------------------*/
sci_h5isVlen(char * fname,int * pvApiCtx)144 int sci_h5isVlen(char * fname, int* pvApiCtx)
145 {
146     return sci_h5isfoo(HDF5Scilab::H5VLEN, fname, pvApiCtx);
147 }
148 /*--------------------------------------------------------------------------*/
149