File: lstops.f

package info (click to toggle)
scilab 2.2-4
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 31,472 kB
  • ctags: 21,963
  • sloc: fortran: 110,983; ansic: 89,717; makefile: 3,016; sh: 1,892; csh: 150; cpp: 101
file content (347 lines) | stat: -rw-r--r-- 9,213 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
      subroutine lstops
c =============================================================
c     operations elementaires sur les listes
c =============================================================
c
      include '../stack.h'
c
c
      integer rhs1,vol1,vol2,typ2,op,iadr,sadr,top0
      integer strpos
      external strpos
c
c
      data insert/2/,extrac/3/

c
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c 
      op=fin
      fun=0
c
      if (ddt .eq. 4) then
         write(buf(1:4),'(i4)') op
         call basout(io,wte,' lstops '//buf(1:4))
      endif
c
      lw=lstk(top+1)
      rhs1=rhs
      top0=top
      if(op.eq.insert) rhs=rhs-2
      if(op.eq.extrac) rhs=rhs-1
c
   05 il1=iadr(lstk(top))
      if(istk(il1).lt.0) il1=iadr(istk(il1+1))
      m1=istk(il1+1)
      it1=istk(il1+2)
      id1=il1+3
      l1r=sadr(il1+m1+3)
c
      if(op.eq.extrac) goto 10
      if(op.eq.insert) goto 30
c
c     operations non implantee
      fin=-fin
      rhs=rhs1
      return
c
c extraction
   10 ltyp=istk(il1)
      if(rhs.eq.1) goto 11
      fin=-fin
      rhs=rhs1
      return
c
   11 rhs=rhs1-1
      top=top-1
      ilcol=iadr(lstk(top))
      if(istk(ilcol).eq.10) then
         ilt=iadr(sadr(il1+istk(il1+1)+3))
         nt=istk(ilt+1)*istk(ilt+2)
         if(nt.eq.1) then
            top=top0
            fin=-fin
            rhs=rhs1
            return
         endif
c     .  element is designated by its name
         if(istk(ilcol+1).gt.1.and.istk(ilcol+2).gt.1) then
            call error(21)
            return
         endif
         ncol=istk(ilcol+1)*istk(ilcol+2)
         lcol=iadr(lw)
         lw=sadr(lcol+ncol)
         err=lw-lstk(bot)
         if(err.gt.0) then
            call error(17)
            return
         endif
c     .  look for corresponding index
         l=ilcol+5+ncol
         do 12 i=1,ncol
            nl=istk(ilcol+4+i)-istk(ilcol+3+i)
            n=strpos(istk(ilt+5),nt-1,istk(ilt+5+nt),istk(l),nl)
            l=l+nl
            if(n.le.0) then
               call error(21)
               return
            endif
            n=n+1
            istk(lcol-1+i)=n
 12      continue
      else
c     .  element is designated by its index
         if(istk(ilcol).ne.1.or.istk(ilcol+3).ne.0) then
            call error(21)
            return
         endif
         if(istk(ilcol+1).gt.1.and.istk(ilcol+2).gt.1) then
            call error(21)
            return
         endif
         if(istk(ilcol+1).gt.0) then
            ncol=istk(ilcol+1)*istk(ilcol+2)
            lcol=sadr(ilcol+4)
            call entier(ncol,stk(lcol),istk(iadr(lcol)))
            lcol=iadr(lcol)
         else
            goto 20
         endif
      endif
c
      if(ncol.ne.lhs) then
         call error(41)
         return
      endif
c
      if(top+ncol+1.ge.bot) then
         call error(18)
         return
      endif
      do  17 i=1,ncol
      n=istk(lcol-1+i)
      if(n.gt.m1.or.n.lt.1) then
         call error(21)
         return
      endif
      lstk(top+1)=lstk(top)+istk(il1+2+n)-istk(il1+1+n)
      top=top+1
   17 continue
c
      top=top-1
      ill=max(lcol+ncol,iadr(lstk(top+1)))
      err=sadr(ill+ncol)-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
c      call isort(istk(lcol),ncol,istk(ill))
      do  18 i=1,ncol
      n=istk(lcol-1+i)
      istk(ill-1+i)=istk(il1+1+n)+l1r-1
   18 continue
c
      do  19 i=1,ncol
         k=top-ncol+i
         call dcopy(lstk(k+1)-lstk(k),stk(istk(ill-1+i)),1,
     $        stk(lstk(k)),1)
   19 continue
      goto 99
c
c     extraction list(:) 
c
   20 l=lstk(top)
      if(m1.ne.lhs) then
         call error(41)
         return
      endif

      if(top+1+m1.ge.bot) then
         call error(18)
         return
      endif
      do  21 i=1,m1
      lstk(top+1)=lstk(top)+istk(il1+2+i)-istk(il1+1+i)
      top=top+1
   21 continue
      top=top-1
      call dcopy(istk(il1+m1+2)-1,stk(l1r),1,stk(l),1)
      goto 99
c
c insert
   30 if(rhs.eq.1.and.(istk(il1).eq.15.or.istk(il1).eq.16)) goto 31
      fin=-fin
      rhs=rhs1
      return
c
   31 top=top-1
      ltyp=istk(il1)
      vol2=lstk(top+1)-lstk(top)
      l2=lstk(top)
      typ2=istk(iadr(l2))
c
      top=top-1
      ilcol=iadr(lstk(top))
      if(istk(ilcol).eq.10) then
         ilt=iadr(sadr(il1+istk(il1+1)+3))
         nt=istk(ilt+1)*istk(ilt+2)
         if(nt.eq.1) then
            top=top0
            fin=-fin
            rhs=rhs1
            return
         endif
c     .  element is designated by its name
         if(istk(ilcol+1)*istk(ilcol+2).ne.1) then
            call error(21)
            return
         endif
c     .  look for corresponding index
         n=strpos(istk(ilt+5),nt-1,istk(ilt+5+nt),istk(ilcol+6),
     $        istk(ilcol+5)-istk(ilcol+4))
         if(n.le.0) then
            call error(21)
            return
         endif
         n=n+1
      else
         if(istk(ilcol).ne.1.or.istk(ilcol+3).ne.0) then
            call error(21)
            return
         endif
         if(istk(ilcol+1)*istk(ilcol+2).ne.1) then
            call error(21)
            return
         endif
         n=int(stk(sadr(ilcol+4)))
         if(n.lt.0.or.n.gt.m1+1) then
            call error(21)
            return
         endif
      endif
c
      vol1=istk(il1+2+m1)-1
      ilr=iadr(lw)
      istk(ilr)=ltyp
      istk(ilr+1)=m1+1
      istk(ilr+2)=1
c
      if(n.eq.0) then
c     add a new element "on the left"
         if(typ2.eq.0) then
c     null element : nothing added
            call dcopy(lstk(top+3)-lstk(top+2),stk(lstk(top+2)),1,
     &           stk(lstk(top)),1)
            lstk(top+1)=lstk(top)+lstk(top+3)-lstk(top+2)
            goto 99
         endif
         ilr=iadr(lw)
         istk(ilr)=15
         istk(ilr+1)=m1+1
         istk(ilr+2)=1
         istk(ilr+3)=1+vol2
         do 32 i=1,m1
            istk(ilr+3+i)=istk(ilr+2+i)+istk(il1+2+i)-istk(il1+1+i)
 32      continue
         lr=sadr(ilr+4+m1)
         call dcopy(vol2,stk(l2),1,stk(lr),1)
         lr=lr+vol2
         call dcopy(vol1,stk(l1r),1,stk(lr),1)
         lr=lr+vol1
         call dcopy(lr-lw,stk(lw),1,stk(lstk(top)),1)
         lstk(top+1)=lstk(top)+lr-lw
      elseif(n.eq.m1+1) then
c     add a new element "on the right"
         if(typ2.eq.0) then
c     null element : nothing added
            call dcopy(lstk(top+3)-lstk(top+2),stk(lstk(top+2)),1,
     &           stk(lstk(top)),1)
            lstk(top+1)=lstk(top)+lstk(top+3)-lstk(top+2)
            goto 99
         endif
         ilr=iadr(lw)
         istk(ilr)=ltyp
         istk(ilr+1)=m1+1
         call icopy(m1+1,istk(il1+2),1,istk(ilr+2),1)
         istk(ilr+3+m1)=istk(ilr+2+m1)+vol2
         lr=sadr(ilr+4+m1)
         call dcopy(vol1,stk(l1r),1,stk(lr),1)
         lr=lr+vol1
         call dcopy(vol2,stk(l2),1,stk(lr),1)
         lr=lr+vol2
         call dcopy(lr-lw,stk(lw),1,stk(lstk(top)),1)
         lstk(top+1)=lstk(top)+lr-lw
      elseif(typ2.ne.0) then
c     change the specified element
         if (istk(il1+2+n)-istk(il1+1+n).eq.vol2) then
c     element is directly replaced 
            lr=l1r+istk(il1+1+n)-1
            call dcopy(vol2,stk(l2),1,stk(lr),1)
c     .     list has been modified in place
            il1=iadr(lstk(top))
            istk(il1)=-1
            istk(il1+1)=-1
            istk(il1+2)=istk(iadr(lstk(top0))+2)
            lstk(top+1)=lstk(top)+3
            goto 99
         endif
         ilr=iadr(lw)
         istk(ilr)=ltyp
         istk(ilr+1)=m1+1
         if(ltyp.eq.16.and.n.eq.1.and.typ2.ne.10) istk(ilr)=15
         istk(ilr+1)=m1
         call icopy(n,istk(il1+2),1,istk(ilr+2),1)
         istk(ilr+2+n)=istk(ilr+1+n)+vol2
         do 36 i=n+1,m1+1
            istk(ilr+i+2)=istk(ilr+i+1)+istk(il1+i+2)-istk(il1+i+1)
 36      continue
         lr=sadr(ilr+3+m1)
         call dcopy(istk(il1+1+n)-1,stk(l1r),1,stk(lr),1)
         lr=lr+istk(il1+1+n)-1
         call dcopy(vol2,stk(l2),1,stk(lr),1)
         lr=lr+vol2
         l1r=l1r+istk(il1+2+n)-1
         call dcopy(istk(il1+2+m1)-istk(il1+2+n),stk(l1r),1,stk(lr),1)
         lr=lr+istk(il1+2+m1)-istk(il1+2+n)
 38      call dcopy(lr-lw,stk(lw),1,stk(lstk(top)),1)
         lstk(top+1)=lstk(top)+lr-lw
      else
c     suppress the specified element
         il=iadr(lstk(top))
         l2r=l1r-1+istk(il1+2+n)
         call icopy(2+n,istk(il1),1,istk(il),1)
         if(ltyp.eq.16.and.n.eq.1) istk(il)=15
         istk(il+1)=istk(il+1)-1
         do 41 i=n,m1
            istk(il+i+2)=istk(il+i+1)+istk(il1+i+3)-istk(il1+i+2)
 41      continue
         l=sadr(il+2+m1)
         call dcopy(istk(il+n+1)-1,stk(l1r),1,stk(l),1)
         l=l+istk(il+n+1)-1
         call dcopy(istk(il+1+m1)-istk(il+1+n),stk(l2r),1,stk(l),1)
         lstk(top+1)=l+istk(il+1+m1)-istk(il+1+n)
      endif
      goto 99
         
c

   99 return
      end
      integer function strpos(ptr,ns,chars,str,n)
      integer ptr(ns+1),ns,chars(*),str(n),n
      do 10 i=1,ns
         i1=ptr(i)
         i2=ptr(i+1)
         if(i2-i1.eq.n) then
            do 05 j=1,n
               if(str(j).ne.chars(i1-1+j)) goto 10
 05         continue
            strpos=i
            return
         endif
 10   continue
      strpos=0
      return
      end