3 * Copyright (C) INRIA -
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * See the file ./license.txt
21 /*--------------------------------------------------------------------------*/
23 #include "gw_scicos.h"
25 #include "scicos_block4.h"
27 #include "localization.h"
29 #include "createblklist.h"
30 #include "extractblklist.h"
33 /*--------------------------------------------------------------------------*/
34 extern int *listentry(int *header, int i);
35 /*--------------------------------------------------------------------------*/
36 int sci_callblk(char *fname, unsigned long fname_len)
38 /* auxilary variables -dimension and address-
39 * for scilab stack variables
44 int m2_1 = 0, n2_1 = 0;
53 int ierr = 0, ret = 0;
58 /* length of the scilab list scicos struct */
61 /* variable for callf */
66 memset(&Block, 0, sizeof(scicos_block));
68 /* check number of rhs/lhs param */
72 /* check rhs 1 (input scilab structure) */
73 il1 = (int *) GetData(1);
78 Scierror(888, _("%s : First argument must be a scicos_block typed list.\n"), fname);
82 il2_1 = (int *) (listentry(il1, 1));
85 if ((il2_1[0] != 10) || ((m2_1 * n2_1) != nblklst))
87 Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
90 len_str = il2_1[5] - 1;
93 if ((str = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL)
95 Scierror(888, _("%s: Memory allocation error.\n"), fname);
99 C2F(cvstr)(&len_str, &il2_1[5 + nblklst], str, (j = 1, &j), len_str);
100 ret = strcmp("scicos_block", str);
104 Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
110 Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
114 /* convert scilab scicos struct to a C scicos struct */
115 ret = extractblklist(il1, &Block, &ierr);
121 Scierror(888, _("%s: Memory allocation error.\n"), fname);
125 Scierror(888, _("%s : First argument must be a valid scicos_block typed list.\n"), fname);
137 for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]);
144 for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]);
147 for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]);
154 for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]);
158 if (strlen(Block.label) != 0) FREE(Block.label);
163 /* check rhs 2 (flag) */
164 il2 = (int *) GetData(2);
167 if ((il2[0] != 1) || (m2*n2 != 1))
169 Scierror(888, _("%s : Second argument must be scalar.\n"), fname);
172 flag = (scicos_flag) * ((double *)(&il2[4]));
174 /* check rhs 3 (time) */
175 il3 = (int *) GetData(3);
179 if ((il3[0] != 1) || (m3*n3 != 1))
181 Scierror(888, _("%s : Third argument must be scalar.\n"), fname);
184 t = *((double *)(&il3[4]));
187 callf(&t, &Block, &flag);
189 /* build output scilab structure */
192 ierr = createblklist(&Block, &ierr, -1, Block.type);
197 for (j = 0; j < Block.noz; j++) FREE(Block.ozptr[j]);
203 for (j = 0; j < Block.nin; j++) FREE(Block.inptr[j]);
206 for (j = 0; j < Block.nout; j++) FREE(Block.outptr[j]);
213 for (j = 0; j < Block.nopar; j++) FREE(Block.oparptr[j]);
217 if (strlen(Block.label) != 0) FREE(Block.label);
222 CreateVar(4, TYPED_LIST_DATATYPE, &nblklst, (j = 1, &j), &l_tmp);
228 /*--------------------------------------------------------------------------*/