#include "/usr/local/lib/scilab/routines/machine.h"
/* Code prototype for standalone use  */
/*     Generated by Code_Generation toolbox of Scicos with scilab-2.6 */
/*     date : 27-Feb-2002 */

#include <stdio.h>
#include <string.h>

void Fibomain1(double *z, double *t, double * rpar, integer *nrpar,
  integer *ipar,integer *nipar);

void Fibomain2(double *z, double *t, double * rpar, integer *nrpar,
  integer *ipar,integer *nipar) ;

void Fibo_init(double *z, double *t, double * rpar, integer *nrpar,
  integer *ipar,integer *nipar) ;

void Fibo_end(double *z, double *t, double * rpar, integer *nrpar,
  integer *ipar,integer * nipar) ;

void Fibo_sim(double tf) ;

void Fibo_events(int *nevprt, double *t);

void set_nevprt(int nevprt);
static double RPAR1[1];
static integer NRPAR1  = 0;
static integer IPAR1[ ]= {1,1};
static integer NIPAR1  = 2;
/*Main program */
int main()
{
   double tf=20.0;
   Fibo_sim(tf);
   return 0;
}

/*----------------------------------------  External simulation function */ 
void 
Fibo_sim(tf)
 
     double tf; 
{
  double t;
  int nevprt=1;

  /*Initial values */
  double z[]={1,2,3,1,2,0.5,0.5,0,0,0,0,0,0,0};
  t=0.0;
  Fibo_init(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
  while (t<=tf) {   
    Fibo_events(&nevprt,&t);
    set_nevprt(nevprt);
    Fibomain1(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
    Fibomain2(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
  }
  Fibo_end(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
  return ;
}
/*----------------------------------------  Lapack messag function */ 
void
C2F(xerbla)(SRNAME,INFO,L)
char *SRNAME;
int *INFO;
long int L;
{
printf("** On entry to %s, parameter number %d  had an illegal value\n",SRNAME,*INFO);
}
/*----------------------------------------  External events handling function */ 
void 
Fibo_events(int *nevprt,double *t)
{
/*  set next event time and associated events ports  
 *  nevprt has binary expression b1..b1 where bi is a bit 
 *  bi is set to 1 if an activation is received by port i. Note that
 *  more than one activation can be received simultaneously 
 *  Caution: at least one bi should be equal to one */

    int i,p,b[]={0};

    b[0]=1;
    *t = *t + 1; /* CUST: *t + 0.1 changed to *t + 1 */
    *nevprt=0;p=1;
    for (i=0;i<1;i++) {
      *nevprt=*nevprt+b[i]*p;
      p=p*2;}
}
/*---------------------------------------- Actuators */ 
void 
Fibo_actuator(flag,nport,nevprt,t,u,nu)
     /*
      * To be customized for standalone execution
      * flag  : specifies the action to be done
      * nport : specifies the  index of the Super Bloc 
      *         regular input (The input ports are numbered 
      *         from the top to the bottom ) 
      * nevprt: indicates if an activation had been received
      *         0 = no activation
      *         1 = activation
      * t     : the current time value
      * u     : the vector inputs value
      * nu    : the input  vector size
      */
     integer *flag,*nevprt,*nport;
     integer *nu;

     double  *t, u[];
{
  int k;
  /* skeleton to be customized */
  switch (*flag) {
  case 2 : 
    if(*nevprt>0) {/* get the input value */
      printf("n=%4.0f | u = %9.5f |\n",*t,u[0]);/* CUST: added */
    } 
    break;
  case 4 : /* actuator initialisation */
    /* do whatever you want to initialize the actuator */
    break;
  case 5 : /* actuator ending */
    /* do whatever you want to end the actuator */
    break;
  }
}
