1
subroutine cossim(neq,x,xptr,z,zptr,iz,izptr,told,tf,
3
$ tevts,evtspt,nevts,pointi,inpptr,inplnk,outptr,
4
$ outlnk,lnkptr,clkptr,ordptr,nptr,
5
$ ordclk,nordcl,ztyp,cord,iord,niord,oord,zord,
6
$ critev,rpar,rpptr,ipar,
7
$ ipptr,funptr,funtyp,rhot,ihot,outtb,jroot,w,iwa,ierr)
11
c maximum number of clock output for one block
16
C neq must contain after #states all integer data for simblk and grblk
17
double precision x(*),z(*),told,tf,tevts(*),rpar(*),outtb(*)
18
double precision w(*),rhot(*)
20
C X must contain after state values all real data for simblk and grblk
21
integer xptr(*),zptr(*),iz(*),izptr(*),evtspt(nevts),nevts,pointi
22
integer inpptr(*),inplnk(*),outptr(*),outlnk(*),lnkptr(*)
23
integer clkptr(*),ordptr(nptr),nptr,ztyp(*)
24
integer ordclk(nordcl,2),nordcl,cord(*),iord(*),oord(*),zord(*)
25
integer critev(*),rpptr(*),ipar(*),ipptr(*),funptr(*),funtyp(*)
26
integer ihot(*),jroot(*),ierr
29
integer i,k,ierr1,iopt,istate,itask,j,jdum,jt,
30
& ksz,flag,keve,kpo,nord,nclock
32
double precision tvec(nts)
36
integer otimer,ntimer,stimer
39
integer nblk,nordptr,nout,ng,nrwp,niwp,ncord,
41
common /cossiz/ nblk,nordptr,nout,ng,nrwp,niwp,ncord,
50
double precision scale
51
common /rtfactor/ scale
53
double precision atol,rtol,ttol,deltat
54
common /costol/ atol,rtol,ttol,deltat
64
call iset(niwp,0,ihot,1)
65
call dset(nrwp,0.0d0,rhot,1)
66
call realtimeinit(told, scale)
70
c initialisation (propagation of constant blocks outputs)
71
if(niord.eq.0) goto 10
74
nclock = iord(jj+niord)
76
call callf(kfun,nclock,funptr,funtyp,told,x,x,xptr,z,zptr,iz,
77
$ izptr,rpar,rpptr,ipar,ipptr,tvec,ntvec,inpptr,inplnk
78
$ ,outptr,outlnk,lnkptr,outtb,flag)
86
if (told .ge. tf) return
89
if (ntimer.ne.otimer) then
103
if (abs(t-told) .lt. ttol) then
107
if (told .gt. t) then
108
C ! scheduling problem
112
if (told .ne. t) then
113
if (xptr(nblk+1) .eq. 1) then
114
C . no continuous state
115
if(told+deltat+ttol.gt.t) then
120
c . update outputs of 'c' type blocks
121
if (ncord.eq.0) goto 343
123
call cdoit(neq,x,xptr,z,zptr,iz,izptr,told,tf
124
$ ,tevts,evtspt,nevts,pointi,inpptr,inplnk,outptr
125
$ ,outlnk,lnkptr,clkptr,ordptr,nptr
126
$ ,ordclk,nordcl,cord,iord,niord,oord,zord,critev,
128
$ ,ipptr,funptr,funtyp,outtb,w,hot,ierr)
140
C Compute tcrit (rhot(1))
143
20 if(critev(kpo).eq.1) then
152
c . form initial zero crossing input signs
155
c . loop on zero crossing block
157
if (ztyp(kfun).eq.1) then
158
c . loop on block ports
159
do 34 kport=inpptr(kfun),inpptr(kfun+1)-1
161
do 33 i=lnkptr(klink),lnkptr(klink+1)-1
162
if (outtb(i).gt.0.d0) then
177
t=min(told+deltat,min(t,tf+ttol))
180
call lsodar(simblk,neq,x,told,t,1,rtol,atol,itask,
181
& istate,iopt,rhot,nrwp,ihot,niwp,jdum,jt,grblk,
183
if (istate .le. 0) then
184
if (istate .eq. -3) then
191
call lsoda(simblk,neq,x,told,t,
193
& istate,iopt,rhot,nrwp,ihot,niwp,jdum,jt)
196
if (istate .gt. 0) goto 38
198
C ! integration problem
205
c . update outputs of 'c' type blocks
209
call cdoit(neq,x,xptr,z,zptr,iz,izptr,told,tf
210
$ ,tevts,evtspt,nevts,pointi,inpptr,inplnk,outptr
211
$ ,outlnk,lnkptr,clkptr,ordptr,nptr
212
$ ,ordclk,nordcl,cord,iord,niord,oord,zord,critev,
214
$ ,ipptr,funptr,funtyp,outtb,w,hot,ierr)
217
if (istate .eq. 3) then
218
C . at a least one root has been found
221
if (ztyp(kfun).eq.1) then
222
c . loop on block input ports
224
do 42 kport=inpptr(kfun),inpptr(kfun+1)-1
225
c . get corresponding link pointer
227
ksz=ksz+lnkptr(klink+1)-lnkptr(klink)
229
c . kev is a base 2 coding of reached zero crossing surfaces
232
kev=2*kev+jroot(ig+ksz-j)
235
if (kev.eq.0) jjflg=0
237
kev=2*kev+jroot(ng+ig+ksz-j)
240
if (jjflg .ne. 0) then
242
ntvec=clkptr(kfun+1)-clkptr(kfun)
243
c . call corresponding block to determine output event (kev)
244
call callf(kfun,kev,funptr,funtyp,
246
$ zptr,iz,izptr,rpar,rpptr,ipar,ipptr,tvec,
247
$ ntvec,inpptr,inplnk,outptr,outlnk,lnkptr,
253
c . update event agenda
254
do 47 k=1,clkptr(kfun+1)-clkptr(kfun)
255
if (tvec(k).ge.told) then
256
if (critev(k+clkptr(kfun)-1).eq.1)
258
call addevs(tevts,evtspt,nevts,pointi,
259
& tvec(k),k+clkptr(kfun)-1,ierr1)
260
if (ierr1 .ne. 0) then
271
c ! save initial signs of zero crossing surface
277
call ddoit(neq,x,xptr,z,zptr,iz,izptr,told,tf,
278
$ tevts,evtspt,nevts,pointi,inpptr,inplnk,outptr,
279
$ outlnk,lnkptr,clkptr,ordptr,nptr,
280
$ ordclk,nordcl,cord,iord,niord,oord,zord,critev,
282
$ ipptr,funptr,funtyp,outtb,w,iwa,hot,ierr)
286
C end of main loop on time