Xcos-Scicos: indent some files before modification
[scilab.git] / scilab / modules / scicos / sci_gateway / c / sci_model2blk.c
1 /*  Scicos
2 *
3 *  Copyright (C) INRIA -
4 *
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.
9 *
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.
14 *
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.
18 *
19 * See the file ./license.txt
20 */
21 /*--------------------------------------------------------------------------*/
22 #include <stdio.h>
23 #include "gw_scicos.h"
24 #include "stack-c.h"
25 #include "Scierror.h"
26 #include "localization.h"
27 #include "scicos_block4.h"
28 #include "MALLOC.h"
29 #include "cvstr.h"
30 #include "sciblk4.h"
31 #include "sciblk2.h"
32 #include "MlistGetFieldNumber.h"
33 #include "dynamic_link.h"
34 #include "createblklist.h"
35 #include "scicos.h"
36 /*--------------------------------------------------------------------------*/
37 extern int *listentry(int *header, int i);
38 extern int C2F(funnum) (char *fname);
39 extern int C2F(namstr)();
40 extern void  F2C(sciblk)();
41 /*--------------------------------------------------------------------------*/
42 extern int ntabsim;
43 extern OpTab tabsim[];
44 /*--------------------------------------------------------------------------*/
45 /* model2blk Build a scicos_block structure from
46 * a scicos model
47 *
48 * [Block] = model2blk(objs.model)
49 *
50 * rhs 1 : a scicos model Tlist
51 *        - 1  : model(1)     : !model      sim     in      in2     intyp    out    out2  outtyp
52 *                               evtin      evtout  state   dstate  odstate  rpar   ipar  opar
53 *                               blocktype  firing  dep_ut  label   nzcross  nmode  equations  !
54 *        - 2  : model.sim       :
55 *        - 3  : model.in        :
56 *        - 4  : model.in2       :
57 *        - 5  : model.intyp     :
58 *        - 6  : model.out       :
59 *        - 7  : model.out2      :
60 *        - 8  : model.outtyp    :
61 *        - 9  : model.evtin     :
62 *        - 10 : model.evtout    :
63 *        - 11 : model.state     :
64 *        - 12 : model.dsate     :
65 *        - 13 : model.odsate    :
66 *        - 14 : model.rpar      :
67 *        - 15 : model.ipar      :
68 *        - 16 : model.opar      :
69 *        - 17 : model.blocktype :
70 *        - 18 : model.firing    :
71 *        - 19 : model.dep_ut    :
72 *        - 20 : model.label     :
73 *        - 21 : model.nzcross   :
74 *        - 22 : model.nmode      :
75 *        - 23 : model.equations :
76 *
77 * lhs 1 : a scicos block Tlist
78 *
79 * initial rev 12/11/07, Alan
80 * 05/07/08, Alan : fix for xprop
81 *                  add extra comments
82 *                  check in/out size and type
83 *
84 */
85 int sci_model2blk(char *fname, unsigned long fname_len)
86 {
87     int m1 = 0, n1 = 0;
88     int *il1 = NULL;
89     int n = 0;
90     int mh = 0, nh = 0;
91     int *ilh = NULL;
92     int mh2 = 0, nh2 = 0;
93     int *ilh2 = NULL;
94     int mh3 = 0, nh3 = 0;
95     int *ilh3 = NULL;
96     int ierr = 0;
97     int TopSave = 0;
98     int i = 0, j = 0;
99     int l_tmp = 0;
100     double type = 0.0;
101     int len_str = 0;
102     int lfunpt = 0;
103     int typfsim = 0;
104     int ifun = 0;
105     int *il_sim = NULL;
106
107     int id[nsiz];
108
109     double *ptr_d = NULL;
110     char *ptr_c = NULL;
111     unsigned char *ptr_uc = NULL;
112     short *ptr_s = NULL;
113     unsigned short *ptr_us = NULL;
114     long *ptr_l = NULL;
115     unsigned long *ptr_ul = NULL;
116     int nblklst = 40;
117
118     scicos_block Block;
119     memset(&Block, 0, sizeof(scicos_block));
120
121
122
123     /* check size of rhs/lhs parameters */
124     CheckRhs(1, 1);
125     CheckLhs(1, 1);
126
127     il1 = (int *) GetData(1);
128     m1  = il1[1];
129     n1  = il1[2];
130
131     /* check for a tlist */
132     if (il1[0] != sci_mlist)
133     {
134         Scierror(888, _("%s : First argument must be a Typed list.\n"), fname);
135         return 0;
136     }
137
138     /* check for a type "scicos model" */
139     ilh = (int *) (listentry(il1, 1));
140     mh  = ilh[1];
141     nh  = ilh[2];
142     if ((ilh[mh * nh + 5] != 22) || \
143             (ilh[mh * nh + 6] != 24) || \
144             (ilh[mh * nh + 7] != 13) || \
145             (ilh[mh * nh + 8] != 14) || \
146             (ilh[mh * nh + 9] != 21))
147     {
148         Scierror(888, _("%s : First argument must be a scicos model.\n"), fname);
149         return 0;
150     }
151
152     /* TODO */
153     /* 2 : model.sim  */
154     n            = MlistGetFieldNumber(il1, "sim");
155     ilh          = (int *) (listentry(il1, n));
156     mh           = ilh[1];
157     nh           = ilh[2];
158     if (ilh[0] == sci_list)
159     {
160         /* sim  is a list */
161         ilh2 = (int *) (listentry(ilh, 2));
162         Block.type = (int) * ((double *) (&ilh2[4]));
163         ilh2 = (int *) (listentry(ilh, 1));
164         typfsim = ilh2[0]; /* typfsim  the name the comput funct */
165         il_sim = ilh2;
166     }
167     else
168     {
169         Block.type = 0;
170         typfsim = ilh[0];
171         il_sim = ilh;
172     }
173     /* check if typfsim is a scilab function */
174     if ((typfsim == sci_u_function) || (typfsim == sci_c_function))
175     {
176         /* TODO */
177         lfunpt = -1;
178     }
179     /* check if typfsim is a string */
180     else if (typfsim == sci_strings)
181     {
182         len_str = il_sim[5] - 1;
183         C2F(cha1).buf[0] = ' ';
184         C2F(cvstr)(&len_str, &il_sim[6], &C2F(cha1).buf[0], (j = 1, &j), len_str);
185         C2F(cha1).buf[len_str] = '\0';
186         /* search fun ptr of the comput func in the scilab func table */
187         ifun = C2F(funnum)(C2F(cha1).buf);
188         if (ifun > 0)
189         {
190             lfunpt = ifun;
191         }
192         else
193         {
194             C2F(namstr)(id, &il_sim[6], &len_str, (j = 0, &j));
195             C2F(com).fin = 0;
196             C2F(funs)(id);
197             if ((C2F(com).fun == -1) | (C2F(com).fun == -2))
198             {
199                 lfunpt = -*Lstk(C2F(com).fin);
200             }
201             else
202             {
203                 lfunpt = 0;
204                 Scierror(888, _("%s : unknown block : %s\n"), fname, C2F(cha1).buf);
205                 return 0;
206             }
207         }
208     }
209     /* else {
210     * error
211     }*/
212     /* comput func is a scilab function */
213     if (lfunpt < 0)
214     {
215         switch (Block.type)
216         {
217             case 0:
218                 Block.funpt = F2C(sciblk);
219                 break;
220             case 1:
221                 Scierror(888, _("%s : type 1 function not allowed for scilab blocks\n"), fname);
222                 return 0;
223             case 2:
224                 Scierror(888, _("%s : type 2 function not allowed for scilab blocks\n"), fname);
225                 return 0;
226             case 3:
227                 Block.funpt = sciblk2;
228                 Block.type = 2;
229                 break;
230             case 5:
231                 Block.funpt = sciblk4;
232                 Block.type = 4;
233                 break;
234             case 99: /* debugging block */
235                 Block.funpt = sciblk4;
236                 Block.type = 4;
237                 break;
238             case 10005:
239                 Block.funpt = sciblk4;
240                 Block.type = 10004;
241                 break;
242             default :
243                 Scierror(888, _("%s : Undefined Function type\n"), fname);
244                 return 0;
245         }
246         Block.scsptr = -lfunpt;
247     }
248     else if (lfunpt <= ntabsim)
249     {
250         Block.funpt = *(tabsim[lfunpt - 1].fonc);
251         Block.scsptr = 0;
252     }
253     else
254     {
255         lfunpt -= (ntabsim + 1);
256         GetDynFunc(lfunpt, &Block.funpt);
257         if (Block.funpt == (voidf) 0)
258         {
259             Scierror(888, _("%s : Function not found\n"), fname);
260             return 0;
261         }
262         Block.scsptr = 0;
263     }
264
265     /* check input ports */
266     /* 3 : model.in  */
267     n            = MlistGetFieldNumber(il1, "in");
268     ilh          = (int *) (listentry(il1, n));
269     mh           = ilh[1];
270     nh           = ilh[2];
271     Block.nin    = mh * nh;
272     Block.insz   = NULL;
273     Block.inptr  = NULL;
274     if (mh * nh != 0)
275     {
276         /* check value of in */
277         for (i = 0; i < Block.nin; i++)
278         {
279             if ((*((double *)(&ilh[4]) + i)) <= 0.)
280             {
281                 Scierror(888, _("%s : Undetermined Size. in(%d)=%d. Please adjust your model.\n"), \
282                          fname, i + 1, (int)(*((double *)(&ilh[4]) + i)));
283                 return 0;
284             }
285         }
286         /* alloc insz */
287         if ((Block.insz = (int *) MALLOC(Block.nin * 3 * sizeof(int))) == NULL)
288         {
289             Scierror(888, _("%s : Allocation error.\n"), fname);
290             return 0;
291         }
292         /* alloc inptr */
293         if ((Block.inptr = (void **) MALLOC(Block.nin * sizeof(void *))) == NULL)
294         {
295             FREE(Block.insz);
296             Scierror(888, _("%s : Allocation error.\n"), fname);
297             return 0;
298         }
299         /* 4 : model.in2  */
300         n    = MlistGetFieldNumber(il1, "in2");
301         ilh2 = (int *) (listentry(il1, n));
302         mh2  = ilh2[1];
303         nh2  = ilh2[2];
304         /* check value of in2 */
305         for (i = 0; i < (mh2 * nh2); i++)
306         {
307             if ((*((double *)(&ilh2[4]) + i)) <= 0.)
308             {
309                 Scierror(888, _("%s : Undetermined Size. in2(%d)=%d. Please adjust your model.\n"), \
310                          fname, i + 1, (int)(*((double *)(&ilh2[4]) + i)));
311                 FREE(Block.insz);
312                 FREE(Block.inptr);
313                 return 0;
314             }
315         }
316         /* 5 : model.intyp  */
317         n    = MlistGetFieldNumber(il1, "intyp");
318         ilh3 = (int *) (listentry(il1, n));
319         mh3  = ilh3[1];
320         nh3  = ilh3[2];
321         /* check value of intyp */
322         for (i = 0; i < (mh3 * nh3); i++)
323         {
324             if ((*((double *)(&ilh3[4]) + i)) <= 0.)
325             {
326                 Scierror(888, _("%s : Undetermined Type. intyp(%d)=%d. Please adjust your model.\n"), \
327                          fname, i + 1, (int)(*((double *)(&ilh3[4]) + i)));
328                 FREE(Block.insz);
329                 FREE(Block.inptr);
330                 return 0;
331             }
332         }
333         if (((mh * nh) == (mh2 * nh2)) && (((mh * nh) == (mh3 * nh3))))
334         {
335             for (i = 0; i < Block.nin; i++)
336             {
337                 Block.insz[i] = (int) * ((double *)(&ilh[4]) + i);
338                 Block.insz[Block.nin + i] = (int) * ((double *)(&ilh2[4]) + i);
339                 type = *((double *)(&ilh3[4]) + i);
340                 if (type == 1)
341                 {
342                     Block.insz[2 * Block.nin + i] = 10;
343                 }
344                 else if (type == 2)
345                 {
346                     Block.insz[2 * Block.nin + i] = 11;
347                 }
348                 else if (type == 3)
349                 {
350                     Block.insz[2 * Block.nin + i] = 84;
351                 }
352                 else if (type == 4)
353                 {
354                     Block.insz[2 * Block.nin + i] = 82;
355                 }
356                 else if (type == 5)
357                 {
358                     Block.insz[2 * Block.nin + i] = 81;
359                 }
360                 else if (type == 6)
361                 {
362                     Block.insz[2 * Block.nin + i] = 814;
363                 }
364                 else if (type == 7)
365                 {
366                     Block.insz[2 * Block.nin + i] = 812;
367                 }
368                 else if (type == 8)
369                 {
370                     Block.insz[2 * Block.nin + i] = 811;
371                 }
372                 else
373                 {
374                     Block.insz[2 * Block.nin + i] = 10;
375                 }
376             }
377         }
378         else
379         {
380             for (i = 0; i < Block.nin; i++)
381             {
382                 Block.insz[i] = (int) * ((double *)(&ilh[4]) + i);
383                 Block.insz[Block.nin + i] = 1;
384                 Block.insz[2 * Block.nin + i] = 10;
385             }
386         }
387
388         for (i = 0; i < Block.nin; i++)
389         {
390             switch (Block.insz[2 * Block.nin + i])
391             {
392                 case 10  :
393                     if ((Block.inptr[i] = (double *) MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(double))) == NULL)
394                     {
395                         for (j = 0; j < i; j++)
396                         {
397                             FREE(Block.inptr[j]);
398                         }
399                         FREE(Block.inptr);
400                         FREE(Block.insz);
401                         Scierror(888, _("%s : Allocation error.\n"), fname);
402                         return 0;
403                     }
404                     ptr_d = (double *) Block.inptr[i];
405                     for (j = 0; j < Block.insz[i]*Block.insz[Block.nin + i]; j++)
406                     {
407                         ptr_d[j] = 0.;
408                     }
409                     break;
410                 case 11  :
411                     if ((Block.inptr[i] = (double *) \
412                                           MALLOC(2 * Block.insz[i] * Block.insz[Block.nin + i] * sizeof(double))) == NULL)
413                     {
414                         for (j = 0; j < i; j++)
415                         {
416                             FREE(Block.inptr[j]);
417                         }
418                         FREE(Block.inptr);
419                         FREE(Block.insz);
420                         Scierror(888, _("%s : Allocation error.\n"), fname);
421                         return 0;
422                     }
423                     ptr_d = (double *) Block.inptr[i];
424                     for (j = 0; j < 2 * Block.insz[i]*Block.insz[Block.nin + i]; j++)
425                     {
426                         ptr_d[j] = 0.;
427                     }
428                     break;
429                 case 84  :
430                     if ((Block.inptr[i] = (long *) \
431                                           MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(long))) == NULL)
432                     {
433                         for (j = 0; j < i; j++)
434                         {
435                             FREE(Block.inptr[j]);
436                         }
437                         FREE(Block.inptr);
438                         FREE(Block.insz);
439                         Scierror(888, _("%s : Allocation error.\n"), fname);
440                         return 0;
441                     }
442                     ptr_l = (long *) Block.inptr[i];
443                     for (j = 0; j < Block.insz[i]*Block.insz[Block.nin + i]; j++)
444                     {
445                         ptr_l[j] = 0;
446                     }
447                     break;
448                 case 82  :
449                     if ((Block.inptr[i] = (short *) \
450                                           MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(short))) == NULL)
451                     {
452                         for (j = 0; j < i; j++)
453                         {
454                             FREE(Block.inptr[j]);
455                         }
456                         FREE(Block.inptr);
457                         FREE(Block.insz);
458                         Scierror(888, _("%s : Allocation error.\n"), fname);
459                         return 0;
460                     }
461                     ptr_s = (short *) Block.inptr[i];
462                     for (j = 0; j < Block.insz[i]*Block.insz[Block.nin + i]; j++)
463                     {
464                         ptr_s[j] = 0;
465                     }
466                     break;
467                 case 81  :
468                     if ((Block.inptr[i] = (char *) \
469                                           MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(char))) == NULL)
470                     {
471                         for (j = 0; j < i; j++)
472                         {
473                             FREE(Block.inptr[j]);
474                         }
475                         FREE(Block.inptr);
476                         FREE(Block.insz);
477                         Scierror(888, _("%s : Allocation error.\n"), fname);
478                         return 0;
479                     }
480                     ptr_c = (char *) Block.inptr[i];
481                     for (j = 0; j < Block.insz[i]*Block.insz[Block.nin + i]; j++)
482                     {
483                         ptr_c[j] = 0;
484                     }
485                     break;
486                 case 814 :
487                     if ((Block.inptr[i] = (unsigned long *) \
488                                           MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(unsigned long))) == NULL)
489                     {
490                         for (j = 0; j < i; j++)
491                         {
492                             FREE(Block.inptr[j]);
493                         }
494                         FREE(Block.inptr);
495                         FREE(Block.insz);
496                         Scierror(888, _("%s : Allocation error.\n"), fname);
497                         return 0;
498                     }
499                     ptr_ul = (unsigned long *) Block.inptr[i];
500                     for (j = 0; j < Block.insz[i]*Block.insz[Block.nin + i]; j++)
501                     {
502                         ptr_ul[j] = 0;
503                     }
504                     break;
505                 case 812 :
506                     if ((Block.inptr[i] = (unsigned short *) \
507                                           MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(unsigned short))) == NULL)
508                     {
509                         for (j = 0; j < i; j++)
510                         {
511                             FREE(Block.inptr[j]);
512                         }
513                         FREE(Block.inptr);
514                         FREE(Block.insz);
515                         Scierror(888, _("%s : Allocation error.\n"), fname);
516                         return 0;
517                     }
518                     ptr_us = (unsigned short *) Block.inptr[i];
519                     for (j = 0; j < Block.insz[i]*Block.insz[Block.nin + i]; j++)
520                     {
521                         ptr_us[j] = 0;
522                     }
523                     break;
524                 case 811 :
525                     if ((Block.inptr[i] = (unsigned char *) \
526                                           MALLOC(Block.insz[i] * Block.insz[Block.nin + i] * sizeof(unsigned char))) == NULL)
527                     {
528                         for (j = 0; j < i; j++)
529                         {
530                             FREE(Block.inptr[j]);
531                         }
532                         FREE(Block.inptr);
533                         FREE(Block.insz);
534                         Scierror(888, _("%s : Allocation error.\n"), fname);
535                         return 0;
536                     }
537                     ptr_uc = (unsigned char *) Block.inptr[i];
538                     for (j = 0; j < Block.insz[i]*Block.insz[Block.nin + i]; j++)
539                     {
540                         ptr_uc[j] = 0;
541                     }
542                     break;
543             }
544         }
545     }
546
547     /* check output ports */
548     /* 6 : model.out  */
549     n            = MlistGetFieldNumber(il1, "out");
550     ilh          = (int *) (listentry(il1, n));
551     mh           = ilh[1];
552     nh           = ilh[2];
553     Block.nout   = mh * nh;
554     Block.outsz  = NULL;
555     Block.outptr = NULL;
556     if (mh * nh != 0)
557     {
558         /* check value of out */
559         for (i = 0; i < Block.nout; i++)
560         {
561             if ((*((double *)(&ilh[4]) + i)) <= 0.)
562             {
563                 Scierror(888, _("%s : Undetermined Size. out(%d)=%d. Please adjust your model.\n"), \
564                          fname, i + 1, (int)(*((double *)(&ilh[4]) + i)));
565                 for (j = 0; j < Block.nin; j++)
566                 {
567                     FREE(Block.inptr[j]);
568                 }
569                 FREE(Block.inptr);
570                 FREE(Block.insz);
571                 return 0;
572             }
573         }
574         /* alloc outsz */
575         if ((Block.outsz = (int *) MALLOC(Block.nout * 3 * sizeof(int))) == NULL)
576         {
577             Scierror(888, _("%s : Allocation error.\n"), fname);
578             for (j = 0; j < Block.nin; j++)
579             {
580                 FREE(Block.inptr[j]);
581             }
582             FREE(Block.inptr);
583             FREE(Block.insz);
584             return 0;
585         }
586         /* alloc outptr */
587         if ((Block.outptr = (void **) MALLOC(Block.nout * sizeof(void *))) == NULL)
588         {
589             FREE(Block.outsz);
590             for (j = 0; j < Block.nin; j++)
591             {
592                 FREE(Block.inptr[j]);
593             }
594             FREE(Block.inptr);
595             FREE(Block.insz);
596             Scierror(888, _("%s : Allocation error.\n"), fname);
597             return 0;
598         }
599         /* 7 : model.out2  */
600         n    = MlistGetFieldNumber(il1, "out2");
601         ilh2 = (int *) (listentry(il1, n));
602         mh2  = ilh2[1];
603         nh2  = ilh2[2];
604         /* check value of out2 */
605         for (i = 0; i < (mh2 * nh2); i++)
606         {
607             if ((*((double *)(&ilh2[4]) + i)) <= 0.)
608             {
609                 Scierror(888, _("%s : Undetermined Size. out2(%d)=%d. Please adjust your model.\n"), \
610                          fname, i + 1, (int)(*((double *)(&ilh2[4]) + i)));
611                 for (j = 0; j < Block.nin; j++)
612                 {
613                     FREE(Block.inptr[j]);
614                 }
615                 FREE(Block.insz);
616                 FREE(Block.inptr);
617                 FREE(Block.outptr);
618                 FREE(Block.outsz);
619                 return 0;
620             }
621         }
622         /* 8 : model.outtyp  */
623         n    = MlistGetFieldNumber(il1, "outtyp");
624         ilh3 = (int *) (listentry(il1, n));
625         mh3  = ilh3[1];
626         nh3  = ilh3[2];
627         /* check value of intyp */
628         for (i = 0; i < (mh3 * nh3); i++)
629         {
630             if ((*((double *)(&ilh3[4]) + i)) <= 0.)
631             {
632                 Scierror(888, _("%s : Undetermined Type. outtyp(%d)=%d. Please adjust your model.\n"), \
633                          fname, i + 1, (int)(*((double *)(&ilh3[4]) + i)));
634                 FREE(Block.insz);
635                 FREE(Block.inptr);
636                 FREE(Block.outptr);
637                 FREE(Block.outsz);
638                 return 0;
639             }
640         }
641         if (((mh * nh) == (mh2 * nh2)) && (((mh * nh) == (mh3 * nh3))))
642         {
643             for (i = 0; i < Block.nout; i++)
644             {
645                 Block.outsz[i] = (int) * ((double *)(&ilh[4]) + i);
646                 Block.outsz[Block.nout + i] = (int) * ((double *)(&ilh2[4]) + i);
647                 type = *((double *)(&ilh3[4]) + i);
648                 if (type == 1)
649                 {
650                     Block.outsz[2 * Block.nout + i] = 10;
651                 }
652                 else if (type == 2)
653                 {
654                     Block.outsz[2 * Block.nout + i] = 11;
655                 }
656                 else if (type == 3)
657                 {
658                     Block.outsz[2 * Block.nout + i] = 84;
659                 }
660                 else if (type == 4)
661                 {
662                     Block.outsz[2 * Block.nout + i] = 82;
663                 }
664                 else if (type == 5)
665                 {
666                     Block.outsz[2 * Block.nout + i] = 81;
667                 }
668                 else if (type == 6)
669                 {
670                     Block.outsz[2 * Block.nout + i] = 814;
671                 }
672                 else if (type == 7)
673                 {
674                     Block.outsz[2 * Block.nout + i] = 812;
675                 }
676                 else if (type == 8)
677                 {
678                     Block.outsz[2 * Block.nout + i] = 811;
679                 }
680                 else
681                 {
682                     Block.outsz[2 * Block.nout + i] = 10;
683                 }
684             }
685         }
686         else
687         {
688             for (i = 0; i < Block.nout; i++)
689             {
690                 Block.outsz[i] = (int) * ((double *)(&ilh[4]) + i);
691                 Block.outsz[Block.nout + i] = 1;
692                 Block.outsz[2 * Block.nout + i] = 10;
693             }
694         }
695         for (i = 0; i < Block.nout; i++)
696         {
697             switch (Block.outsz[2 * Block.nout + i])
698             {
699                 case 10  :
700                     if ((Block.outptr[i] = (double *) \
701                                            MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(double))) == NULL)
702                     {
703                         for (j = 0; j < Block.nin; j++)
704                         {
705                             FREE(Block.inptr[j]);
706                         }
707                         FREE(Block.inptr);
708                         FREE(Block.insz);
709                         for (j = 0; j < i; j++)
710                         {
711                             FREE(Block.outptr[j]);
712                         }
713                         FREE(Block.outptr);
714                         FREE(Block.outsz);
715                         Scierror(888, _("%s : Allocation error.\n"), fname);
716                         return 0;
717                     }
718                     ptr_d = (double *) Block.outptr[i];
719                     for (j = 0; j < Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
720                     {
721                         ptr_d[j] = 0.;
722                     }
723                     break;
724                 case 11  :
725                     if ((Block.outptr[i] = (double *) \
726                                            MALLOC(2 * Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(double))) == NULL)
727                     {
728                         for (j = 0; j < Block.nin; j++)
729                         {
730                             FREE(Block.inptr[j]);
731                         }
732                         FREE(Block.inptr);
733                         FREE(Block.insz);
734                         for (j = 0; j < i; j++)
735                         {
736                             FREE(Block.outptr[j]);
737                         }
738                         FREE(Block.outptr);
739                         FREE(Block.outsz);
740                         Scierror(888, _("%s : Allocation error.\n"), fname);
741                         return 0;
742                     }
743                     ptr_d = (double *) Block.outptr[i];
744                     for (j = 0; j < 2 * Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
745                     {
746                         ptr_d[j] = 0.;
747                     }
748                     break;
749                 case 84  :
750                     if ((Block.outptr[i] = (long *) \
751                                            MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(long))) == NULL)
752                     {
753                         for (j = 0; j < Block.nin; j++)
754                         {
755                             FREE(Block.inptr[j]);
756                         }
757                         FREE(Block.inptr);
758                         FREE(Block.insz);
759                         for (j = 0; j < i; j++)
760                         {
761                             FREE(Block.outptr[j]);
762                         }
763                         FREE(Block.outptr);
764                         FREE(Block.outsz);
765                         Scierror(888, _("%s : Allocation error.\n"), fname);
766                         return 0;
767                     }
768                     ptr_l = (long *) Block.outptr[i];
769                     for (j = 0; j < Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
770                     {
771                         ptr_l[j] = 0;
772                     }
773                     break;
774                 case 82  :
775                     if ((Block.outptr[i] = (short *) \
776                                            MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(short))) == NULL)
777                     {
778                         for (j = 0; j < Block.nin; j++)
779                         {
780                             FREE(Block.inptr[j]);
781                         }
782                         FREE(Block.inptr);
783                         FREE(Block.insz);
784                         for (j = 0; j < i; j++)
785                         {
786                             FREE(Block.outptr[j]);
787                         }
788                         FREE(Block.outptr);
789                         FREE(Block.outsz);
790                         Scierror(888, _("%s : Allocation error.\n"), fname);
791                         return 0;
792                     }
793                     ptr_s = (short *) Block.outptr[i];
794                     for (j = 0; j < Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
795                     {
796                         ptr_s[j] = 0;
797                     }
798                     break;
799                 case 81  :
800                     if ((Block.outptr[i] = (char *) \
801                                            MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(char))) == NULL)
802                     {
803                         for (j = 0; j < Block.nin; j++)
804                         {
805                             FREE(Block.inptr[j]);
806                         }
807                         FREE(Block.inptr);
808                         FREE(Block.insz);
809                         for (j = 0; j < i; j++)
810                         {
811                             FREE(Block.outptr[j]);
812                         }
813                         FREE(Block.outptr);
814                         FREE(Block.outsz);
815                         Scierror(888, _("%s : Allocation error.\n"), fname);
816                         return 0;
817                     }
818                     ptr_c = (char *) Block.outptr[i];
819                     for (j = 0; j < Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
820                     {
821                         ptr_c[j] = 0;
822                     }
823                     break;
824                 case 814 :
825                     if ((Block.outptr[i] = (unsigned long *) \
826                                            MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(unsigned long))) == NULL)
827                     {
828                         for (j = 0; j < Block.nin; j++)
829                         {
830                             FREE(Block.inptr[j]);
831                         }
832                         FREE(Block.inptr);
833                         FREE(Block.insz);
834                         for (j = 0; j < i; j++)
835                         {
836                             FREE(Block.outptr[j]);
837                         }
838                         FREE(Block.outptr);
839                         FREE(Block.outsz);
840                         Scierror(888, _("%s : Allocation error.\n"), fname);
841                         return 0;
842                     }
843                     ptr_ul = (unsigned long *) Block.outptr[i];
844                     for (j = 0; j < Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
845                     {
846                         ptr_ul[j] = 0;
847                     }
848                     break;
849                 case 812 :
850                     if ((Block.outptr[i] = (unsigned short *) \
851                                            MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(unsigned short))) == NULL)
852                     {
853                         for (j = 0; j < Block.nin; j++)
854                         {
855                             FREE(Block.inptr[j]);
856                         }
857                         FREE(Block.inptr);
858                         FREE(Block.insz);
859                         for (j = 0; j < i; j++)
860                         {
861                             FREE(Block.outptr[j]);
862                         }
863                         FREE(Block.outptr);
864                         FREE(Block.outsz);
865                         Scierror(888, _("%s : Allocation error.\n"), fname);
866                         return 0;
867                     }
868                     ptr_us = (unsigned short *) Block.outptr[i];
869                     for (j = 0; j < Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
870                     {
871                         ptr_us[j] = 0;
872                     }
873                     break;
874                 case 811 :
875                     if ((Block.outptr[i] = (unsigned char *) \
876                                            MALLOC(Block.outsz[i] * Block.outsz[Block.nout + i] * sizeof(unsigned char))) == NULL)
877                     {
878                         for (j = 0; j < Block.nin; j++)
879                         {
880                             FREE(Block.inptr[j]);
881                         }
882                         FREE(Block.inptr);
883                         FREE(Block.insz);
884                         for (j = 0; j < i; j++)
885                         {
886                             FREE(Block.outptr[j]);
887                         }
888                         FREE(Block.outptr);
889                         FREE(Block.outsz);
890                         Scierror(888, _("%s : Allocation error.\n"), fname);
891                         return 0;
892                     }
893                     ptr_uc = (unsigned char *) Block.outptr[i];
894                     for (j = 0; j < Block.outsz[i]*Block.outsz[Block.nout + i]; j++)
895                     {
896                         ptr_uc[j] = 0;
897                     }
898                     break;
899             }
900         }
901     }
902
903     /* event input port */
904     /* 9 : model.evtin  */
905
906     /* event output port  */
907     /* 10 : model.evtout  */
908     n            = MlistGetFieldNumber(il1, "evtout");
909     ilh          = (int *) (listentry(il1, n));
910     mh           = ilh[1];
911     nh           = ilh[2];
912     Block.nevout = mh * nh;
913     Block.evout  = NULL;
914     if (mh * nh != 0)
915     {
916         if ((Block.evout = (double *) MALLOC(Block.nevout * sizeof(double))) == NULL)
917         {
918             for (j = 0; j < Block.nin; j++)
919             {
920                 FREE(Block.inptr[j]);
921             }
922             FREE(Block.inptr);
923             FREE(Block.insz);
924             for (j = 0; j < Block.nout; j++)
925             {
926                 FREE(Block.outptr[j]);
927             }
928             FREE(Block.outptr);
929             FREE(Block.outsz);
930             Scierror(888, _("%s : Allocation error.\n"), fname);
931             return 0;
932         }
933         n            = MlistGetFieldNumber(il1, "firing");
934         ilh2         = (int *) (listentry(il1, n));
935         mh2          = ilh2[1];
936         nh2          = ilh2[2];
937         if ((mh * nh) == (mh2 * nh2))
938         {
939             for (j = 0; j < Block.nevout; j++)
940             {
941                 Block.evout[j] = *((double *)(&ilh2[4]) + j);
942             }
943         }
944         else
945         {
946             for (j = 0; j < Block.nevout; j++)
947             {
948                 Block.evout[j] = -1.0;
949             }
950         }
951     }
952
953     /* continuous state  */
954     /* 11 : model.state  */
955     n            = MlistGetFieldNumber(il1, "state");
956     ilh          = (int *) (listentry(il1, n));
957     mh           = ilh[1];
958     nh           = ilh[2];
959     Block.nx     = mh * nh;
960     Block.x      = NULL;
961     Block.xprop  = NULL;
962     Block.xd     = NULL;
963     Block.res    = NULL;
964     if (mh * nh != 0)
965     {
966         /* x */
967         if ((Block.x = (double *) MALLOC(Block.nx * sizeof(double))) == NULL)
968         {
969             for (j = 0; j < Block.nin; j++)
970             {
971                 FREE(Block.inptr[j]);
972             }
973             FREE(Block.inptr);
974             FREE(Block.insz);
975             for (j = 0; j < Block.nout; j++)
976             {
977                 FREE(Block.outptr[j]);
978             }
979             FREE(Block.outptr);
980             FREE(Block.outsz);
981             FREE(Block.evout);
982             Scierror(888, _("%s : Allocation error.\n"), fname);
983             return 0;
984         }
985
986         for (j = 0; j < Block.nx; j++)
987         {
988             Block.x[j] = *((double *)(&ilh[4]) + j);
989         }
990
991         /* xd */
992         if ((Block.xd = (double *) MALLOC(Block.nx * sizeof(double))) == NULL)
993         {
994             for (j = 0; j < Block.nin; j++)
995             {
996                 FREE(Block.inptr[j]);
997             }
998             FREE(Block.inptr);
999             FREE(Block.insz);
1000             for (j = 0; j < Block.nout; j++)
1001             {
1002                 FREE(Block.outptr[j]);
1003             }
1004             FREE(Block.outptr);
1005             FREE(Block.outsz);
1006             FREE(Block.evout);
1007             FREE(Block.x);
1008             Scierror(888, _("%s : Allocation error.\n"), fname);
1009             return 0;
1010         }
1011
1012         for (j = 0; j < Block.nx; j++)
1013         {
1014             Block.xd[j] = 0.;
1015         }
1016         /* xprop */
1017         if ((Block.xprop = (int *) MALLOC(Block.nx * sizeof(int))) == NULL)
1018         {
1019             for (j = 0; j < Block.nin; j++)
1020             {
1021                 FREE(Block.inptr[j]);
1022             }
1023             FREE(Block.inptr);
1024             FREE(Block.insz);
1025             for (j = 0; j < Block.nout; j++)
1026             {
1027                 FREE(Block.outptr[j]);
1028             }
1029             FREE(Block.outptr);
1030             FREE(Block.outsz);
1031             FREE(Block.evout);
1032             FREE(Block.x);
1033             FREE(Block.xd);
1034             Scierror(888, _("%s : Allocation error.\n"), fname);
1035             return 0;
1036         }
1037
1038         for (j = 0; j < Block.nx; j++)
1039         {
1040             Block.xprop[j] = 1;
1041         }
1042         /* res */
1043         /*if (blktyp>10000) {*/
1044         if ((Block.res = (double *) MALLOC(Block.nx * sizeof(double))) == NULL)
1045         {
1046             for (j = 0; j < Block.nin; j++)
1047             {
1048                 FREE(Block.inptr[j]);
1049             }
1050             FREE(Block.inptr);
1051             FREE(Block.insz);
1052             for (j = 0; j < Block.nout; j++)
1053             {
1054                 FREE(Block.outptr[j]);
1055             }
1056             FREE(Block.outptr);
1057             FREE(Block.outsz);
1058             FREE(Block.evout);
1059             FREE(Block.x);
1060             FREE(Block.xd);
1061             FREE(Block.xprop);
1062             Scierror(888, _("%s : Allocation error.\n"), fname);
1063             return 0;
1064         }
1065
1066         for (j = 0; j < Block.nx; j++)
1067         {
1068             Block.res[j] = 0.;
1069         }
1070         /*}*/
1071     }
1072
1073     /* discrete state  */
1074     /* 12 : model.dstate  */
1075     n            = MlistGetFieldNumber(il1, "dstate");
1076     ilh          = (int *) (listentry(il1, n));
1077     mh           = ilh[1];
1078     nh           = ilh[2];
1079     Block.nz     = mh * nh;
1080     Block.z      = NULL;
1081
1082     if (mh * nh != 0)
1083     {
1084         if ((Block.z = (double *) MALLOC(Block.nz * sizeof(double))) == NULL)
1085         {
1086             for (j = 0; j < Block.nin; j++)
1087             {
1088                 FREE(Block.inptr[j]);
1089             }
1090             FREE(Block.inptr);
1091             FREE(Block.insz);
1092             for (j = 0; j < Block.nout; j++)
1093             {
1094                 FREE(Block.outptr[j]);
1095             }
1096             FREE(Block.outptr);
1097             FREE(Block.outsz);
1098             FREE(Block.evout);
1099             FREE(Block.x);
1100             FREE(Block.xd);
1101             FREE(Block.xprop);
1102             FREE(Block.res);
1103             Scierror(888, _("%s : Allocation error.\n"), fname);
1104             return 0;
1105         }
1106
1107         for (j = 0; j < Block.nz; j++)
1108         {
1109             Block.z[j] = *((double *)(&ilh[4]) + j);
1110         }
1111     }
1112
1113     /* discrete object state  */
1114     /* 13 : model.odstate  */
1115     n            = MlistGetFieldNumber(il1, "odstate");
1116     ilh          = (int *) (listentry(il1, n));
1117     mh           = ilh[1];
1118     nh           = ilh[2];
1119     Block.noz    = mh * nh;
1120     Block.ozsz   = NULL;
1121     Block.oztyp  = NULL;
1122     Block.ozptr  = NULL;
1123     if (mh * nh != 0)
1124     {
1125         if ((Block.ozsz = (int *) MALLOC(2 * Block.noz * sizeof(int))) == NULL)
1126         {
1127             for (j = 0; j < Block.nin; j++)
1128             {
1129                 FREE(Block.inptr[j]);
1130             }
1131             FREE(Block.inptr);
1132             FREE(Block.insz);
1133             for (j = 0; j < Block.nout; j++)
1134             {
1135                 FREE(Block.outptr[j]);
1136             }
1137             FREE(Block.outptr);
1138             FREE(Block.outsz);
1139             FREE(Block.evout);
1140             FREE(Block.x);
1141             FREE(Block.xd);
1142             FREE(Block.xprop);
1143             FREE(Block.res);
1144             FREE(Block.z);
1145             Scierror(888, _("%s : Allocation error.\n"), fname);
1146             return 0;
1147         }
1148
1149         if ((Block.oztyp = (int *) MALLOC(Block.noz * sizeof(int))) == NULL)
1150         {
1151             for (j = 0; j < Block.nin; j++)
1152             {
1153                 FREE(Block.inptr[j]);
1154             }
1155             FREE(Block.inptr);
1156             FREE(Block.insz);
1157             for (j = 0; j < Block.nout; j++)
1158             {
1159                 FREE(Block.outptr[j]);
1160             }
1161             FREE(Block.outptr);
1162             FREE(Block.outsz);
1163             FREE(Block.evout);
1164             FREE(Block.x);
1165             FREE(Block.xd);
1166             FREE(Block.xprop);
1167             FREE(Block.res);
1168             FREE(Block.z);
1169             FREE(Block.ozsz);
1170             Scierror(888, _("%s : Allocation error.\n"), fname);
1171             return 0;
1172         }
1173
1174         if ((Block.ozptr = (void **) MALLOC(Block.noz * sizeof(void *))) == NULL)
1175         {
1176             for (j = 0; j < Block.nin; j++)
1177             {
1178                 FREE(Block.inptr[j]);
1179             }
1180             FREE(Block.inptr);
1181             FREE(Block.insz);
1182             for (j = 0; j < Block.nout; j++)
1183             {
1184                 FREE(Block.outptr[j]);
1185             }
1186             FREE(Block.outptr);
1187             FREE(Block.outsz);
1188             FREE(Block.evout);
1189             FREE(Block.x);
1190             FREE(Block.xd);
1191             FREE(Block.xprop);
1192             FREE(Block.res);
1193             FREE(Block.z);
1194             FREE(Block.ozsz);
1195             FREE(Block.oztyp);
1196             Scierror(888, _("%s : Allocation error.\n"), fname);
1197             return 0;
1198         }
1199
1200         for (i = 0; i < mh * nh; i++)
1201         {
1202             ilh2 = (int *) (listentry(ilh, i + 1));
1203             mh2  = ilh2[1];
1204             nh2  = ilh2[2];
1205             Block.ozsz[i] = mh2;
1206             Block.ozsz[Block.noz + i] = nh2;
1207             if (ilh2[0] == 1)
1208             {
1209                 if (ilh2[3] == 0)
1210                 {
1211                     Block.oztyp[i] = 10;
1212                     if ((Block.ozptr[i] = (double *) MALLOC(mh2 * nh2 * sizeof(double))) == NULL)
1213                     {
1214                         for (j = 0; j < Block.nin; j++)
1215                         {
1216                             FREE(Block.inptr[j]);
1217                         }
1218                         FREE(Block.inptr);
1219                         FREE(Block.insz);
1220                         for (j = 0; j < Block.nout; j++)
1221                         {
1222                             FREE(Block.outptr[j]);
1223                         }
1224                         FREE(Block.outptr);
1225                         FREE(Block.outsz);
1226                         FREE(Block.evout);
1227                         FREE(Block.x);
1228                         FREE(Block.xd);
1229                         FREE(Block.xprop);
1230                         FREE(Block.res);
1231                         FREE(Block.z);
1232                         FREE(Block.ozsz);
1233                         FREE(Block.oztyp);
1234                         for (j = 0; j < i; j++)
1235                         {
1236                             FREE(Block.ozptr[j]);
1237                         }
1238                         Scierror(888, _("%s : Allocation error.\n"), fname);
1239                         return 0;
1240                     }
1241                     ptr_d = (double *) Block.ozptr[i];
1242                     for (j = 0; j < mh2 * nh2; j++)
1243                     {
1244                         ptr_d[j] = *((double *)(&ilh2[4]) + j);
1245                     }
1246                 }
1247                 else if (ilh2[3] == 1)
1248                 {
1249                     Block.oztyp[i] = 11;
1250                     if ((Block.ozptr[i] = (double *) MALLOC(2 * mh2 * nh2 * sizeof(double))) == NULL)
1251                     {
1252                         for (j = 0; j < Block.nin; j++)
1253                         {
1254                             FREE(Block.inptr[j]);
1255                         }
1256                         FREE(Block.inptr);
1257                         FREE(Block.insz);
1258                         for (j = 0; j < Block.nout; j++)
1259                         {
1260                             FREE(Block.outptr[j]);
1261                         }
1262                         FREE(Block.outptr);
1263                         FREE(Block.outsz);
1264                         FREE(Block.evout);
1265                         FREE(Block.x);
1266                         FREE(Block.xd);
1267                         FREE(Block.xprop);
1268                         FREE(Block.res);
1269                         FREE(Block.z);
1270                         FREE(Block.ozsz);
1271                         FREE(Block.oztyp);
1272                         for (j = 0; j < i; j++)
1273                         {
1274                             FREE(Block.ozptr[j]);
1275                         }
1276                         Scierror(888, _("%s : Allocation error.\n"), fname);
1277                         return 0;
1278                     }
1279                     ptr_d = (double *) Block.ozptr[i];
1280                     for (j = 0; j < 2 * mh2 * nh2; j++)
1281                     {
1282                         ptr_d[j] = *((double *)(&ilh2[4]) + j);
1283                     }
1284                 }
1285             }
1286             else if (ilh2[0] == 8)
1287             {
1288                 if (ilh2[3] == 4)
1289                 {
1290                     Block.oztyp[i] = 84;
1291                     if ((Block.ozptr[i] = (long *) MALLOC(mh2 * nh2 * sizeof(long))) == NULL)
1292                     {
1293                         for (j = 0; j < Block.nin; j++)
1294                         {
1295                             FREE(Block.inptr[j]);
1296                         }
1297                         FREE(Block.inptr);
1298                         FREE(Block.insz);
1299                         for (j = 0; j < Block.nout; j++)
1300                         {
1301                             FREE(Block.outptr[j]);
1302                         }
1303                         FREE(Block.outptr);
1304                         FREE(Block.outsz);
1305                         FREE(Block.evout);
1306                         FREE(Block.x);
1307                         FREE(Block.xd);
1308                         FREE(Block.xprop);
1309                         FREE(Block.res);
1310                         FREE(Block.z);
1311                         FREE(Block.ozsz);
1312                         FREE(Block.oztyp);
1313                         for (j = 0; j < i; j++)
1314                         {
1315                             FREE(Block.ozptr[j]);
1316                         }
1317                         Scierror(888, _("%s : Allocation error.\n"), fname);
1318                         return 0;
1319                     }
1320                     ptr_l = (long *) Block.ozptr[i];
1321                     for (j = 0; j < mh2 * nh2; j++)
1322                     {
1323                         ptr_l[j] = *((long *)(&ilh2[4]) + j);
1324                     }
1325                 }
1326                 else if (ilh2[3] == 2)
1327                 {
1328                     Block.oztyp[i] = 82;
1329                     if ((Block.ozptr[i] = (short *) MALLOC(mh2 * nh2 * sizeof(short))) == NULL)
1330                     {
1331                         for (j = 0; j < Block.nin; j++)
1332                         {
1333                             FREE(Block.inptr[j]);
1334                         }
1335                         FREE(Block.inptr);
1336                         FREE(Block.insz);
1337                         for (j = 0; j < Block.nout; j++)
1338                         {
1339                             FREE(Block.outptr[j]);
1340                         }
1341                         FREE(Block.outptr);
1342                         FREE(Block.outsz);
1343                         FREE(Block.evout);
1344                         FREE(Block.x);
1345                         FREE(Block.xd);
1346                         FREE(Block.xprop);
1347                         FREE(Block.res);
1348                         FREE(Block.z);
1349                         FREE(Block.ozsz);
1350                         FREE(Block.oztyp);
1351                         for (j = 0; j < i; j++)
1352                         {
1353                             FREE(Block.ozptr[j]);
1354                         }
1355                         Scierror(888, _("%s : Allocation error.\n"), fname);
1356                         return 0;
1357                     }
1358                     ptr_s = (short *) Block.ozptr[i];
1359                     for (j = 0; j < mh2 * nh2; j++)
1360                     {
1361                         ptr_s[j] = *((short *)(&ilh2[4]) + j);
1362                     }
1363                 }
1364                 else if (ilh2[3] == 1)
1365                 {
1366                     Block.oztyp[i] = 81;
1367                     if ((Block.ozptr[i] = (char *) MALLOC(mh2 * nh2 * sizeof(char))) == NULL)
1368                     {
1369                         for (j = 0; j < Block.nin; j++)
1370                         {
1371                             FREE(Block.inptr[j]);
1372                         }
1373                         FREE(Block.inptr);
1374                         FREE(Block.insz);
1375                         for (j = 0; j < Block.nout; j++)
1376                         {
1377                             FREE(Block.outptr[j]);
1378                         }
1379                         FREE(Block.outptr);
1380                         FREE(Block.outsz);
1381                         FREE(Block.evout);
1382                         FREE(Block.x);
1383                         FREE(Block.xd);
1384                         FREE(Block.xprop);
1385                         FREE(Block.res);
1386                         FREE(Block.z);
1387                         FREE(Block.ozsz);
1388                         FREE(Block.oztyp);
1389                         for (j = 0; j < i; j++)
1390                         {
1391                             FREE(Block.ozptr[j]);
1392                         }
1393                         Scierror(888, _("%s : Allocation error.\n"), fname);
1394                         return 0;
1395                     }
1396                     ptr_c = (char *) Block.ozptr[i];
1397                     for (j = 0; j < mh2 * nh2; j++)
1398                     {
1399                         ptr_c[j] = *((char *)(&ilh2[4]) + j);
1400                     }
1401                 }
1402                 else if (ilh2[3] == 14)
1403                 {
1404                     Block.oztyp[i] = 814;
1405                     if ((Block.ozptr[i] = (unsigned long *) MALLOC(mh2 * nh2 * sizeof(unsigned long))) == NULL)
1406                     {
1407                         for (j = 0; j < Block.nin; j++)
1408                         {
1409                             FREE(Block.inptr[j]);
1410                         }
1411                         FREE(Block.inptr);
1412                         FREE(Block.insz);
1413                         for (j = 0; j < Block.nout; j++)
1414                         {
1415                             FREE(Block.outptr[j]);
1416                         }
1417                         FREE(Block.outptr);
1418                         FREE(Block.outsz);
1419                         FREE(Block.evout);
1420                         FREE(Block.x);
1421                         FREE(Block.xd);
1422                         FREE(Block.xprop);
1423                         FREE(Block.res);
1424                         FREE(Block.z);
1425                         FREE(Block.ozsz);
1426                         FREE(Block.oztyp);
1427                         for (j = 0; j < i; j++)
1428                         {
1429                             FREE(Block.ozptr[j]);
1430                         }
1431                         Scierror(888, _("%s : Allocation error.\n"), fname);
1432                         return 0;
1433                     }
1434                     ptr_ul = (unsigned long *) Block.ozptr[i];
1435                     for (j = 0; j < mh2 * nh2; j++)
1436                     {
1437                         ptr_ul[j] = *((unsigned long *)(&ilh2[4]) + j);
1438                     }
1439                 }
1440                 else if (ilh2[3] == 12)
1441                 {
1442                     Block.oztyp[i] = 812;
1443                     if ((Block.ozptr[i] = (unsigned short *) MALLOC(mh2 * nh2 * sizeof(unsigned short))) == NULL)
1444                     {
1445                         for (j = 0; j < Block.nin; j++)
1446                         {
1447                             FREE(Block.inptr[j]);
1448                         }
1449                         FREE(Block.inptr);
1450                         FREE(Block.insz);
1451                         for (j = 0; j < Block.nout; j++)
1452                         {
1453                             FREE(Block.outptr[j]);
1454                         }
1455                         FREE(Block.outptr);
1456                         FREE(Block.outsz);
1457                         FREE(Block.evout);
1458                         FREE(Block.x);
1459                         FREE(Block.xd);
1460                         FREE(Block.xprop);
1461                         FREE(Block.res);
1462                         FREE(Block.z);
1463                         FREE(Block.ozsz);
1464                         FREE(Block.oztyp);
1465                         for (j = 0; j < i; j++)
1466                         {
1467                             FREE(Block.ozptr[j]);
1468                         }
1469                         Scierror(888, _("%s : Allocation error.\n"), fname);
1470                         return 0;
1471                     }
1472                     ptr_us = (unsigned short *) Block.ozptr[i];
1473                     for (j = 0; j < mh2 * nh2; j++)
1474                     {
1475                         ptr_us[j] = *((unsigned short *)(&ilh2[4]) + j);
1476                     }
1477                 }
1478                 else if (ilh2[3] == 11)
1479                 {
1480                     Block.oztyp[i] = 811;
1481                     if ((Block.ozptr[i] = (unsigned char *) MALLOC(mh2 * nh2 * sizeof(unsigned char))) == NULL)
1482                     {
1483                         for (j = 0; j < Block.nin; j++)
1484                         {
1485                             FREE(Block.inptr[j]);
1486                         }
1487                         FREE(Block.inptr);
1488                         FREE(Block.insz);
1489                         for (j = 0; j < Block.nout; j++)
1490                         {
1491                             FREE(Block.outptr[j]);
1492                         }
1493                         FREE(Block.outptr);
1494                         FREE(Block.outsz);
1495                         FREE(Block.evout);
1496                         FREE(Block.x);
1497                         FREE(Block.xd);
1498                         FREE(Block.xprop);
1499                         FREE(Block.res);
1500                         FREE(Block.z);
1501                         FREE(Block.ozsz);
1502                         FREE(Block.oztyp);
1503                         for (j = 0; j < i; j++)
1504                         {
1505                             FREE(Block.ozptr[j]);
1506                         }
1507                         Scierror(888, _("%s : Allocation error.\n"), fname);
1508                         return 0;
1509                     }
1510                     ptr_uc = (unsigned char *) Block.ozptr[i];
1511                     for (j = 0; j < mh2 * nh2; j++)
1512                     {
1513                         ptr_uc[j] = *((unsigned char *)(&ilh2[4]) + j);
1514                     }
1515                 }
1516             }
1517         }
1518     }
1519
1520     /* real parameters */
1521     /* 14 : model.rpar  */
1522     n            = MlistGetFieldNumber(il1, "rpar");
1523     ilh          = (int *) (listentry(il1, n));
1524     mh           = ilh[1];
1525     nh           = ilh[2];
1526     Block.nrpar  = mh * nh;
1527     Block.rpar   = NULL;
1528     if (mh * nh != 0)
1529     {
1530         if ((Block.rpar = (double *) MALLOC(Block.nrpar * sizeof(double))) == NULL)
1531         {
1532             for (j = 0; j < Block.nin; j++)
1533             {
1534                 FREE(Block.inptr[j]);
1535             }
1536             FREE(Block.inptr);
1537             FREE(Block.insz);
1538             for (j = 0; j < Block.nout; j++)
1539             {
1540                 FREE(Block.outptr[j]);
1541             }
1542             FREE(Block.outptr);
1543             FREE(Block.outsz);
1544             FREE(Block.evout);
1545             FREE(Block.x);
1546             FREE(Block.xd);
1547             FREE(Block.xprop);
1548             FREE(Block.res);
1549             FREE(Block.z);
1550             FREE(Block.ozsz);
1551             FREE(Block.oztyp);
1552             for (j = 0; j < Block.noz; j++)
1553             {
1554                 FREE(Block.ozptr[j]);
1555             }
1556             Scierror(888, _("%s : Allocation error.\n"), fname);
1557             return 0;
1558         }
1559         for (j = 0; j < Block.nrpar; j++)
1560         {
1561             Block.rpar[j] = *((double *)(&ilh[4]) + j);
1562         }
1563     }
1564
1565     /* integer parameters */
1566     /* 15 : model.ipar  */
1567     n            = MlistGetFieldNumber(il1, "ipar");
1568     ilh          = (int *) (listentry(il1, n));
1569     mh           = ilh[1];
1570     nh           = ilh[2];
1571     Block.nipar  = mh * nh;
1572     Block.ipar   = NULL;
1573     if (mh * nh != 0)
1574     {
1575         if ((Block.ipar = (int *) MALLOC(Block.nipar * sizeof(int))) == NULL)
1576         {
1577             for (j = 0; j < Block.nin; j++)
1578             {
1579                 FREE(Block.inptr[j]);
1580             }
1581             FREE(Block.inptr);
1582             FREE(Block.insz);
1583             for (j = 0; j < Block.nout; j++)
1584             {
1585                 FREE(Block.outptr[j]);
1586             }
1587             FREE(Block.outptr);
1588             FREE(Block.outsz);
1589             FREE(Block.evout);
1590             FREE(Block.x);
1591             FREE(Block.xd);
1592             FREE(Block.xprop);
1593             FREE(Block.res);
1594             FREE(Block.z);
1595             FREE(Block.ozsz);
1596             FREE(Block.oztyp);
1597             for (j = 0; j < Block.noz; j++)
1598             {
1599                 FREE(Block.ozptr[j]);
1600             }
1601             FREE(Block.rpar);
1602             Scierror(888, _("%s : Allocation error.\n"), fname);
1603             return 0;
1604         }
1605
1606         for (j = 0; j < Block.nipar; j++)
1607         {
1608             Block.ipar[j] = (int) * ((double *)(&ilh[4]) + j);
1609         }
1610     }
1611
1612     /* object parameters */
1613     /* 16 : model.opar  */
1614     n             = MlistGetFieldNumber(il1, "opar");
1615     ilh           = (int *) (listentry(il1, n));
1616     mh            = ilh[1];
1617     nh            = ilh[2];
1618     Block.nopar   = mh * nh;
1619     Block.oparsz  = NULL;
1620     Block.opartyp = NULL;
1621     Block.oparptr = NULL;
1622     if (mh * nh != 0)
1623     {
1624         if ((Block.oparsz = (int *) MALLOC(2 * Block.nopar * sizeof(int))) == NULL)
1625         {
1626             for (j = 0; j < Block.nin; j++)
1627             {
1628                 FREE(Block.inptr[j]);
1629             }
1630             FREE(Block.inptr);
1631             FREE(Block.insz);
1632             for (j = 0; j < Block.nout; j++)
1633             {
1634                 FREE(Block.outptr[j]);
1635             }
1636             FREE(Block.outptr);
1637             FREE(Block.outsz);
1638             FREE(Block.evout);
1639             FREE(Block.x);
1640             FREE(Block.xd);
1641             FREE(Block.xprop);
1642             FREE(Block.res);
1643             FREE(Block.z);
1644             FREE(Block.ozsz);
1645             FREE(Block.oztyp);
1646             for (j = 0; j < Block.noz; j++)
1647             {
1648                 FREE(Block.ozptr[j]);
1649             }
1650             FREE(Block.rpar);
1651             FREE(Block.ipar);
1652             Scierror(888, _("%s : Allocation error.\n"), fname);
1653             return 0;
1654         }
1655
1656         if ((Block.opartyp = (int *) MALLOC(Block.nopar * sizeof(int))) == NULL)
1657         {
1658             for (j = 0; j < Block.nin; j++)
1659             {
1660                 FREE(Block.inptr[j]);
1661             }
1662             FREE(Block.inptr);
1663             FREE(Block.insz);
1664             for (j = 0; j < Block.nout; j++)
1665             {
1666                 FREE(Block.outptr[j]);
1667             }
1668             FREE(Block.outptr);
1669             FREE(Block.outsz);
1670             FREE(Block.evout);
1671             FREE(Block.x);
1672             FREE(Block.xd);
1673             FREE(Block.xprop);
1674             FREE(Block.res);
1675             FREE(Block.z);
1676             FREE(Block.ozsz);
1677             FREE(Block.oztyp);
1678             for (j = 0; j < Block.noz; j++)
1679             {
1680                 FREE(Block.ozptr[j]);
1681             }
1682             FREE(Block.rpar);
1683             FREE(Block.ipar);
1684             FREE(Block.oparsz);
1685             Scierror(888, _("%s : Allocation error.\n"), fname);
1686             return 0;
1687         }
1688
1689         if ((Block.oparptr = (void **) MALLOC(Block.nopar * sizeof(void *))) == NULL)
1690         {
1691             for (j = 0; j < Block.nin; j++)
1692             {
1693                 FREE(Block.inptr[j]);
1694             }
1695             FREE(Block.inptr);
1696             FREE(Block.insz);
1697             for (j = 0; j < Block.nout; j++)
1698             {
1699                 FREE(Block.outptr[j]);
1700             }
1701             FREE(Block.outptr);
1702             FREE(Block.outsz);
1703             FREE(Block.evout);
1704             FREE(Block.x);
1705             FREE(Block.xd);
1706             FREE(Block.xprop);
1707             FREE(Block.res);
1708             FREE(Block.z);
1709             FREE(Block.ozsz);
1710             FREE(Block.oztyp);
1711             for (j = 0; j < Block.noz; j++)
1712             {
1713                 FREE(Block.ozptr[j]);
1714             }
1715             FREE(Block.rpar);
1716             FREE(Block.ipar);
1717             FREE(Block.oparsz);
1718             FREE(Block.opartyp);
1719             Scierror(888, _("%s : Allocation error.\n"), fname);
1720             return 0;
1721         }
1722
1723         for (i = 0; i < mh * nh; i++)
1724         {
1725             ilh2 = (int *) (listentry(ilh, i + 1));
1726             mh2  = ilh2[1];
1727             nh2  = ilh2[2];
1728             Block.oparsz[i] = mh2;
1729             Block.oparsz[Block.nopar + i] = nh2;
1730             if (ilh2[0] == 1)
1731             {
1732                 if (ilh2[3] == 0)
1733                 {
1734                     Block.opartyp[i] = 10;
1735                     if ((Block.oparptr[i] = (double *) MALLOC(mh2 * nh2 * sizeof(double))) == NULL)
1736                     {
1737                         for (j = 0; j < Block.nin; j++)
1738                         {
1739                             FREE(Block.inptr[j]);
1740                         }
1741                         FREE(Block.inptr);
1742                         FREE(Block.insz);
1743                         for (j = 0; j < Block.nout; j++)
1744                         {
1745                             FREE(Block.outptr[j]);
1746                         }
1747                         FREE(Block.outptr);
1748                         FREE(Block.outsz);
1749                         FREE(Block.evout);
1750                         FREE(Block.x);
1751                         FREE(Block.xd);
1752                         FREE(Block.xprop);
1753                         FREE(Block.res);
1754                         FREE(Block.z);
1755                         FREE(Block.ozsz);
1756                         FREE(Block.oztyp);
1757                         for (j = 0; j < Block.noz; j++)
1758                         {
1759                             FREE(Block.ozptr[j]);
1760                         }
1761                         FREE(Block.rpar);
1762                         FREE(Block.ipar);
1763                         FREE(Block.oparsz);
1764                         FREE(Block.opartyp);
1765                         for (j = 0; j < i; j++)
1766                         {
1767                             FREE(Block.oparptr[j]);
1768                         }
1769                         Scierror(888, _("%s : Allocation error.\n"), fname);
1770                         return 0;
1771                     }
1772                     ptr_d = (double *) Block.oparptr[i];
1773                     for (j = 0; j < mh2 * nh2; j++)
1774                     {
1775                         ptr_d[j] = *((double *)(&ilh2[4]) + j);
1776                     }
1777                 }
1778                 else if (ilh2[3] == 1)
1779                 {
1780                     Block.opartyp[i] = 11;
1781                     if ((Block.oparptr[i] = (double *) MALLOC(2 * mh2 * nh2 * sizeof(double))) == NULL)
1782                     {
1783                         for (j = 0; j < Block.nin; j++)
1784                         {
1785                             FREE(Block.inptr[j]);
1786                         }
1787                         FREE(Block.inptr);
1788                         FREE(Block.insz);
1789                         for (j = 0; j < Block.nout; j++)
1790                         {
1791                             FREE(Block.outptr[j]);
1792                         }
1793                         FREE(Block.outptr);
1794                         FREE(Block.outsz);
1795                         FREE(Block.evout);
1796                         FREE(Block.x);
1797                         FREE(Block.xd);
1798                         FREE(Block.xprop);
1799                         FREE(Block.res);
1800                         FREE(Block.z);
1801                         FREE(Block.ozsz);
1802                         FREE(Block.oztyp);
1803                         for (j = 0; j < Block.noz; j++)
1804                         {
1805                             FREE(Block.ozptr[j]);
1806                         }
1807                         FREE(Block.rpar);
1808                         FREE(Block.ipar);
1809                         FREE(Block.oparsz);
1810                         FREE(Block.opartyp);
1811                         for (j = 0; j < i; j++)
1812                         {
1813                             FREE(Block.oparptr[j]);
1814                         }
1815                         Scierror(888, _("%s : Allocation error.\n"), fname);
1816                         return 0;
1817                     }
1818
1819                     ptr_d = (double *) Block.oparptr[i];
1820                     for (j = 0; j < 2 * mh2 * nh2; j++)
1821                     {
1822                         ptr_d[j] = *((double *)(&ilh2[4]) + j);
1823                     }
1824                 }
1825             }
1826             else if (ilh2[0] == 8)
1827             {
1828                 if (ilh2[3] == 4)
1829                 {
1830                     Block.opartyp[i] = 84;
1831                     if ((Block.oparptr[i] = (long *) MALLOC(mh2 * nh2 * sizeof(long))) == NULL)
1832                     {
1833                         for (j = 0; j < Block.nin; j++)
1834                         {
1835                             FREE(Block.inptr[j]);
1836                         }
1837                         FREE(Block.inptr);
1838                         FREE(Block.insz);
1839                         for (j = 0; j < Block.nout; j++)
1840                         {
1841                             FREE(Block.outptr[j]);
1842                         }
1843                         FREE(Block.outptr);
1844                         FREE(Block.outsz);
1845                         FREE(Block.evout);
1846                         FREE(Block.x);
1847                         FREE(Block.xd);
1848                         FREE(Block.xprop);
1849                         FREE(Block.res);
1850                         FREE(Block.z);
1851                         FREE(Block.ozsz);
1852                         FREE(Block.oztyp);
1853                         for (j = 0; j < Block.noz; j++)
1854                         {
1855                             FREE(Block.ozptr[j]);
1856                         }
1857                         FREE(Block.rpar);
1858                         FREE(Block.ipar);
1859                         FREE(Block.oparsz);
1860                         FREE(Block.opartyp);
1861                         for (j = 0; j < i; j++)
1862                         {
1863                             FREE(Block.oparptr[j]);
1864                         }
1865                         Scierror(888, _("%s : Allocation error.\n"), fname);
1866                         return 0;
1867                     }
1868                     ptr_l = (long *) Block.oparptr[i];
1869                     for (j = 0; j < mh2 * nh2; j++)
1870                     {
1871                         ptr_l[j] = *((long *)(&ilh2[4]) + j);
1872                     }
1873                 }
1874                 else if (ilh2[3] == 2)
1875                 {
1876                     Block.opartyp[i] = 82;
1877                     if ((Block.oparptr[i] = (short *) MALLOC(mh2 * nh2 * sizeof(short))) == NULL)
1878                     {
1879                         for (j = 0; j < Block.nin; j++)
1880                         {
1881                             FREE(Block.inptr[j]);
1882                         }
1883                         FREE(Block.inptr);
1884                         FREE(Block.insz);
1885                         for (j = 0; j < Block.nout; j++)
1886                         {
1887                             FREE(Block.outptr[j]);
1888                         }
1889                         FREE(Block.outptr);
1890                         FREE(Block.outsz);
1891                         FREE(Block.evout);
1892                         FREE(Block.x);
1893                         FREE(Block.xd);
1894                         FREE(Block.xprop);
1895                         FREE(Block.res);
1896                         FREE(Block.z);
1897                         FREE(Block.ozsz);
1898                         FREE(Block.oztyp);
1899                         for (j = 0; j < Block.noz; j++)
1900                         {
1901                             FREE(Block.ozptr[j]);
1902                         }
1903                         FREE(Block.rpar);
1904                         FREE(Block.ipar);
1905                         FREE(Block.oparsz);
1906                         FREE(Block.opartyp);
1907                         for (j = 0; j < i; j++)
1908                         {
1909                             FREE(Block.oparptr[j]);
1910                         }
1911                         Scierror(888, _("%s : Allocation error.\n"), fname);
1912                         return 0;
1913                     }
1914                     ptr_s = (short *) Block.oparptr[i];
1915                     for (j = 0; j < mh2 * nh2; j++)
1916                     {
1917                         ptr_s[j] = *((short *)(&ilh2[4]) + j);
1918                     }
1919                 }
1920                 else if (ilh2[3] == 1)
1921                 {
1922                     Block.opartyp[i] = 81;
1923                     if ((Block.oparptr[i] = (char *) MALLOC(mh2 * nh2 * sizeof(char))) == NULL)
1924                     {
1925                         for (j = 0; j < Block.nin; j++)
1926                         {
1927                             FREE(Block.inptr[j]);
1928                         }
1929                         FREE(Block.inptr);
1930                         FREE(Block.insz);
1931                         for (j = 0; j < Block.nout; j++)
1932                         {
1933                             FREE(Block.outptr[j]);
1934                         }
1935                         FREE(Block.outptr);
1936                         FREE(Block.outsz);
1937                         FREE(Block.evout);
1938                         FREE(Block.x);
1939                         FREE(Block.xd);
1940                         FREE(Block.xprop);
1941                         FREE(Block.res);
1942                         FREE(Block.z);
1943                         FREE(Block.ozsz);
1944                         FREE(Block.oztyp);
1945                         for (j = 0; j < Block.noz; j++)
1946                         {
1947                             FREE(Block.ozptr[j]);
1948                         }
1949                         FREE(Block.rpar);
1950                         FREE(Block.ipar);
1951                         FREE(Block.oparsz);
1952                         FREE(Block.opartyp);
1953                         for (j = 0; j < i; j++)
1954                         {
1955                             FREE(Block.oparptr[j]);
1956                         }
1957                         Scierror(888, _("%s : Allocation error.\n"), fname);
1958                         return 0;
1959                     }
1960                     ptr_c = (char *) Block.oparptr[i];
1961                     for (j = 0; j < mh2 * nh2; j++)
1962                     {
1963                         ptr_c[j] = *((char *)(&ilh2[4]) + j);
1964                     }
1965                 }
1966                 else if (ilh2[3] == 14)
1967                 {
1968                     Block.opartyp[i] = 814;
1969                     if ((Block.oparptr[i] = (unsigned long *) MALLOC(mh2 * nh2 * sizeof(unsigned long))) == NULL)
1970                     {
1971                         for (j = 0; j < Block.nin; j++)
1972                         {
1973                             FREE(Block.inptr[j]);
1974                         }
1975                         FREE(Block.inptr);
1976                         FREE(Block.insz);
1977                         for (j = 0; j < Block.nout; j++)
1978                         {
1979                             FREE(Block.outptr[j]);
1980                         }
1981                         FREE(Block.outptr);
1982                         FREE(Block.outsz);
1983                         FREE(Block.evout);
1984                         FREE(Block.x);
1985                         FREE(Block.xd);
1986                         FREE(Block.xprop);
1987                         FREE(Block.res);
1988                         FREE(Block.z);
1989                         FREE(Block.ozsz);
1990                         FREE(Block.oztyp);
1991                         for (j = 0; j < Block.noz; j++)
1992                         {
1993                             FREE(Block.ozptr[j]);
1994                         }
1995                         FREE(Block.rpar);
1996                         FREE(Block.ipar);
1997                         FREE(Block.oparsz);
1998                         FREE(Block.opartyp);
1999                         for (j = 0; j < i; j++)
2000                         {
2001                             FREE(Block.oparptr[j]);
2002                         }
2003                         Scierror(888, _("%s : Allocation error.\n"), fname);
2004                         return 0;
2005                     }
2006                     ptr_ul = (unsigned long *) Block.oparptr[i];
2007                     for (j = 0; j < mh2 * nh2; j++)
2008                     {
2009                         ptr_ul[j] = *((unsigned long *)(&ilh2[4]) + j);
2010                     }
2011                 }
2012                 else if (ilh2[3] == 12)
2013                 {
2014                     Block.opartyp[i] = 812;
2015                     if ((Block.oparptr[i] = (unsigned short *) MALLOC(mh2 * nh2 * sizeof(unsigned short))) == NULL)
2016                     {
2017                         for (j = 0; j < Block.nin; j++)
2018                         {
2019                             FREE(Block.inptr[j]);
2020                         }
2021                         FREE(Block.inptr);
2022                         FREE(Block.insz);
2023                         for (j = 0; j < Block.nout; j++)
2024                         {
2025                             FREE(Block.outptr[j]);
2026                         }
2027                         FREE(Block.outptr);
2028                         FREE(Block.outsz);
2029                         FREE(Block.evout);
2030                         FREE(Block.x);
2031                         FREE(Block.xd);
2032                         FREE(Block.xprop);
2033                         FREE(Block.res);
2034                         FREE(Block.z);
2035                         FREE(Block.ozsz);
2036                         FREE(Block.oztyp);
2037                         for (j = 0; j < Block.noz; j++)
2038                         {
2039                             FREE(Block.ozptr[j]);
2040                         }
2041                         FREE(Block.rpar);
2042                         FREE(Block.ipar);
2043                         FREE(Block.oparsz);
2044                         FREE(Block.opartyp);
2045                         for (j = 0; j < i; j++)
2046                         {
2047                             FREE(Block.oparptr[j]);
2048                         }
2049                         Scierror(888, _("%s : Allocation error.\n"), fname);
2050                         return 0;
2051                     }
2052                     ptr_us = (unsigned short *) Block.oparptr[i];
2053                     for (j = 0; j < mh2 * nh2; j++)
2054                     {
2055                         ptr_us[j] = *((unsigned short *)(&ilh2[4]) + j);
2056                     }
2057                 }
2058                 else if (ilh2[3] == 11)
2059                 {
2060                     Block.opartyp[i] = 811;
2061                     if ((Block.oparptr[i] = (unsigned char *) MALLOC(mh2 * nh2 * sizeof(unsigned char))) == NULL)
2062                     {
2063                         for (j = 0; j < Block.nin; j++)
2064                         {
2065                             FREE(Block.inptr[j]);
2066                         }
2067                         FREE(Block.inptr);
2068                         FREE(Block.insz);
2069                         for (j = 0; j < Block.nout; j++)
2070                         {
2071                             FREE(Block.outptr[j]);
2072                         }
2073                         FREE(Block.outptr);
2074                         FREE(Block.outsz);
2075                         FREE(Block.evout);
2076                         FREE(Block.x);
2077                         FREE(Block.xd);
2078                         FREE(Block.xprop);
2079                         FREE(Block.res);
2080                         FREE(Block.z);
2081                         FREE(Block.ozsz);
2082                         FREE(Block.oztyp);
2083                         for (j = 0; j < Block.noz; j++)
2084                         {
2085                             FREE(Block.ozptr[j]);
2086                         }
2087                         FREE(Block.rpar);
2088                         FREE(Block.ipar);
2089                         FREE(Block.oparsz);
2090                         FREE(Block.opartyp);
2091                         for (j = 0; j < i; j++)
2092                         {
2093                             FREE(Block.oparptr[j]);
2094                         }
2095                         Scierror(888, _("%s : Allocation error.\n"), fname);
2096                         return 0;
2097                     }
2098                     ptr_uc = (unsigned char *) Block.oparptr[i];
2099                     for (j = 0; j < mh2 * nh2; j++)
2100                     {
2101                         ptr_uc[j] = *((unsigned char *)(&ilh2[4]) + j);
2102                     }
2103                 }
2104             }
2105         }
2106     }
2107
2108     /* labels */
2109     /* 20 : model.label  */
2110     n            = MlistGetFieldNumber(il1, "label");
2111     ilh          = (int *) (listentry(il1, n));
2112     mh           = ilh[1];
2113     nh           = ilh[2];
2114     Block.label  = "";
2115     if (mh * nh != 0)
2116     {
2117         len_str  = ilh[5] - 1;
2118         if (len_str != 0)
2119         {
2120             if ((Block.label = (char *) MALLOC((len_str + 1) * sizeof(char))) == NULL)
2121             {
2122                 for (j = 0; j < Block.nin; j++)
2123                 {
2124                     FREE(Block.inptr[j]);
2125                 }
2126                 FREE(Block.inptr);
2127                 FREE(Block.insz);
2128                 for (j = 0; j < Block.nout; j++)
2129                 {
2130                     FREE(Block.outptr[j]);
2131                 }
2132                 FREE(Block.outptr);
2133                 FREE(Block.outsz);
2134                 FREE(Block.evout);
2135                 FREE(Block.x);
2136                 FREE(Block.xd);
2137                 FREE(Block.xprop);
2138                 FREE(Block.res);
2139                 FREE(Block.z);
2140                 FREE(Block.ozsz);
2141                 FREE(Block.oztyp);
2142                 for (j = 0; j < Block.noz; j++)
2143                 {
2144                     FREE(Block.ozptr[j]);
2145                 }
2146                 FREE(Block.rpar);
2147                 FREE(Block.ipar);
2148                 FREE(Block.oparsz);
2149                 FREE(Block.opartyp);
2150                 for (j = 0; j < Block.nopar; j++)
2151                 {
2152                     FREE(Block.oparptr[j]);
2153                 }
2154                 Scierror(888, _("%s : Allocation error.\n"), fname);
2155                 return 0;
2156             }
2157             Block.label[len_str] = '\0';
2158             C2F(cvstr)(&len_str, &ilh[6], Block.label, (j = 1, &j), len_str);
2159         }
2160     }
2161
2162     /* zero crossing */
2163     /* 21 : model.nzcross  */
2164     n            = MlistGetFieldNumber(il1, "nzcross");
2165     ilh          = (int *) (listentry(il1, n));
2166     mh           = ilh[1];
2167     nh           = ilh[2];
2168     Block.ng     = (int) * ((double *)(&ilh[4]));
2169     Block.g      = NULL;
2170     Block.jroot  = NULL;
2171     if (Block.ng != 0)
2172     {
2173         if ((Block.g = (double *) MALLOC(Block.ng * sizeof(double))) == NULL)
2174         {
2175             for (j = 0; j < Block.nin; j++)
2176             {
2177                 FREE(Block.inptr[j]);
2178             }
2179             FREE(Block.inptr);
2180             FREE(Block.insz);
2181             for (j = 0; j < Block.nout; j++)
2182             {
2183                 FREE(Block.outptr[j]);
2184             }
2185             FREE(Block.outptr);
2186             FREE(Block.outsz);
2187             FREE(Block.evout);
2188             FREE(Block.x);
2189             FREE(Block.xd);
2190             FREE(Block.res);
2191             FREE(Block.xprop);
2192             FREE(Block.z);
2193             FREE(Block.ozsz);
2194             FREE(Block.oztyp);
2195             for (j = 0; j < Block.noz; j++)
2196             {
2197                 FREE(Block.ozptr[j]);
2198             }
2199             FREE(Block.rpar);
2200             FREE(Block.ipar);
2201             FREE(Block.oparsz);
2202             FREE(Block.opartyp);
2203             for (j = 0; j < Block.nopar; j++)
2204             {
2205                 FREE(Block.oparptr[j]);
2206             }
2207             FREE(Block.label);
2208             Scierror(888, _("%s : Allocation error.\n"), fname);
2209             return 0;
2210         }
2211
2212         for (j = 0; j < Block.ng; j++)
2213         {
2214             Block.g[j] = 0.;
2215         }
2216         if ((Block.jroot = (int *) MALLOC(Block.ng * sizeof(int))) == NULL)
2217         {
2218             for (j = 0; j < Block.nin; j++)
2219             {
2220                 FREE(Block.inptr[j]);
2221             }
2222             FREE(Block.inptr);
2223             FREE(Block.insz);
2224             for (j = 0; j < Block.nout; j++)
2225             {
2226                 FREE(Block.outptr[j]);
2227             }
2228             FREE(Block.outptr);
2229             FREE(Block.outsz);
2230             FREE(Block.evout);
2231             FREE(Block.x);
2232             FREE(Block.xd);
2233             FREE(Block.res);
2234             FREE(Block.xprop);
2235             FREE(Block.z);
2236             FREE(Block.ozsz);
2237             FREE(Block.oztyp);
2238             for (j = 0; j < Block.noz; j++)
2239             {
2240                 FREE(Block.ozptr[j]);
2241             }
2242             FREE(Block.rpar);
2243             FREE(Block.ipar);
2244             FREE(Block.oparsz);
2245             FREE(Block.opartyp);
2246             for (j = 0; j < Block.nopar; j++)
2247             {
2248                 FREE(Block.oparptr[j]);
2249             }
2250             FREE(Block.label);
2251             FREE(Block.g);
2252             Scierror(888, _("%s : Allocation error.\n"), fname);
2253             return 0;
2254         }
2255
2256         for (j = 0; j < Block.ng; j++)
2257         {
2258             Block.jroot[j] = 0;
2259         }
2260     }
2261
2262     /* mode */
2263     /* 22 : model.nmode  */
2264     n            = MlistGetFieldNumber(il1, "nmode");
2265     ilh          = (int *) (listentry(il1, n));
2266     mh           = ilh[1];
2267     nh           = ilh[2];
2268     Block.nmode  = (int) * ((double *)(&ilh[4]));
2269     Block.mode  = NULL;
2270     if (Block.nmode != 0)
2271     {
2272         if ((Block.mode = (int *) MALLOC(Block.nmode * sizeof(double))) == NULL)
2273         {
2274             for (j = 0; j < Block.nin; j++)
2275             {
2276                 FREE(Block.inptr[j]);
2277             }
2278             FREE(Block.inptr);
2279             FREE(Block.insz);
2280             for (j = 0; j < Block.nout; j++)
2281             {
2282                 FREE(Block.outptr[j]);
2283             }
2284             FREE(Block.outptr);
2285             FREE(Block.outsz);
2286             FREE(Block.evout);
2287             FREE(Block.x);
2288             FREE(Block.xd);
2289             FREE(Block.res);
2290             FREE(Block.xprop);
2291             FREE(Block.z);
2292             FREE(Block.ozsz);
2293             FREE(Block.oztyp);
2294             for (j = 0; j < Block.noz; j++)
2295             {
2296                 FREE(Block.ozptr[j]);
2297             }
2298             FREE(Block.rpar);
2299             FREE(Block.ipar);
2300             FREE(Block.oparsz);
2301             FREE(Block.opartyp);
2302             for (j = 0; j < Block.nopar; j++)
2303             {
2304                 FREE(Block.oparptr[j]);
2305             }
2306             FREE(Block.label);
2307             FREE(Block.g);
2308             FREE(Block.jroot);
2309             Scierror(888, _("%s : Allocation error.\n"), fname);
2310             return 0;
2311         }
2312
2313         for (j = 0; j < Block.nmode; j++)
2314         {
2315             Block.mode[j] = 0;
2316         }
2317     }
2318
2319     /* work */
2320     if ((Block.work = (void **) MALLOC(sizeof(void *))) == NULL)
2321     {
2322         for (j = 0; j < Block.nin; j++)
2323         {
2324             FREE(Block.inptr[j]);
2325         }
2326         FREE(Block.inptr);
2327         FREE(Block.insz);
2328         for (j = 0; j < Block.nout; j++)
2329         {
2330             FREE(Block.outptr[j]);
2331         }
2332         FREE(Block.outptr);
2333         FREE(Block.outsz);
2334         FREE(Block.evout);
2335         FREE(Block.x);
2336         FREE(Block.xd);
2337         FREE(Block.res);
2338         FREE(Block.xprop);
2339         FREE(Block.z);
2340         FREE(Block.ozsz);
2341         FREE(Block.oztyp);
2342         for (j = 0; j < Block.noz; j++)
2343         {
2344             FREE(Block.ozptr[j]);
2345         }
2346         FREE(Block.rpar);
2347         FREE(Block.ipar);
2348         FREE(Block.oparsz);
2349         FREE(Block.opartyp);
2350         for (j = 0; j < Block.nopar; j++)
2351         {
2352             FREE(Block.oparptr[j]);
2353         }
2354         FREE(Block.label);
2355         FREE(Block.g);
2356         FREE(Block.jroot);
2357         FREE(Block.mode);
2358         Scierror(888, _("%s : Allocation error.\n"), fname);
2359         return 0;
2360     }
2361     *Block.work = NULL;
2362
2363     TopSave = Top;
2364
2365     ierr = createblklist(&Block, &ierr, -1, Block.type);
2366
2367     for (j = 0; j < Block.nin; j++)
2368     {
2369         FREE(Block.inptr[j]);
2370     }
2371     FREE(Block.inptr);
2372     FREE(Block.insz);
2373     for (j = 0; j < Block.nout; j++)
2374     {
2375         FREE(Block.outptr[j]);
2376     }
2377     FREE(Block.outptr);
2378     FREE(Block.outsz);
2379     FREE(Block.evout);
2380     FREE(Block.x);
2381     FREE(Block.xd);
2382     FREE(Block.res);
2383     FREE(Block.z);
2384     FREE(Block.ozsz);
2385     FREE(Block.oztyp);
2386     for (j = 0; j < Block.noz; j++)
2387     {
2388         FREE(Block.ozptr[j]);
2389     }
2390     FREE(Block.rpar);
2391     FREE(Block.ipar);
2392     FREE(Block.oparsz);
2393     FREE(Block.opartyp);
2394     for (j = 0; j < Block.nopar; j++)
2395     {
2396         FREE(Block.oparptr[j]);
2397     }
2398     if (len_str != 0)
2399     {
2400         FREE(Block.label);
2401     }
2402     FREE(Block.g);
2403     FREE(Block.jroot);
2404     FREE(Block.mode);
2405     Top = TopSave;
2406
2407     CreateVar(2, TYPED_LIST_DATATYPE, &nblklst, (j = 1, &j), &l_tmp);
2408     LhsVar(1) = 2;
2409     PutLhsVar();
2410
2411     return 0;
2412 }
2413 /*--------------------------------------------------------------------------*/
2414