~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to demos/scicos/CodeGen/Therm_standalone.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <machine.h>
 
2
/* Code prototype for standalone use  */
 
3
/*     Generated by Code_Generation toolbox of Scicos with scilab-2.6 */
 
4
/*     date : 15-Feb-2002 */
 
5
 
 
6
#include <stdio.h>
 
7
#include <string.h>
 
8
static  FILE * fd;
 
9
 
 
10
void thermmain1(double *z, double *t, double * rpar, integer *nrpar,
 
11
  integer *ipar,integer *nipar);
 
12
 
 
13
void thermmain2(double *z, double *t, double * rpar, integer *nrpar,
 
14
  integer *ipar,integer *nipar) ;
 
15
 
 
16
void therm_init(double *z, double *t, double * rpar, integer *nrpar,
 
17
  integer *ipar,integer *nipar) ;
 
18
 
 
19
void therm_end(double *z, double *t, double * rpar, integer *nrpar,
 
20
  integer *ipar,integer * nipar) ;
 
21
 
 
22
void therm_sim(double tf) ;
 
23
 
 
24
void therm_events(int *nevprt, double *t);
 
25
 
 
26
void set_nevprt(int nevprt);
 
27
static double RPAR1[ ] = {0,0,6,-6,10,-10,1,1,0.1,0};
 
28
static integer NRPAR1  = 10;
 
29
static integer IPAR1[ ]= {1,1,1,2};
 
30
static integer NIPAR1  = 4;
 
31
/*Main program */
 
32
int main()
 
33
{
 
34
  double tf=10.0;
 
35
  therm_sim(tf);
 
36
  return 0;
 
37
}
 
38
 
 
39
/*----------------------------------------  External simulation function */ 
 
40
void 
 
41
therm_sim(tf)
 
42
 
 
43
     double tf; 
 
44
{
 
45
  double t;
 
46
  int nevprt=1;
 
47
 
 
48
  /*Initial values */
 
49
  double z[]={0,0,0,0,0,0,6,-6,10,-10,-10,10,0,-6,-6,0,0,0,0,0,0,0,0,0,
 
50
    0,0,0,0,0,0,0,0,0,0,0};
 
51
  t=0.0;
 
52
  therm_init(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
 
53
  while (t<=tf) {   
 
54
    therm_events(&nevprt,&t);
 
55
    set_nevprt(nevprt);
 
56
    thermmain1(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
 
57
    thermmain2(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
 
58
  }
 
59
  therm_end(z,&t,RPAR1,&NRPAR1,IPAR1,&NIPAR1);
 
60
  return ;
 
61
}
 
62
/*----------------------------------------  Lapack messag function */ 
 
63
void
 
64
C2F(xerbla)(SRNAME,INFO,L)
 
65
char *SRNAME;
 
66
int *INFO;
 
67
long int L;
 
68
{
 
69
printf("** On entry to %s, parameter number %d  had an illegal value\n",SRNAME,*INFO);
 
70
}
 
71
/*----------------------------------------  External events handling function */ 
 
72
void 
 
73
therm_events(int *nevprt,double *t)
 
74
{
 
75
/*  set next event time and associated events ports  
 
76
 *  nevprt has binary expression b1..b1 where bi is a bit 
 
77
 *  bi is set to 1 if an activation is received by port i. Note that
 
78
 *  more than one activation can be received simultaneously 
 
79
 *  Caution: at least one bi should be equal to one */
 
80
 
 
81
    int i,p,b[]={0};
 
82
 
 
83
    b[0]=1;
 
84
    *t = *t + 0.1;
 
85
    *nevprt=0;p=1;
 
86
    for (i=0;i<1;i++) {
 
87
      *nevprt=*nevprt+b[i]*p;
 
88
      p=p*2;}
 
89
}
 
90
/*---------------------------------------- Actuators */ 
 
91
void 
 
92
therm_actuator(flag,nport,nevprt,t,u,nu)
 
93
     /*
 
94
      * To be customized for standalone execution
 
95
      * flag  : specifies the action to be done
 
96
      * nport : specifies the  index of the Super Bloc 
 
97
      *         regular input (The input ports are numbered 
 
98
      *         from the top to the bottom ) 
 
99
      * nevprt: indicates if an activation had been received
 
100
      *         0 = no activation
 
101
      *         1 = activation
 
102
      * t     : the current time value
 
103
      * u     : the vector inputs value
 
104
      * nu    : the input  vector size
 
105
      */
 
106
     integer *flag,*nevprt,*nport;
 
107
     integer *nu;
 
108
 
 
109
     double  *t, u[];
 
110
{
 
111
  int k;
 
112
  switch (*nport) {
 
113
  case 1 :/* Port number 1 ----------*/
 
114
    /* skeleton to be customized */
 
115
    switch (*flag) {
 
116
    case 2 : 
 
117
/* CUST: added */
 
118
      printf("t=%4.1f |               | out1 = %6.2f |               |\n",*t,u[0]);
 
119
      break;
 
120
    case 4 : /* actuator initialisation */
 
121
      /* do whatever you want to initialize the actuator */
 
122
      break;
 
123
    case 5 : /* actuator ending */
 
124
      /* do whatever you want to end the actuator */
 
125
      break;
 
126
    }
 
127
  break;
 
128
  case 2 :/* Port number 2 ----------*/
 
129
    switch (*flag) {
 
130
    case 2 : 
 
131
      /* CUST: added */
 
132
      printf("t=%4.1f |               |               | OUT2 = %6.2f |\n",*t,u[0]);
 
133
      break;
 
134
    case 4 : /* actuator initialisation */
 
135
      /* do whatever you want to initialize the actuator */
 
136
      break;
 
137
    case 5 : /* actuator ending */
 
138
      /* do whatever you want to end the actuator */
 
139
      break;
 
140
    }
 
141
  break;
 
142
  }
 
143
}
 
144
/*---------------------------------------- Sensor */ 
 
145
void 
 
146
therm_sensor(flag,nport,nevprt,t,y,ny)
 
147
     /*
 
148
      * To be customized for standalone execution
 
149
      * flag  : specifies the action to be done
 
150
      * nport : specifies the  index of the Super Bloc 
 
151
      *         regular input (The input ports are numbered 
 
152
      *         from the top to the bottom ) 
 
153
      * nevprt: indicates if an activation had been received
 
154
      *         0 = no activation
 
155
      *         1 = activation
 
156
      * t     : the current time value
 
157
      * y     : the vector outputs value
 
158
      * ny    : the output  vector size
 
159
      */
 
160
     integer *flag,*nevprt,*nport;
 
161
     integer *ny;
 
162
 
 
163
     double  *t, y[];
 
164
{
 
165
  int k;
 
166
  float tmp;
 
167
 
 
168
  switch (*flag) {
 
169
  case 1 : /* set the ouput value */
 
170
    /* skeleton to be customized */
 
171
    /* CUST: added */
 
172
    fscanf(fd,"%e\n",&tmp);y[0]=tmp;
 
173
    printf("t=%4.1f | in   = %6.2f |               |               |\n",*t,y[0]);
 
174
    break;
 
175
  case 2 : /* Update internal discrete state if any */
 
176
    break;
 
177
  case 4 : /* sensor initialisation */
 
178
    /* do whatever you want to initialize the sensor */
 
179
    fd=fopen("data","r");/* CUST: added */
 
180
    break;
 
181
  case 5 : /* sensor ending */
 
182
    /* do whatever you want to end the sensor */
 
183
    fclose(fd);/* CUST: added */
 
184
    break;
 
185
  }
 
186
}