readf4.c

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

Generated on Tue Sep 9 17:48:34 2008 for Scilab [trunk] by  doxygen 1.5.5