3 * Copyright (C) 2015 - Scilab Enterprises - Antoine ELIAS
4 * Copyright (C) DIGITEO - 2009 - Allan CORNET
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * See the file ./license.txt
22 /*--------------------------------------------------------------------------*/
23 #include "internal.hxx"
35 #include "createblklist.hxx"
36 /*--------------------------------------------------------------------------*/
37 //extern void str2sci(char** x, int n, int m); /* core/src/c/str2sci.h */
38 //extern void C2F(itosci)();
39 //extern void C2F(dtosci)();
40 //extern int C2F(scierr)();
41 //extern void C2F(vvtosci)();
42 //extern int C2F(mktlist)();
43 /*--------------------------------------------------------------------------*/
44 static types::InternalType* vartosci(void* data, const int rows, const int cols, const int type)
46 const int size = rows * cols;
51 types::Double* var = new types::Double(rows, cols);
52 for (int i = 0; i < size; ++i)
54 var->get()[i] = ((types::Double::type*)data)[i];
60 types::Double* var = new types::Double(rows, cols, true);
61 for (int i = 0; i < size; ++i)
63 var->get()[i] = ((types::Double::type*)data)[i];
64 var->getImg()[i] = ((types::Double::type*)data)[size + i];
70 types::Int8* var = new types::Int8(rows, cols);
71 for (int i = 0; i < size; ++i)
73 var->get()[i] = ((types::Int8::type*)data)[i];
79 types::Int16* var = new types::Int16(rows, cols);
80 for (int i = 0; i < size; ++i)
82 var->get()[i] = ((types::Int16::type*)data)[i];
88 types::Int32* var = new types::Int32(rows, cols);
89 for (int i = 0; i < size; ++i)
91 var->get()[i] = ((types::Int32::type*)data)[i];
97 types::UInt8* var = new types::UInt8(rows, cols);
98 for (int i = 0; i < size; ++i)
100 var->get()[i] = ((types::UInt8::type*)data)[i];
106 types::UInt16* var = new types::UInt16(rows, cols);
107 for (int i = 0; i < size; ++i)
109 var->get()[i] = ((types::UInt16::type*)data)[i];
115 types::UInt32* var = new types::UInt32(rows, cols);
116 for (int i = 0; i < size; ++i)
118 var->get()[i] = ((types::UInt32::type*)data)[i];
129 types::InternalType* createblklist(const scicos_block* const Blocks, const int flag_imp, const int /*funtyp*/)
131 /* set string of first element of scilab Blocks tlist -please update me- */
132 const int fieldCount = 41;
135 static const char *str_blklst[] = {"scicos_block", "nevprt", "funpt", "type",
136 "scsptr", "nz", "z", "noz",
137 "ozsz", "oztyp", "oz", "nx",
138 "x", "xd", "res", "nin",
139 "insz", "inptr", "nout", "outsz",
140 "outptr", "nevout", "evout", "nrpar",
141 "rpar", "nipar", "ipar", "nopar",
142 "oparsz", "opartyp", "opar", "ng",
143 "g", "ztyp", "jroot", "label",
144 "work", "nmode", "mode", "xprop",
148 int *xptr = nullptr; /* to retrieve xptr by import and zcptr of scicos_blocks */
149 double *x = nullptr; /* ptr for x, xd and g for scicos_blocks */
150 double *xd = nullptr;
151 int *zcptr = nullptr;
156 int nv, mv; /* length of data */
157 int nblk; /* to store number of blocks */
158 //int ng; /* to store number of zero cross */
159 void *ptr; /* ptr for data comming from import structure */
161 /*retrieve nblk by import structure*/
162 char Nblk[] = "nblk";
163 getscicosvarsfromimport(Nblk, &ptr, &nv, &mv);
164 nblk = ((int*)ptr)[0];
166 /* retrieve ng by import structure */
168 getscicosvarsfromimport(Ng, &ptr, &nv, &mv);
169 //ng = ((int*)ptr)[0];
171 /*retrieve xptr by import structure*/
172 char Xptr[] = "xptr";
173 getscicosvarsfromimport(Xptr, &ptr, &nv, &mv);
176 /*retrieve zcptr by import structure*/
177 char Zcptr[] = "zcptr";
178 getscicosvarsfromimport(Zcptr, &ptr, &nv, &mv);
181 /*retrieve x and xd by import structure*/
183 getscicosvarsfromimport(X, &ptr, &nv, &mv);
185 xd = &x[xptr[nblk] - 1];
187 /*retrieve g by import structure*/
189 getscicosvarsfromimport(G, &ptr, &nv, &mv);
193 types::TList* m = new types::TList();
195 /* 1 - scicos_block */
196 types::String* s = new types::String(1, fieldCount);
197 for (int i = 0; i < fieldCount; ++i)
199 s->set(i, str_blklst[i]);
205 m->append(new types::Double(static_cast<double>(Blocks->nevprt)));
208 //cast function ptr to double*
209 if (sizeof(voidg) >= sizeof(double))
211 // store N double values as the function pointer value
212 size = sizeof(voidg) / sizeof(double);
216 // push at least one double
220 types::Double* funpt = new types::Double(size, 1);
221 double* d = funpt->get();
222 for (int i = 0; i < size; ++i)
224 d[i] = (double)((long long)Blocks->funpt);
230 m->append(new types::Double(static_cast<double>(Blocks->type)));
233 //cast function ptr to double*
235 if (sizeof(types::InternalType*) >= sizeof(double))
237 // store N double values as the function pointer value
238 size = sizeof(types::InternalType*) / sizeof(double);
242 // push at least one double
245 types::Double* scsptr = new types::Double(size, 1);
247 for (int i = 0; i < size; ++i)
249 d[i] = (double)((long long)Blocks->scsptr);
255 m->append(new types::Double(static_cast<double>(Blocks->nz)));
258 m->append(vartosci(Blocks->z, Blocks->nz, 1, SCSREAL_N));
261 m->append(new types::Double(static_cast<double>(Blocks->noz)));
264 types::Double* ozsz = new types::Double(Blocks->noz, 1);
266 for (int i = 0; i < Blocks->noz; ++i)
268 d[i] = static_cast<double>(Blocks->ozsz[i]);
274 types::Double* oztyp = new types::Double(Blocks->noz, 1);
276 for (int i = 0; i < Blocks->noz; ++i)
278 d[i] = static_cast<double>(Blocks->oztyp[i]);
284 types::List* ozptr = new types::List();
285 for (int k = 0; k < Blocks->noz; k++)
287 const int rows = Blocks->ozsz[k]; /* retrieve number of rows */
288 const int cols = Blocks->ozsz[Blocks->noz + k]; /* retrieve number of cols */
289 const int type = Blocks->oztyp[k]; /* retrieve type */
290 ozptr->append(vartosci(Blocks->ozptr[k], rows, cols, type));
296 m->append(new types::Double(static_cast<double>(Blocks->nx)));
301 m->append(vartosci(&x[xptr[flag_imp] - 1], Blocks->nx, 1, SCSREAL_N));
305 m->append(vartosci(Blocks->x, Blocks->nx, 1, SCSREAL_N));
311 m->append(vartosci(&xd[xptr[flag_imp] - 1], Blocks->nx, 1, SCSREAL_N));
315 m->append(vartosci(Blocks->xd, Blocks->nx, 1, SCSREAL_N));
319 m->append(vartosci(Blocks->res, Blocks->nx, 1, SCSREAL_N));
322 m->append(new types::Double(static_cast<double>(Blocks->nin)));
325 types::Double* insz = new types::Double(3 * Blocks->nin, 1);
327 for (int i = 0; i < 3 * Blocks->nin; ++i)
329 d[i] = static_cast<double>(Blocks->insz[i]);
335 types::List* inptr = new types::List();
336 for (int k = 0; k < Blocks->nin; k++)
338 const int rows = Blocks->insz[k]; /* retrieve number of rows */
339 const int cols = Blocks->insz[Blocks->nin + k]; /* retrieve number of cols */
340 const int type = Blocks->insz[2 * Blocks->nin + k]; /* retrieve type */
341 inptr->append(vartosci(Blocks->inptr[k], rows, cols, type));
347 m->append(new types::Double(static_cast<double>(Blocks->nout)));
350 types::Double* outsz = new types::Double(3 * Blocks->nout, 1);
352 for (int i = 0; i < 3 * Blocks->nout; ++i)
354 d[i] = static_cast<double>(Blocks->outsz[i]);
359 types::List* outptr = new types::List();
360 for (int k = 0; k < Blocks->nout; k++)
362 const int rows = Blocks->outsz[k]; /* retrieve number of rows */
363 const int cols = Blocks->outsz[Blocks->nout + k]; /* retrieve number of cols */
364 const int type = Blocks->outsz[2 * Blocks->nout + k]; /* retrieve type */
365 outptr->append(vartosci(Blocks->outptr[k], rows, cols, type));
371 m->append(new types::Double(static_cast<double>(Blocks->nevout)));
374 m->append(vartosci(Blocks->evout, Blocks->nevout, 1, SCSREAL_N));
377 m->append(new types::Double(static_cast<double>(Blocks->nrpar)));
380 m->append(vartosci(Blocks->rpar, Blocks->nrpar, 1, SCSREAL_N));
383 m->append(new types::Double(static_cast<double>(Blocks->nipar)));
386 types::Double* ipar = new types::Double(Blocks->nipar, 1);
388 for (int i = 0; i < Blocks->nipar; ++i)
390 d[i] = static_cast<double>(Blocks->ipar[i]);
396 m->append(new types::Double(static_cast<double>(Blocks->nopar)));
399 types::Double* oparsz = new types::Double(Blocks->nopar, 1);
401 for (int i = 0; i < Blocks->nopar; ++i)
403 d[i] = static_cast<double>(Blocks->oparsz[i]);
409 types::Double* opartyp = new types::Double(Blocks->nopar, 1);
411 for (int i = 0; i < Blocks->nopar; ++i)
413 d[i] = static_cast<double>(Blocks->opartyp[i]);
419 types::List* opar = new types::List();
420 for (int k = 0; k < Blocks->nopar; k++)
422 const int rows = Blocks->oparsz[k]; /* retrieve number of rows */
423 const int cols = Blocks->oparsz[Blocks->nopar + k]; /* retrieve number of cols */
424 const int type = Blocks->opartyp[k]; /* retrieve type */
425 opar->append(vartosci(Blocks->oparptr[k], rows, cols, type));
431 m->append(new types::Double(static_cast<double>(Blocks->ng)));
436 m->append(vartosci(&g[zcptr[flag_imp] - 1], Blocks->ng, 1, SCSREAL_N));
440 m->append(vartosci(Blocks->g, Blocks->ng, 1, SCSREAL_N));
444 m->append(new types::Double(static_cast<double>(Blocks->ztyp)));
447 types::Double* jroot = new types::Double(Blocks->ng, 1);
449 for (int i = 0; i < Blocks->ng; ++i)
451 d[i] = static_cast<double>(Blocks->jroot[i]);
457 m->append(new types::String(Blocks->label));
460 //store address as double
461 m->append(new types::Double((double)((long long)Blocks->work)));
464 m->append(new types::Double(static_cast<double>(Blocks->nmode)));
467 types::Double* mode = new types::Double(Blocks->nmode, 1);
469 for (int i = 0; i < Blocks->nmode; ++i)
471 d[i] = static_cast<double>(Blocks->mode[i]);
477 types::Double* xprop = new types::Double(Blocks->nx, 1);
479 for (int i = 0; i < Blocks->nx; ++i)
481 d[i] = static_cast<double>(Blocks->xprop[i]);
489 m->append(new types::String(Blocks->uid));
493 m->append(new types::String(L""));
498 /*--------------------------------------------------------------------------*/