File: logelm.f

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (462 lines) | stat: -rw-r--r-- 10,539 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
      subroutine logelm
c ================================== ( Inria    ) =============
c evaluation des fonctions elementaires sur les booleens
c =============================================================
c
c     Copyright INRIA
      include '../stack.h'

c
      if (ddt .eq. 4) then
         write(buf(1:4),'(i4)') fin
         call basout(io,wte,' logelm '//buf(1:4))
      endif

c     functions/fin
c     1      2     3    4
c   find   bool2s  or  and
c
c
c
      goto (10,20,30,40) fin
 10   call intfind
      return
 20   call intsbool2s
      return
 30   call intor('or')
      return
 40   call intand('and')
      return
      end
c
      subroutine intfind
      include '../stack.h'
c
      external gettype
      integer gettype,vt,top0
c
      top0=top
      if(rhs.ne.1.and.rhs.ne.2) then
         call error(39)
         return
      endif

      if(rhs.eq.2) then
c     max number of index to find
         call getrmat('find', top, top, m2, n2, l2)
         nmax=stk(l2)
         if(nmax.le.0.and.nmax.ne.-1) then
            err=2
            call error(116)
            return
         endif
         top=top-1
      else
         nmax=-1
      endif

      vt=gettype(top)
      if(vt.eq.1.or.vt.eq.4) then
         if(lhs.gt.2) then
            call error(39)
            return
         endif
         call intsfind(nmax)
      elseif(vt.eq.5.or.vt.eq.6) then
         if(lhs.gt.2) then
            call error(39)
            return
         endif
         call intspfind(nmax)
      else
c     .  overloaded find
         call putfunnam('find',top)
         top=top0
         fun=-1
         return
      endif
      return
      end

      subroutine intsfind(nmax)
c     find of a full standard or boolean matrix
      include '../stack.h'

      double precision tv
c
      logical ref
      integer nmax
      integer sadr,iadr
c
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      lw=lstk(top+1)
c

      
      il1=iadr(lstk(top))
      ilr=il1
      if(nmax.eq.0) then
         nt=nmax
         goto 17
      endif
      if(istk(il1).lt.0) il1=iadr(istk(il1+1))
      ref=ilr.ne.il1

      if(istk(il1).eq.1) then
c     argument is a standard matrix
         m1=istk(il1+1)
         mn1=istk(il1+1)*istk(il1+2)
         it1=istk(il1+3)
         if(it1.ne.0) then
            call putfunnam('find',top)
            if(nmax.ne.-1) top=top+1
            fun=-1
            return
         endif
         l1=sadr(il1+4)
         if(ref) then
            err=sadr(ilr+4)+mn1-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call icopy(4,istk(il1),1,istk(ilr),1)
         endif
         lr=sadr(ilr+4)
         l=lr
         if(mn1.gt.0) then
            if (nmax.lt.0) then
c     .     get all the occurences
               do 11 k=0,mn1-1
                  if(stk(l1+k).ne.0.0d0) then
                     stk(l)=float(k+1)
                     l=l+1
                  endif
 11            continue
            else
c     .     get at most nmax occurences
               do 12 k=0,mn1-1
                  if(stk(l1+k).ne.0.0d0) then
                     stk(l)=float(k+1)
                     l=l+1
                     if(l-lr.ge.nmax) goto 13
                  endif
 12            continue
            endif
 13         nt=l-lr
         else
            nt=0
         endif
      elseif(istk(il1).eq.4) then
c     argument is a full boolean matrix
         m1=istk(il1+1)
         mn1=istk(il1+1)*istk(il1+2)
         if(.not.ref) then
            il=max(il1+3+mn1,iadr(lstk(top)+mn1*lhs)+8)
            err=sadr(il+mn1)-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call icopy(mn1,istk(il1+3),1,istk(il),1)
         else
            il=il1+3
         endif
         istk(ilr)=1
         lr=sadr(ilr+4)
         if(mn1.gt.0) then
            l=lr
            if(nmax.lt.0) then
c     .     get all occurrences
               do 14 k=0,mn1-1
                  if(istk(il+k).ne.1) goto 14
                  stk(l)=float(k+1)
                  l=l+1
 14            continue
            else
c     .     get at most nmax occurences
               do 15 k=0,mn1-1
                  if(istk(il+k).ne.1) goto 15
                  stk(l)=float(k+1)
                  l=l+1
                  if(l-lr.ge.nmax) goto 16
 15            continue
            endif
 16         nt=l-lr
         else
            nt=0
         endif
      endif
 17   istk(ilr)=1
      istk(ilr+1)=min(1,nt)
      istk(ilr+2)=nt
      istk(ilr+3)=0
      lstk(top+1)=lr+nt
      if(lhs.eq.1) goto 999
      top=top+1
      il2=iadr(lstk(top))
      istk(il2)=1
      istk(il2+1)=min(1,nt)
      istk(il2+2)=nt
      istk(il2+3)=0
      l2=sadr(il2+4)
      lstk(top+1)=l2+nt
      if(nt.eq.0) goto 999
      do 18 k=0,nt-1
         stk(l2+k)=float(int((stk(lr+k)-1.0d0)/m1)+1)
         stk(lr+k)=stk(lr+k)-(stk(l2+k)-1.0d+0)*m1
 18   continue
      goto 999
c
  999 return
      end

      subroutine intspfind(nmax)
      include '../stack.h'

      logical ref
      double precision temp
      integer sadr,iadr
c
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      lw=lstk(top+1)


      il1=iadr(lstk(top))
      ilr=il1
      if(nmax.eq.0) then
         nt=nmax
         goto 17
      endif
      if(istk(il1).lt.0) il1=iadr(istk(il1+1))
      ref=ilr.ne.il1

c     sparse matrix find
      m1=istk(il1+1)
      n1=istk(il1+2)
      it1=istk(il1+3)
      if(it1.ne.0) then
         call putfunnam('find',top)
         if(nmax.ne.-1) top=top+1
         fun=-1
         return
      endif
      nel1=istk(il1+4)
      if(nel1.eq.0) then
         nt=0
         lr=sadr(ilr+4)
         goto 17
      endif
c
      if(.not.ref) then
         lr=lw
      else
         lr=sadr(ilr+4)
      endif
      err=lr+nel1-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif

      li=il1+5
      lj=li+m1

      l=lr
      ip=lj

      do 10 i=0,m1-1
         ni=istk(li+i)
         if(ni.ne.0) then
            do 01 ii=0,ni-1
               stk(l+ii)=(i+1)+(istk(ip+ii)-1)*m1
 01         continue
            l=l+ni
            ip=ip+ni
         endif
 10   continue

c     order the index column wise
      call dsort(stk(lr),nel1,istk(iadr(lr+nel1)))
      do 11 i=1,int(nel1/2)
         temp=stk(lr-1+i)
         stk(lr-1+i)=stk(lr+nel1-i)
         stk(lr+nel1-i)=temp
 11   continue

      nt=nel1
      if(nmax.ge.0) nt=min(nel1,nmax)

      if(.not.ref) then
         l=sadr(il1+4)
         call dcopy(nt,stk(lr),1,stk(l),1)
         lr=l
      endif

      
 17   istk(ilr)=1
      istk(ilr+1)=min(1,nt)
      istk(ilr+2)=nt
      istk(ilr+3)=0
      lstk(top+1)=lr+nt
      if(lhs.eq.1) return
      top=top+1
      il2=iadr(lstk(top))
      istk(il2)=1
      istk(il2+1)=min(1,nt)
      istk(il2+2)=nt
      istk(il2+3)=0
      l2=sadr(il2+4)
      lstk(top+1)=l2+nt
      if(nt.eq.0) return
      do 18 k=0,nt-1
         stk(l2+k)=float(int((stk(lr+k)-1.0d0)/m1)+1)
         stk(lr+k)=stk(lr+k)-(stk(l2+k)-1.0d+0)*m1
 18   continue

      return
      end

      subroutine intsbool2s
      include '../stack.h'

      logical ref
      integer sadr,iadr
c
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      lw=lstk(top+1)
c

   10 if(rhs.ne.1) then
         call error(39)
         return
      endif
      if(lhs.ne.1) then
         call error(39)
         return
      endif

      il1=iadr(lstk(top))
      ilr=il1
      if(istk(il1).lt.0) il1=iadr(istk(il1+1))
      ref=ilr.ne.il1
      mn1=istk(il1+1)*istk(il1+2)
      if (mn1.eq.0) return

      if(istk(il1).eq.4) then

c     argument is a full boolean matrix
         lr=sadr(ilr+4)
         err=lr+mn1-lstk(bot)
         if(err.gt.0) then
            call error(17)
            return
         endif

         do 13 k=mn1-1,0,-1
            stk(lr+k)=istk(il1+3+k)
 13      continue
         istk(ilr)=1
         istk(ilr+1)=istk(il1+1)
         istk(ilr+2)=istk(il1+2)
         istk(ilr+3)=0
         lstk(top+1)=lr+mn1
      elseif(istk(il1).eq.6) then
c     argument is a sparse boolean matrix
         m1=istk(il1+1)
         n1=istk(il1+2)
         nel1=istk(il1+4)
c   
         if(ref) then
            err=sadr(ilr+5+m1+nel1)+nel1-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call icopy(m1+nel1,istk(il1+5),1,istk(ilr+5),1)
         endif
         lj=sadr(ilr+5+m1+nel1)
         call dset(nel1,1.0d0,stk(lj),1)
         istk(ilr)=5
         istk(ilr+1)=istk(il1+1)
         istk(ilr+2)=istk(il1+2)
         istk(ilr+3)=0
         istk(ilr+4)=nel1
         lstk(top+1)=lj+nel1
      elseif(istk(il1).eq.1) then
         if(istk(il1+3).ne.0) then
            call putfunnam('bool2s',top)
            fun=-1
            return
         endif
         
         if(mn1.eq.0) then
            istk(ilr)=1
            istk(ilr+1)=0
            istk(ilr+2)=0
            istk(ilr+3)=0
            lstk(top+1)=lr
         else
            l1=sadr(il1+4)
            lr=sadr(ilr+4)
            if(ref) then
               err=lr+mn1-lstk(bot)
               if(err.gt.0) then
                  call error(17)
                  return
               endif
            endif
            do 20 k=mn1-1,0,-1
               if(stk(l1+k).ne.0.0d0) then
                  stk(lr+k)=1.0d0
               else
                  stk(lr+k)=0.0d0
               endif
 20         continue
            istk(ilr)=1
            istk(ilr+1)=istk(il1+1)
            istk(ilr+2)=istk(il1+2)
            istk(ilr+3)=0
            lstk(top+1)=lr+mn1
         endif
      elseif(istk(il1).eq.5) then
c     argument is a sparse matrix
         m1=istk(il1+1)
         n1=istk(il1+2)
         nel1=istk(il1+4)
         if(istk(il1+3).ne.0) then
            call putfunnam('bool2s',top)
            fun=-1
            return
         endif
c
         if(ref) then
            err=sadr(ilr+5+m1+nel1)+nel1-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call icopy(m1+nel1,istk(il1+5),1,istk(ilr+5),1)
         endif
         lj=sadr(ilr+5+m1+nel1)
         call dset(nel1,1.0d0,stk(lj),1)
         istk(ilr)=5
         istk(ilr+1)=istk(il1+1)
         istk(ilr+2)=istk(il1+2)
         istk(ilr+3)=0
         istk(ilr+4)=nel1
         lstk(top+1)=lj+nel1
      else
         call putfunnam('bool2s',top)
         fun=-1
         return
      endif
      end