File: strops.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 (638 lines) | stat: -rw-r--r-- 15,578 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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
      subroutine strops
c ====================================================================
c
c   operations sur les matrices de chaines de caracteres
c
c ====================================================================
c
      include '../stack.h'
c
      integer plus,quote,equal,less,great,insert,extrac
      integer top0,iadr,sadr,op,vol,volr,rhs1
      logical iscolon
      data plus/45/,quote/53/
      data equal/50/,less/59/,great/60/,insert/2/,extrac/3/
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c 
      op=fin
c
      if (ddt .eq. 4) then
         write(buf(1:4),'(i4)') fin
         call basout(io,wte,' strops '//buf(1:4))
      endif
c
      fun=0
c
      top0=top
c
      lw=lstk(top+1)
      rhs1=rhs
      if(op.eq.insert) rhs=2
      if(op.eq.extrac) rhs=1
c
      if(rhs.eq.1) goto 05
      il2=iadr(lstk(top))
      if(istk(il2).lt.0) il2=iadr(istk(il2+1))
      m2=istk(il2+1)
      n2=istk(il2+2)
      it2=istk(il2+3)
      mn2=m2*n2
      id2=il2+4
      l2r=id2+mn2+1
      l3r=lw
c
      top = top-1
   05 il1=iadr(lstk(top))
      if(istk(il1).lt.0) il1=iadr(istk(il1+1))
      m1=istk(il1+1)
      n1=istk(il1+2)
      it1=istk(il1+3)
      mn1 = m1*n1
      id1=il1+4
      l1r=id1+mn1+1
      vol=istk(id1+mn1)-1
c
      goto (60,120,130,65) op
      if (rhs .eq. 1.and.op.eq.quote) goto 110
      if (op .eq. plus ) go to 20
      if(op.eq.equal.or.op.eq.less+great) goto 180
c
c     operations non implantees
 10   top=top0
      rhs=rhs1
      fin=-fin
      return


c
c addition
c
   20 if(m1.ne.m2.or.n1.ne.n2) then
         call error(8)
         return
      endif
      if(istk(il1).ne.istk(il2)) goto 10
      err=lw+sadr(istk(id1+mn1)+istk(id2+mn2))-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
c
      lr=iadr(lw)
      l=lr
      i1=1
      do 11 i=1,mn1
      la=istk(id1+i)-i1
      lb=istk(id2+i)-istk(id2+i-1)
      i1=istk(id1+i)
      istk(id1+i)=istk(id1+i-1)+la+lb
      call icopy(la,istk(l1r),1,istk(l),1)
      l1r=l1r+la
      l=l+la
      call icopy(lb,istk(l2r),1,istk(l),1)
      l2r=l2r+lb
      l=l+lb
11    continue
      call icopy(l-lr,istk(lr),1,istk(il1+5+mn1),1)
      lstk(top+1)=sadr(il1+5+mn1+l-lr)
      goto 999
c
c concatenation [a, b]
c
   60 continue
      if(m1.lt.0.or.m2.lt.0) then
            call error(14)
            return
      endif
      if(m2.eq.0) then
         return
      elseif(m1.eq.0)then
         call dcopy(lstk(top+2)-lstk(top+1),stk(lstk(top+1)),1,
     &        stk(lstk(top)),1)
         lstk(top+1)=lstk(top)+lstk(top+2)-lstk(top+1)
         return
      elseif(m1.ne.m2) then
         call error(5)
         return
      endif
      if(istk(il1).ne.istk(il2)) goto 10
c
      id3=iadr(lw)
      l3r=id3+mn1+mn2+1
      vol=istk(id1+mn1)+istk(id2+mn2)-2
      err=sadr(l3r+vol)-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
      call impcnc(istk(l1r),istk(id1),m1,istk(l2r),istk(id2),m1,
     & istk(l3r),istk(id3),m1,n1,n2,1)
c
      istk(il1)=10
      istk(il1+1)=m1
      istk(il1+2)=n1+n2
      istk(il1+3)=it1
      call icopy(mn1+mn2+vol+1,istk(id3),1,istk(il1+4),1)
      lstk(top+1)=sadr(il1+5+mn1+mn2+vol)
      goto 999
c
c     concatenation [a;b]
 65   continue
      if(n1.lt.0.or.n2.lt.0) then
            call error(14)
            return
      endif
      if(n2.eq.0) then
         return
      elseif(n1.eq.0)then
         call dcopy(lstk(top+2)-lstk(top+1),stk(lstk(top+1)),1,
     &        stk(lstk(top)),1)
         lstk(top+1)=lstk(top)+lstk(top+2)-lstk(top+1)
         return
      elseif(n1.ne.n2) then
         call error(6)
         return
      endif
      if(istk(il1).ne.istk(il2)) goto 10
c
      id3=iadr(lw)
      l3r=id3+mn1+mn2+1
      vol=istk(id1+mn1)+istk(id2+mn2)-2
      err=sadr(l3r+vol)-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
      call impcnc(istk(l1r),istk(id1),m1,istk(l2r),istk(id2),m2,
     & istk(l3r),istk(id3),m1,m2,n2,-1)
c
      istk(il1)=10
      istk(il1+1)=m1+m2
      istk(il1+2)=n1
      istk(il1+3)=it1
      call icopy(mn1+mn2+vol+1,istk(id3),1,istk(il1+4),1)
      lstk(top+1)=sadr(il1+5+mn1+mn2+vol)
      goto 999
c
c transposition
c
  110 continue
      id2=iadr(lw)
      l2r=id2+mn1+1
      err=sadr(l2r+vol)-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
      call imptra(istk(l1r),istk(id1),m1,istk(l2r),istk(id2),m1,n1)
      istk(il1+1)=n1
      istk(il1+2)=m1
      call icopy(mn1+1+vol,istk(id2),1,istk(id1),1)
      goto 999
c
c insertion
c
c     a(vl,vc)=m  a(v)=u
  120 continue
      ili=iadr(lstk(top0-1))
      if (istk(ili+1)*istk(ili+2).eq.0) then
         top=top0
         rhs=rhs1
         fin=-fin
         return
      endif

      if(istk(il1).ne.istk(il2)) then
          if(istk(il2).ne.1.or.m2*n2.ne.0) goto 10
      endif
      rhs=rhs1-2
      nrow=-1
c
      top=top-1
      if(m1.le.0) then
         call error(14)
         return
      endif
      ilcol=iadr(lstk(top))
      if(istk(ilcol).eq.4) then
         rhs=rhs1
         top=top0
         fin=-fin
         return
      endif

      if(istk(ilcol).ne.1) then
         call error(21)
         return
      endif
      if(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
      ncol=isign(istk(ilcol+1)*istk(ilcol+2),istk(ilcol+1))
      lcol=sadr(ilcol+4)
      if(ncol.lt.0) goto 122
      do 121 i=1,ncol
      istk(ilcol-1+i)=int(stk(lcol-1+i))
  121 continue
  122 continue
      ilrow=ilcol
      if(rhs.eq.1.and.n2.eq.1) then
        nrow=ncol
        ilrow=ilcol
        ncol=-1
      endif
c
      if(rhs.eq.1) then
c     arg3(arg1)=arg2
         if (m2.gt.1.and.n2.gt.1) then
c     .  arg3 is a matrix
            call dimin(m2*n2,1,istk(ilcol),ncol,istk(ilrow),-1,m1*n1,1,
     &           mr,nr,err)
            if(err.gt.0.or.mr.gt.m2*n2) then
               call error(21)
               return
            endif

            idr=iadr(l3r)
            lr=idr+m2*n2+1
            err=sadr(lr)-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call mpinsp(istk(id2),m2*n2,1,istk(ilcol),ncol,istk(ilrow),
     &           -1,istk(id1),m1*n1,1,istk(idr),m2*n2,1,err)
 
            if(err.gt.0) then
               call error(15)
               return
            endif
            volr=istk(idr)
            err=sadr(lr+volr)-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call impins(istk(l2r),istk(id2),m2*n2,1, istk(l1r),
     &          istk(id1),m1*n1,1,istk(lr),istk(idr),m2*n2,1)
            il1=iadr(lstk(top))
            istk(il1)=10
            istk(il1+1)=m2
            istk(il1+2)=n2
            istk(il1+3)=it1
            volr=istk(idr+m2*n2)
            call icopy(m2*n2+1+volr,istk(idr),1,istk(il1+4),1)
            lstk(top+1)=sadr(il1+5+m2*n2+volr)
         else
            call dimin(m2,n2,istk(ilrow),nrow,istk(ilcol),ncol,m1,n1,
     &           mr,nr,err)
            if(err.gt.0) then
               call error(21)
               return
            endif
            idr=iadr(l3r)
            lr=idr+mr*nr+1
            err=sadr(lr)-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call mpinsp(istk(id2),m2,n2,istk(ilrow),nrow,istk(ilcol),
     &           ncol,istk(id1),m1,n1,istk(idr),mr,nr,err)
            if(err.gt.0) then
               call error(15)
               return
            endif
            volr=istk(idr)
            err=sadr(lr+volr)-lstk(bot)
            if(err.gt.0) then
               call error(17)
               return
            endif
            call impins(istk(l2r),istk(id2),m2,n2,
     &           istk(l1r),istk(id1),m1,n1,istk(lr),istk(idr),mr,nr)
c     
            il1=iadr(lstk(top))
            istk(il1)=10
            istk(il1+1)=mr
            istk(il1+2)=nr
            istk(il1+3)=it1
            volr=istk(idr+mr*nr)
            call icopy(mr*nr+1+volr,istk(idr),1,istk(il1+4),1)
            lstk(top+1)=sadr(il1+5+mr*nr+volr)
         endif
      else
c     arg4(arg1,arg2)=arg3
            top=top-1
         ilrow=iadr(lstk(top))
         if(istk(ilrow).eq.4) then
            rhs=rhs1
            top=top0
            fin=-fin
            return
         endif

         if(istk(ilrow).ne.1) then
            call error(21)
            return
         endif
         if(istk(ilrow+3).ne.0) then
            call error(21)
            return
         endif
         if(istk(ilrow+1).gt.1.and.istk(ilrow+2).gt.1) then
            call error(21)
            return
         endif
         nrow=isign(istk(ilrow+1)*istk(ilrow+2),istk(ilrow+1))
         lrow=sadr(ilrow+4)
         if(nrow.lt.0) goto 124
         do 123 i=1,nrow
            istk(ilrow-1+i)=int(stk(lrow-1+i))
 123     continue
 124     continue
c     
 125     call dimin(m2,n2,istk(ilrow),nrow,istk(ilcol),ncol,m1,n1,
     &        mr,nr,err)
         if(err.gt.0) then
            call error(21)
            return
         endif
         idr=iadr(l3r)
         lr=idr+mr*nr+1
         err=sadr(lr)-lstk(bot)
         if(err.gt.0) then
            call error(17)
            return
         endif
         call mpinsp(istk(id2),m2,n2,istk(ilrow),nrow,istk(ilcol),ncol,
     &        istk(id1),m1,n1,istk(idr),mr,nr,err)
         if(err.gt.0) then
            call error(15)
            return
         endif
         volr=istk(idr)
         err=sadr(lr+volr)-lstk(bot)
         if(err.gt.0) then
            call error(17)
            return
         endif
         call impins(istk(l2r),istk(id2),m2,n2,
     &        istk(l1r),istk(id1),m1,n1,istk(lr),istk(idr),mr,nr)
c     
         il1=iadr(lstk(top))
         istk(il1)=10
         istk(il1+1)=mr
         istk(il1+2)=nr
         istk(il1+3)=it1
         volr=istk(idr+mr*nr)
         call icopy(mr*nr+1+volr,istk(idr),1,istk(il1+4),1)
         lstk(top+1)=sadr(il1+5+mr*nr+volr)
      endif
      goto 999
c
c
c extraction
c
  130 rhs=rhs1-1
      mr=-1
      nrow=-1
c
      if(m1.le.0) then
         call error(14)
         return
      endif
c
      top=top-1
      ilcol=iadr(lstk(top))
      if(istk(ilcol).eq.4) then
         rhs=rhs1
         top=top0
         fin=-fin
         return
      endif

      if(istk(ilcol).ne.1) then
         call error(21)
         return
      endif
      if(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
      ncol=isign(istk(ilcol+1)*istk(ilcol+2),istk(ilcol+1))
      nr=ncol
      lcol=sadr(ilcol+4)
      if(ncol.eq.0) goto 146
      if(ncol.lt.0) goto 132
      do 131 i=1,ncol
      istk(ilcol-1+i)=int(stk(lcol-1+i))
  131 continue
  132 continue
c
      if(rhs.eq.1) then
         iscolon=ncol.lt.0
c     vect(arg)
         if(n1.eq.1) then
c     vect is a column vector
            mr=nr
            nr=1
            nrow=ncol
            ilrow=ilcol
            ncol=-1
         else
c     vect is a row vector
            mr=1
            if(m1.ne.1) then
               n1=mn1
               m1=1
            endif
            nrow=-1
            ilrow=ilcol
         endif
         if(iscolon) then
c     vect(:)
            mr=m1*n1
            nr=1
         endif
      else
         top=top-1
         ilrow=iadr(lstk(top))
         if(istk(ilrow).eq.4) then
            rhs=rhs1
            top=top0
            fin=-fin
            return
         endif

         if(istk(ilrow).ne.1) then
            call error(21)
            return
         endif
         if(istk(ilrow+3).ne.0) then
            call error(21)
            return
         endif
         if(istk(ilrow+1).gt.1.and.istk(ilrow+2).gt.1) then
            call error(21)
            return
         endif
         nrow=isign(istk(ilrow+1)*istk(ilrow+2),istk(ilrow+1))
         mr=nrow
         lrow=sadr(ilrow+4)
         if(nrow.eq.0) goto 146
         if(nrow.lt.0) goto 142
         do 141 i=1,nrow
            istk(ilrow-1+i)=int(stk(lrow-1+i))
 141     continue
 142     continue
c     
c     matrix(arg,arg)
         if(mr.lt.0) mr=m1
         if(nr.lt.0) nr=n1
      endif
c
  145 mnr=mr*nr
      idr=iadr(lw)
      lr=idr+mnr+1
      err=sadr(lr)-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
c
      call impext(istk(l1r),istk(id1),m1,n1,istk(ilrow),nrow,
     &    istk(ilcol),ncol,istk(lr),istk(idr),0,err)
      if(err.gt.0) then
         call error(21)
         return
      endif
      volr=istk(idr+mnr)-1
      err=sadr(lr+volr)-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
      call impext(istk(l1r),istk(id1),m1,n1,istk(ilrow),nrow,
     &            istk(ilcol),ncol,istk(lr),istk(idr),1,err)
c
      il1=iadr(lstk(top))
      istk(il1)=10
      istk(il1+1)=mr
      istk(il1+2)=nr
      istk(il1+3)=it1
      call icopy(mnr+1+volr,istk(idr),1,istk(il1+4),1)
      lstk(top+1)=sadr(il1+5+mnr+volr)
      go to 999
  146 continue
c un des vecteurs d'indice est vide
      top=top0-rhs1+1
      il1=iadr(lstk(top))
      istk(il1)=1
      istk(il1+1)=0
      istk(il1+2)=0
      lstk(top+1)=sadr(il1+4)+1
      goto 999
c
c     comparaisons
 180  continue
      itrue=1
      if(op.eq.less+great) itrue=0
c     comparaison des types
      if(istk(il1).ne.istk(il2)) then
         istk(il1)=4
         istk(il1+1)=1
         istk(il1+2)=1
         istk(il1+3)=1-itrue
         lstk(top+1)=sadr(il1+4)
         return
      endif
 181  continue
c     des dimensions
      if(mn1.eq.1.and.mn2.gt.1) then
         nn1=istk(il1+5)-1
         l1r=iadr(lw)
         err=sadr(l1r+nn1+2)-lstk(bot)
         if(err.gt.0) then
            call error(17)
            return
         endif
         call icopy(nn1,istk(il1+6),1,istk(l1r),1)
         id1=l1r+nn1
         istk(id1)=1
         istk(id1+1)=nn1+1
         inc1=0
         inc2=1
         mn1=mn2
         m1=m2
         n1=n2
         istk(il1+1)=m1
         istk(il1+2)=n1
      else if(mn2.eq.1.and.mn1.gt.1) then
         nn2=istk(il2+5)-1
         l2r=iadr(lw)
         err=sadr(l2r+nn2+2)-lstk(bot)
         if(err.gt.0) then
            call error(17)
            return
         endif
         call icopy(nn2,istk(il2+6),1,istk(l2r),1)
         id2=l2r+nn2
         istk(id2)=1
         istk(id2+1)=nn2+1
         inc1=1
         inc2=0
         mn2=mn1
         m2=m1
         n2=n1
      else if(n1.ne.n2.or.m1.ne.m2) then
         istk(il1)=4
         istk(il1+1)=1
         istk(il1+2)=1
         istk(il1+3)=1-itrue
         lstk(top+1)=sadr(il1+4)
         return
      else
         inc1=1
         inc2=1
         l1=il1+5+mn1
         l2=il2+5+mn2
      endif
c     des valeurs
      i1=id1-inc1
      i2=id2-inc2
      l1r=l1r-1
      l2r=l2r-1
      do 185 i=0,mn1-1
         i1=i1+inc1
         i2=i2+inc2
         if(istk(i1+1)-istk(i1).ne.istk(i2+1)-istk(i2) ) goto 184
         nl=istk(i1+1)-istk(i1)-1
         do 182 ii=0,nl
            if(istk(l1r+istk(i1)+ii).ne.istk(l2r+istk(i2)+ii)) goto 184
 182     continue
         istk(il1+3+i)=itrue
         goto 185
 184     istk(il1+3+i)=1-itrue
 185  continue
      istk(il1)=4
      istk(il1+1)=m1
      istk(il1+2)=n1
      lstk(top+1)=sadr(il1+3+mn1)
      goto 999

c

  999 return
      end