00001 #include "scicos_block.h"
00002 #include <math.h>
00003 #include "machine.h"
00004
00005
00006
00007
00008 struct {
00009 double stk[2];
00010 } stack_;
00011
00012 #define stack_1 stack_
00013
00014 struct {
00015 int bot, top, idstk[60000] , lstk[10000],
00016 leps, bbot, bot0, infstk[10000], gbot, gtop, isiz;
00017 } vstk_;
00018
00019 #define vstk_1 vstk_
00020
00021 struct {
00022 int ids[24576] , pstk[4096], rstk[4096], pt, niv,
00023 macr, paus, icall, krec;
00024 } recu_;
00025
00026 #define recu_1 recu_
00027
00028 struct {
00029 int ddt, err, lct[8], lin[65536], lpt[6], hio, rio, wio, rte, wte;
00030 } iop_;
00031
00032 #define iop_1 iop_
00033
00034 struct {
00035 int err1, err2, errct, toperr, errpt, ieee, catch__;
00036 } errgst_;
00037
00038 #define errgst_1 errgst_
00039
00040 struct {
00041 int sym, syn[6], char1, fin, fun, lhs, rhs, ran[2], comp[3];
00042 } com_;
00043
00044 #define com_1 com_
00045
00046 struct {
00047 char alfa[63], alfb[63], buf[4096];
00048 } cha1_;
00049
00050 #define cha1_1 cha1_
00051
00052 struct {
00053 int wmac, lcntr, nmacs, macnms[600] , lgptrs[
00054 101], bptlg[1000];
00055 } dbg_;
00056
00057 #define dbg_1 dbg_
00058
00059 struct {
00060 int lbot, ie, is, ipal, nbarg, ladr[1024];
00061 } adre_;
00062
00063 #define adre_1 adre_
00064
00065 struct {
00066 int nbvars, iwhere[1024], nbrows[1024], nbcols[1024], itflag[1024],
00067 ntypes[1024], lad[1024], ladc[1024], lhsvar[1024];
00068 } intersci_;
00069
00070 #define intersci_1 intersci_
00071
00072 typedef struct
00073 { long int cierr;
00074 long int ciunit;
00075 long int ciend;
00076 char *cifmt;
00077 long int cirec;
00078 } cilist;
00079
00080 typedef char *address;
00081
00082 typedef struct { double r, i; } doublecomplex;
00083
00084
00085
00086 static int c__1 = 1;
00087 static double c_b12 = 0.;
00088 static int c__3 = 3;
00089
00090 int writef4(scicos_block *block,int flag)
00091 {
00092 double* z__=block->z;
00093 double* u=block->inptr[0];
00094 int* nu=block->insz;
00095 int* ipar=block->ipar;
00096 int nevprt=block->nevprt;
00097 double t=get_scicos_time();
00098
00099
00100 address a__1[3];
00101 int i__1, i__2, i__3, i__4[3];
00102 char ch__1[4118];
00103 cilist ci__1;
00104
00105
00106 int s_wsfe(), do_fio(), e_wsfe(), s_wsue(), do_uio(), e_wsue();
00107 int s_cat();
00108
00109
00110 static int mode[2], lfil;
00111 extern int dset_();
00112 static int lfmt;
00113 #define cstk ((char *)&stack_1)
00114 #define istk ((int *)&stack_1)
00115 #define sstk ((real *)&stack_1)
00116 #define zstk ((doublecomplex *)&stack_1)
00117 static int i__, j, k, n, iflag, lunit;
00118 extern int cvstr_();
00119 static int io;
00120 extern int basout_(), clunit_();
00121
00122
00123 static cilist io___10 = { 1, 0, 0, 0, 0 };
00124 static cilist io___14 = { 0, 0, 0, 0, 0 };
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 --u;
00163 --ipar;
00164 --z__;
00165
00166
00167 n = ipar[4];
00168 k = (int) z__[1];
00169 lunit = (int) z__[2];
00170
00171 if (flag == 2 && nevprt > 0) {
00172
00173 ++k;
00174 z__[k + 2] = t;
00175 i__1 = *nu;
00176 for (i__ = 1; i__ <= i__1; ++i__) {
00177 z__[n + 2 + (i__ - 1) * n + k] = u[i__];
00178
00179 }
00180 z__[1] = (double) k;
00181 if (k < n) {
00182 return 0;
00183 }
00184
00185 if (ipar[2] > 0) {
00186
00187 cvstr_(&ipar[2], &ipar[ipar[1] + 5], cha1_1.buf, &c__1, (short)
00188 4096);
00189 i__1 = k;
00190 for (j = 1; j <= i__1; ++j) {
00191 ci__1.cierr = 1;
00192 ci__1.ciunit = lunit;
00193 ci__1.cifmt = cha1_1.buf;
00194 i__2 = s_wsfe(&ci__1);
00195 if (i__2 != 0) {
00196 goto L100;
00197 }
00198 i__3 = *nu;
00199 for (i__ = 0; i__ <= i__3; ++i__) {
00200 i__2 = do_fio(&c__1, (char *)&z__[n + 2 + (i__ - 1) * n +
00201 j], (short)sizeof(double));
00202 if (i__2 != 0) {
00203 goto L100;
00204 }
00205 }
00206 i__2 = e_wsfe();
00207 if (i__2 != 0) {
00208 goto L100;
00209 }
00210
00211 }
00212 } else {
00213
00214 i__1 = k;
00215 for (j = 1; j <= i__1; ++j) {
00216 io___10.ciunit = lunit;
00217 i__2 = s_wsue(&io___10);
00218 if (i__2 != 0) {
00219 goto L100;
00220 }
00221 i__3 = *nu;
00222 for (i__ = 0; i__ <= i__3; ++i__) {
00223 i__2 = do_uio(&c__1, (char *)&z__[n + 2 + (i__ - 1) * n +
00224 j], (short)sizeof(double));
00225 if (i__2 != 0) {
00226 goto L100;
00227 }
00228 }
00229 i__2 = e_wsue();
00230 if (i__2 != 0) {
00231 goto L100;
00232 }
00233
00234 }
00235 }
00236 z__[1] = 0.;
00237 } else if (flag == 4) {
00238
00239 lfil = ipar[1];
00240 cvstr_(&lfil, &ipar[5], cha1_1.buf, &c__1, (short)4096);
00241 lfmt = ipar[2];
00242 lunit = 0;
00243 if (lfmt > 0) {
00244 mode[0] = 3;
00245 mode[1] = 0;
00246 clunit_(&lunit, cha1_1.buf, mode, lfil);
00247 if (iop_1.err > 0) {
00248 goto L100;
00249 }
00250 } else {
00251 mode[0] = 103;
00252 mode[1] = 0;
00253 clunit_(&lunit, cha1_1.buf, mode, lfil);
00254 if (iop_1.err > 0) {
00255 goto L100;
00256 }
00257 }
00258 z__[1] = 0.;
00259 z__[2] = (double) lunit;
00260 z__[3] = t;
00261 i__1 = *nu * n;
00262 dset_(&i__1, &c_b12, &z__[4], &c__1);
00263 } else if (flag == 5) {
00264 if (lunit == 0) {
00265 return 0;
00266 }
00267 if (k >= 1) {
00268
00269 lfmt = ipar[2];
00270 if (lfmt > 0) {
00271
00272 cvstr_(&lfmt, &ipar[ipar[1] + 5], cha1_1.buf, &c__1, (short)
00273 4096);
00274 i__1 = k;
00275 for (j = 1; j <= i__1; ++j) {
00276 ci__1.cierr = 0;
00277 ci__1.ciunit = lunit;
00278 ci__1.cifmt = cha1_1.buf;
00279 s_wsfe(&ci__1);
00280 i__2 = *nu;
00281 for (i__ = 0; i__ <= i__2; ++i__) {
00282 do_fio(&c__1, (char *)&z__[n + 2 + (i__ - 1) * n + j],
00283 (short)sizeof(double));
00284 }
00285 e_wsfe();
00286
00287 }
00288 } else {
00289
00290 i__1 = k;
00291 for (j = 1; j <= i__1; ++j) {
00292 io___14.ciunit = lunit;
00293 s_wsue(&io___14);
00294 i__2 = *nu;
00295 for (i__ = 0; i__ <= i__2; ++i__) {
00296 do_uio(&c__1, (char *)&z__[n + 2 + (i__ - 1) * n + j],
00297 (short)sizeof(double));
00298 }
00299 e_wsue();
00300
00301 }
00302 }
00303 }
00304 lfil = ipar[1];
00305 i__1 = -lunit;
00306 clunit_(&i__1, cha1_1.buf, mode, lfil);
00307 if (iop_1.err > 0) {
00308 goto L100;
00309 }
00310 z__[2] = 0.;
00311 }
00312 return 0;
00313 L100:
00314 iop_1.err = 0;
00315
00316 i__4[0] = 5, a__1[0] = "File ";
00317 i__4[1] = lfil, a__1[1] = cha1_1.buf;
00318 i__4[2] = 17, a__1[2] = " Cannot be opened";
00319 s_cat(ch__1, a__1, i__4, &c__3, (short)4118);
00320 basout_(&io, &iop_1.wte, ch__1, lfil + 22);
00321 iflag = -1;
00322 return 0;
00323 }
00324
00325 #undef zstk
00326 #undef sstk
00327 #undef istk
00328 #undef cstk
00329
00330