readf4.c

Go to the documentation of this file.
00001 #include "scicos_block.h"
00002 #include <math.h>
00003 #include "machine.h"
00004 
00005 /* Common Block Declarations */
00006 int bfrdr();
00007 struct {
00008     double stk[2];
00009 } stack_;
00010 
00011 #define stack_1 stack_
00012 
00013 struct {
00014     int bot, top, idstk[60000]  /* was [6][10000] */, lstk[10000], 
00015             leps, bbot, bot0, infstk[10000], gbot, gtop, isiz;
00016 } vstk_;
00017 
00018 #define vstk_1 vstk_
00019 
00020 struct {
00021     int ids[24576]      /* was [6][4096] */, pstk[4096], rstk[4096], pt, niv, 
00022             macr, paus, icall, krec;
00023 } recu_;
00024 
00025 #define recu_1 recu_
00026 
00027 struct {
00028     int ddt, err, lct[8], lin[65536], lpt[6], hio, rio, wio, rte, wte;
00029 } iop_;
00030 
00031 #define iop_1 iop_
00032 
00033 struct {
00034     int err1, err2, errct, toperr, errpt, ieee, catch__;
00035 } errgst_;
00036 
00037 #define errgst_1 errgst_
00038 
00039 struct {
00040     int sym, syn[6], char1, fin, fun, lhs, rhs, ran[2], comp[3];
00041 } com_;
00042 
00043 #define com_1 com_
00044 
00045 struct {
00046     char alfa[63], alfb[63], buf[4096];
00047 } cha1_;
00048 
00049 #define cha1_1 cha1_
00050 
00051 struct {
00052     int wmac, lcntr, nmacs, macnms[600] /* was [6][100] */, lgptrs[
00053             101], bptlg[1000];
00054 } dbg_;
00055 
00056 #define dbg_1 dbg_
00057 
00058 struct {
00059     int lbot, ie, is, ipal, nbarg, ladr[1024];
00060 } adre_;
00061 
00062 #define adre_1 adre_
00063 
00064 struct {
00065     int nbvars, iwhere[1024], nbrows[1024], nbcols[1024], itflag[1024], 
00066             ntypes[1024], lad[1024], ladc[1024], lhsvar[1024];
00067 } intersci_;
00068 
00069 typedef struct
00070 {       long int cierr;
00071         long int ciunit;
00072         long int ciend;
00073         char *cifmt;
00074         long int cirec;
00075 } cilist;
00076 
00077 #define intersci_1 intersci_
00078 
00079 typedef char *address;
00080 
00081 typedef struct { double r, i; } doublecomplex;
00082 
00083 /* Table of constant values */
00084 
00085 static int c__1 = 1;
00086 static int c__3 = 3;
00087 static int c__2 = 2;
00088 
00089 int readf4(scicos_block *block,int flag)
00090 {
00091 
00092   int nz=block->nz;
00093   double* z__=block->z;
00094   double* y=block->outptr[0];  
00095   int* ny=block->outsz;
00096   int* ipar=block->ipar;
00097   double *tvec=block->evout;
00098   double t=get_scicos_time();
00099 
00100   /* System generated locals */
00101   address a__1[3], a__2[2];
00102   int i__1, i__2[3], i__3[2];
00103   char ch__1[4118], ch__2[4115];
00104   
00105   /* Builtin functions */
00106   int s_cat();
00107   
00108   /* Local variables */
00109   static int mode[2], lfil, kmax;
00110 #define cstk ((char *)&stack_1)
00111   static int ierr;
00112 #define istk ((int *)&stack_1)
00113   static int ievt, lfmt;
00114 #define sstk ((float *)&stack_1)
00115 #define zstk ((doublecomplex *)&stack_1)
00116   static int k, n;
00117   extern int dcopy_();
00118   static int lunit;
00119   extern int cvstr_();
00120   static int io, no;
00121   extern int basout_(), clunit_();
00122   
00123   /*     Copyright INRIA
00124 
00125      Scicos block simulator
00126      write read from a binary or formatted file
00127      include '../stack.h'
00128      ipar(1) = lfil : file name length
00129      ipar(2) = lfmt : format length (0) if binary file
00130      ipar(3) = ievt  : 1 if each data have a an associated time
00131      ipar(4) = N : buffer length
00132      ipar(5:4+lfil) = character codes for file name
00133      ipar(5+lfil:4+lfil+lfmt) = character codes for format if any
00134      ipar(5+lfil+lfmt:5+lfil+lfmt+ny+ievt) = reading mask */
00135   
00136 
00137   /* Parameter adjustments */
00138   --y;
00139   --ipar;
00140   --tvec;
00141   --z__;
00142   
00143   
00144   /* Function Body */
00145   if (flag == 1) {
00146     /*     discrete state */
00147     n = ipar[4];
00148     k = (int) z__[1];
00149     ievt = ipar[3];
00150     kmax = (int) z__[2];
00151     lunit = (int) z__[3];
00152     if (k + 1 > kmax && kmax == n) {
00153       /*     output */
00154       dcopy_(ny, &z__[n * ievt + 3 + k], &n, &y[1], &c__1);
00155       /*     .     read a new buffer */
00156       no = (nz - 3) / n;
00157       bfrdr(&lunit, &ipar[1], &z__[4], &no, &kmax, &ierr);
00158       if (ierr != 0) {
00159         goto L110;
00160       }
00161       z__[1] = 1.;
00162       z__[2] = (double) kmax;
00163     } else if (k < kmax) {
00164       /*     output */
00165       dcopy_(ny, &z__[n * ievt + 3 + k], &n, &y[1], &c__1);
00166       z__[1] += 1.;
00167     }
00168     
00169   } else if (flag == 3) {
00170     n = ipar[4];
00171     k = (int) z__[1];
00172     kmax = (int) z__[2];
00173     if (k > kmax && kmax < n) {
00174       tvec[1] = t - 1.;
00175     } else {
00176       tvec[1] = z__[k + 3];
00177     }
00178   } else if (flag == 4) {
00179     /*     file opening */
00180     lfil = ipar[1];
00181     ievt = ipar[3];
00182     n = ipar[4];
00183     cvstr_(&lfil, &ipar[5], cha1_1.buf, &c__1, (short)4096);
00184     lfmt = ipar[2];
00185     lunit = 0;
00186     if (lfmt > 0) {
00187       mode[0] = 1;
00188       mode[1] = 0;
00189       clunit_(&lunit, cha1_1.buf, mode, lfil);
00190       if (iop_1.err > 0) {
00191         goto L100;
00192       }
00193     } else {
00194       mode[0] = 101;
00195       mode[1] = 0;
00196       clunit_(&lunit, cha1_1.buf, mode, lfil);
00197       if (iop_1.err > 0) {
00198         goto L100;
00199       }
00200     }
00201     z__[3] = (double) lunit;
00202     /*     buffer initialisation */
00203     no = (nz - 3) / n;
00204     bfrdr(&lunit, &ipar[1], &z__[4], &no, &kmax, &ierr);
00205     if (ierr != 0) {
00206       goto L110;
00207     }
00208     z__[1] = 1.;
00209     z__[2] = (double) kmax;
00210   } else if (flag == 5) {
00211     lfil = ipar[1];
00212     n = ipar[4];
00213     k = (int) z__[1];
00214     lunit = (int) z__[3];
00215     if (lunit == 0) {
00216       return 0;
00217     }
00218     i__1 = -lunit;
00219     clunit_(&i__1, cha1_1.buf, mode, lfil);
00220     if (iop_1.err > 0) {
00221       goto L100;
00222     }
00223     z__[3] = 0.;
00224   }
00225   return 0;
00226  L100:
00227   iop_1.err = 0;
00228   lfil = ipar[1];
00229   /* Writing concatenation */
00230   i__2[0] = 5, a__1[0] = "File ";
00231   i__2[1] = lfil, a__1[1] = cha1_1.buf;
00232   i__2[2] = 17, a__1[2] = " Cannot be opened";
00233   s_cat(ch__1, a__1, i__2, &c__3, (short)4118);
00234   basout_(&io, &iop_1.wte, ch__1, lfil + 22);
00235   flag = -1;
00236   return 0;
00237  L110:
00238   lfil = ipar[1];
00239   cvstr_(&lfil, &ipar[5], cha1_1.buf, &c__1, (short)4096);
00240   i__1 = -lunit;
00241   clunit_(&i__1, cha1_1.buf, mode, lfil);
00242   /* Writing concatenation */
00243   i__3[0] = 19, a__2[0] = "Read error on file ";
00244   i__3[1] = lfil, a__2[1] = cha1_1.buf;
00245   s_cat(ch__2, a__2, i__3, &c__2, (short)4115);
00246   basout_(&io, &iop_1.wte, ch__2, lfil + 19);
00247   flag = -1;
00248   return 0;
00249 } /* readf */
00250 
00251 #undef zstk
00252 #undef sstk
00253 #undef istk
00254 #undef cstk
00255 
00256 
00257 int bfrdr(lunit, ipar, z__, no, kmax, ierr)
00258      int *lunit, *ipar;
00259      double *z__;
00260      int *no, *kmax, *ierr;
00261 {
00262   /* System generated locals */
00263   int i__1, i__2, i__3;
00264   cilist ci__1;
00265   
00266   /* Builtin functions */
00267   int s_rsue(), do_uio(), e_rsue(), s_rsfe(), do_fio(), e_rsfe();
00268   
00269   /* Local variables */
00270 #define cstk ((char *)&stack_1)
00271   static int lfmt;
00272 #define istk ((int *)&stack_1)
00273   static int ievt;
00274 #define sstk ((float *)&stack_1)
00275 #define zstk ((doublecomplex *)&stack_1)
00276   static int i__, j, n, imask;
00277   extern /* Subroutine */ int cvstr_();
00278   static int mm;
00279   static double tmp[100];
00280   
00281   /* Fortran I/O blocks */
00282   static cilist io___26 = { 1, 0, 1, 0, 0 }; 
00283   
00284   
00285   /* *------------------------------------------------------------------ */
00286 
00287   /* Parameter adjustments */
00288   --z__;
00289   --ipar;
00290   
00291   /* Function Body */
00292   ievt = ipar[3];
00293   n = ipar[4];
00294   /*      no=(nz-3)/N */
00295   /*     maximum number of value to read */
00296   imask = ipar[1] + 5 + ipar[2];
00297   if (ievt == 0) {
00298     ++imask;
00299   }
00300   mm = 0;
00301   i__1 = *no - 1;
00302   for (i__ = 0; i__ <= i__1; ++i__) {
00303     /* Computing MAX */
00304     i__2 = mm, i__3 = ipar[imask + i__];
00305     mm = max(i__2,i__3);
00306     /* L10: */
00307   }
00308   
00309   lfmt = ipar[2];
00310   *kmax = 0;
00311   if (lfmt == 0) {
00312     /*     unformatted read */
00313     i__1 = n;
00314     for (i__ = 1; i__ <= i__1; ++i__) {
00315       io___26.ciunit = *lunit;
00316       i__2 = s_rsue(&io___26);
00317       if (i__2 != 0) {
00318         goto L100001;
00319       }
00320       i__3 = mm;
00321       for (j = 1; j <= i__3; ++j) {
00322         i__2 = do_uio(&c__1, (char *)&tmp[j - 1], (short)sizeof(
00323                                                                  double));
00324         if (i__2 != 0) {
00325           goto L100001;
00326         }
00327       }
00328       i__2 = e_rsue();
00329     L100001:
00330       if (i__2 < 0) {
00331         goto L20;
00332       }
00333       if (i__2 > 0) {
00334         goto L100;
00335       }
00336       i__2 = *no - 1;
00337       for (j = 0; j <= i__2; ++j) {
00338         z__[j * n + i__] = tmp[ipar[imask + j] - 1];
00339         /* L11: */
00340       }
00341       ++(*kmax);
00342       /* L12: */
00343     }
00344   } else {
00345     /*     formatted read */
00346     cvstr_(&ipar[2], &ipar[ipar[1] + 5], cha1_1.buf, &c__1, (short)4096);
00347     i__1 = n;
00348     for (i__ = 1; i__ <= i__1; ++i__) {
00349       ci__1.cierr = 1;
00350       ci__1.ciend = 1;
00351       ci__1.ciunit = *lunit;
00352       ci__1.cifmt = cha1_1.buf;
00353       i__2 = s_rsfe(&ci__1);
00354       if (i__2 != 0) {
00355         goto L100002;
00356       }
00357       i__3 = mm;
00358       for (j = 1; j <= i__3; ++j) {
00359         i__2 = do_fio(&c__1, (char *)&tmp[j - 1], (short)sizeof(
00360                                                                  double));
00361         if (i__2 != 0) {
00362           goto L100002;
00363         }
00364       }
00365       i__2 = e_rsfe();
00366     L100002:
00367       if (i__2 < 0) {
00368         goto L20;
00369       }
00370       if (i__2 > 0) {
00371         goto L100;
00372       }
00373       i__2 = *no - 1;
00374       for (j = 0; j <= i__2; ++j) {
00375         z__[j * n + i__] = tmp[ipar[imask + j] - 1];
00376         /* L13: */
00377       }
00378       ++(*kmax);
00379       /* L14: */
00380     }
00381   }
00382  L20:
00383   *ierr = 0;
00384   return 0;
00385  L100:
00386   *ierr = 1;
00387   return 0;
00388 } /* bfrdr */
00389 
00390 #undef zstk
00391 #undef sstk
00392 #undef istk
00393 #undef cstk
00394 
00395 

Generated on Sun Mar 4 15:03:59 2007 for Scilab [trunk] by  doxygen 1.5.1