File: matlu.f

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (863 lines) | stat: -rw-r--r-- 19,106 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
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
      subroutine matlu
c ====================================================================
c
c     evaluate functions involving gaussian elimination
c
c ====================================================================
c
c     Copyright INRIA
      include '../stack.h'
      integer id(nsiz),io
c
c     fonction / fin
c     -2   -1    1    2     3    4   5    6    7     
c      \    /   inv  det  rcond  lu      chol  rref 
c
      if (ddt .eq. 4) then
         write(buf(1:4),'(i4)') fin
         call basout(io,wte,' matlu '//buf(1:4))
      endif
c
      if(rhs.le.0) then
         call error(39)
         return
      endif
c
      go to (20,10,99,30,40,50,60,99,80,85),fin+3
c
 10   continue
c     matrix right division, a/a2
      call intrdiv
      goto 99
c
 20   continue
      call intldiv
      goto 99
c
 30   continue
c     inv
      call intinv
      goto 99
c
 40   continue
c     det
      call intdet
      return
c
 50   continue
c     rcond
      call intrcond
      goto 99
c
 60   continue
c     lu
      call intlu
      goto 99
c
 80   continue
c     cholesky
      call intchol
      go to 99
c
 85   continue
c     rref
      call intrref
      go to 99

 99   return
      end

      subroutine intlu
c     lu
      include '../stack.h'
      integer iadr,sadr
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
c     Check number of arguments
      if (rhs .ne. 1) then
         call error(39)
         return
      endif
      if (lhs .ne. 2 .and.lhs .ne. 3) then
         call error(41)
         return
      endif
c     Check input argument type
      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         call putfunnam('lu',top-rhs+1)
         fun=-1
         return
      endif
      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)

      nn=n*n

      if (m .ne. n) then
         err=rhs
         call error(20)
         return
      endif

c     form output matrices
      top = top+1
      ilu=iadr(lstk(top))
      lu=sadr(ilu+4)
      lstk(top+1)=lu+nn*(it+1)
      if(lhs.eq.3) then
         top = top+1
         ile=iadr(lstk(top))
         le=sadr(ile+4)
         lstk(top+1)=le+nn
      endif
      ilp=iadr(lstk(top+1))
c     check for space
      err = sadr(ilp+n) -lstk(bot)
      if (err .gt. 0) then
         call error(17)
         return
      endif
c
      istk(ilu)=1
      istk(ilu+1)=n
      istk(ilu+2)=n
      istk(ilu+3)=it
      if(lhs.eq.3) then
         istk(ile)=1
         istk(ile+1)=n
         istk(ile+2)=n
         istk(ile+3)=0
      endif
      if(nn.le.0) then
c     lu of an empty matrix
         go to 99
      endif

c     Compute factorisation
      if(it.eq.0) then
         call dgefa(stk(l),m,n,istk(ilp),info)
      else
         call wgefa(stk(l),stk(l+nn),m,n,istk(ilp),info)
      endif
c     Form output matrices
      call dset(nn*(it+1),0.0d0,stk(lu),1)
      do 12 kb = 1, n
         k = n+1-kb
         ll=l+(k-1)*n
         luk=lu+(k-1)*n
c     .  copy upper triangle in U
         call dcopy(k,stk(ll),1,stk(luk),1)
         if(k.ne.n) then
            call dscal(n-k,-1.0d+0,stk(ll+k),1)
         endif
c     .  set lower triangle of L to 0
         call dset(k,0.0d+0,stk(ll),1)
         stk(ll+k-1)=1.0d+0
c     
         i = istk(ilp+k-1)
         if (i .ne. k) then
            li = l+i-1+(k-1)*n
            lk = l+k-1+(k-1)*n
            call dswap(n-k+1,stk(li),n,stk(lk),n)
         endif
 12   continue
      if(it.eq.1) then
c     L and U Imaginary part
         do 14 kb = 1, n
            k = n+1-kb
            ll=l+nn+(k-1)*n
            luk=lu+nn+(k-1)*n
            call dcopy(k,stk(ll),1,stk(luk),1)
            if(k.ne.n) then
               call dscal(n-k,-1.0d+0,stk(ll+k),1)
            endif
            call dset(k,0.0d0,stk(ll),1)
 14      continue
         i = istk(ilp+k-1)
         if (i .ne. k) then
            li = l+i-1+(k-1)*n
            lk = l+k-1+(k-1)*n
            call dswap(n-k+1,stk(li),n,stk(lk),n)
         endif
      endif
      if(lhs.eq.3) then
         call dset(nn,0.0d0,stk(le),1)
         call dset(n,1.0d0,stk(le),n+1)
         do 16 kb = 1, n
            k = n+1-kb
            i = istk(ilp+k-1)
            if (i .ne. k) then
               call dswap(n,stk(le+(i-1)*n),1,stk(le+(k-1)*n),1)
            endif
 16      continue
         do 17 k = 1, n
            i = istk(ilp+k-1)
            if (i .ne. k) then
               call dswap(n,stk(l+(i-1)),n,stk(l+(k-1)),n)
               if(it.eq.1) then
                  call dswap(n,stk(l+nn+(i-1)),n,stk(l+nn+(k-1)),n)
               endif
            endif
 17      continue

      endif
 99   continue
      return
      end

      subroutine intchol
c     Cholesky
      include '../stack.h'
      integer iadr,sadr
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
c     Check number of arguments
      if (rhs .ne. 1) then
         call error(39)
         return
      endif
      if (lhs .ne. 1) then
         call error(41)
         return
      endif
c     Check argument type
      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         call putfunnam('chol',top-rhs+1)
         fun=-1
         return
      endif
      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)
      nn=n*n
c     Check argument dimension
      if (m .ne. n) then
         err=rhs
         call error(20)
         return
      endif
c
      if(nn.le.0) return
      if(it.eq.1) call wpofa(stk(l),stk(l+nn),m,n,err)
      if(it.eq.0) call dpofa(stk(l),m,n,err)
      if (err .ne. 0) then
         call error(29)
         return
      endif
      do 81 j = 1, n
         ll = l+j+(j-1)*m
         call dcopy(m-j,0.0d+0,0,stk(ll),1)
         if(it.eq.1) call dcopy(m-j,0.0d+0,0,stk(ll+nn),1)
 81   continue
      return
      end

      subroutine intrref
      include '../stack.h'
      double precision eps
      integer iadr,sadr
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      eps=stk(leps)
c
c     Check number of arguments
      if (rhs .ne. 1) then
         call error(39)
         return
      endif
      if (lhs .ne. 1) then
         call error(41)
         return
      endif

c     Check argument type
      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         call putfunnam('rref',top-rhs+1)
         fun=-1
         return
      endif

      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)
      mn=m*n
      if(mn.le.0) return
c
      if(it.eq.0) then
         call drref(stk(l),m,m,n,eps)
      else
         call wrref(stk(l),stk(l+mn),m,m,n,eps)
      endif
      return
      end

      subroutine intrcond
      include '../stack.h'
      double precision sr,si,rcond
      integer iadr,sadr
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c     
c     Check number of arguments
      if (rhs .ne. 1) then
         call error(39)
         return
      endif
      if (lhs .gt. 2) then
         call error(41)
         return
      endif
c
c     Check  argument type
      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         call putfunnam('rcond',top-rhs+1)
         fun=-1
         return
      endif

      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)
      nn=n*n
c     Check  argument size
      if (m .ne. n) then
         err=rhs
         call error(20)
         return
      endif


      l3 = l + nn*(it+1)
      err = l3+n*(it+1)+sadr(n) - lstk(bot)
      if (err .gt. 0) then
         call error(17)
         return
      endif

      if(nn.le.0) then
c     empty matrix case
         rcond=1.0d0
      else
         if(it.eq.0) then
            call dlslv(stk(l),m,n,sr,0,0,stk(l3),rcond,ierr,0)
         else
            call wlslv(stk(l),stk(l+nn),m,n,sr,si,0,0,stk(l3),
     $           rcond,ierr,0)
         endif
      endif
      stk(l) = rcond
      istk(il+1)=1
      istk(il+2)=1
      istk(il+3)=0
      lstk(top+1)=l+1
      if (lhs .gt. 1) then
         top=top+1
         il=iadr(lstk(top))
         istk(il)=1
         if(nn.eq.0) then
            istk(il+1)=0
            istk(il+2)=0
            istk(il+3)=0
            lstk(top+1)=sadr(il+4)+1
         else
            istk(il+1)=n
            istk(il+2)=1
            istk(il+3)=it
            l=sadr(il+4)
            call dcopy(n*(it+1),stk(l3+sadr(n)),1,stk(l),1)
            lstk(top+1)=l+n*(it+1)
         endif
      endif
      return
      end

      subroutine intdet
      include '../stack.h'
      double precision dtr(2),dti(2),sr,si,t
      integer iadr,sadr
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      if (rhs .ne. 1) then
         call error(39)
         return
      endif
      if (lhs .gt. 2) then
         call error(41)
         return
      endif
c
      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         call putfunnam('det',top-rhs+1)
         fun=-1
         return
      endif
c
      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)
      mn=m*n
      nn=n*n

      if (m .ne. n) then
         err=1
         call error(20)
         return
      endif
      if(mn.le.0) goto 47
      ilp=iadr(l+mn*(it+1))
      lw=sadr(ilp+n)
      err=lw-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif

      if(it.eq.0) then
         call dgefa(stk(l),m,n,istk(ilp),info)
         call dgedi(stk(l),m,n,istk(ilp),dtr,sr,10)
      else
       call wgefa(stk(l),stk(l+mn),m,n,istk(ilp),info)
       call wgedi(stk(l),stk(l+mn),m,n,istk(ilp),dtr,dti,
     &     sr,si,10)
      endif
      k = int(dtr(2))

      if(lhs.eq.1) then
         stk(l) = dtr(1)*10.0d+0**int(dtr(2))
         if(it.eq.1) stk(l+1) = dti(1)*10.0d+0**int(dtr(2))
         istk(il+1)=1
         istk(il+2)=1
         lstk(top+1)=l+it+1
      else
         stk(l) = dtr(2)
         istk(il+1)=1
         istk(il+2)=1
         istk(il+3)=0
         lstk(top+1)=l+1
         top=top+1
         il=iadr(lstk(top))
         istk(il)=1
         istk(il+1)=1
         istk(il+2)=1
         istk(il+3)=it
         l=sadr(il+4)
         stk(l)=dtr(1)
         if(it.eq.1) stk(l+1)=dti(1)
         lstk(top+1)=l+(it+1)
      endif
      go to 99
c cas de la matrice vide
   47 continue
      if(lhs.eq.1) then
         istk(il+1)=1
         istk(il+2)=1
         lstk(top+1)=l+it+1
         stk(l)=1.0d+0
         if (it.eq.1) stk(l+1)=0.0d+0
      else
         stk(l) = 0.0d0
         istk(il+1)=1
         istk(il+2)=1
         istk(il+2)=0
         lstk(top+1)=l+1
         top=top+1
         il=iadr(lstk(top))
         istk(il)=1
         istk(il+1)=1
         istk(il+2)=1
         istk(il+3)=it
         l=sadr(il+4)
         stk(l)=1.0d+0
         if (it.eq.1) stk(l+1)=0.0d+0
         lstk(top+1)=l+(it+1)
      endif
      go to 99
 99   continue
      return
      end

      subroutine intinv
      include '../stack.h'
      double precision sr,si,rcond,t
      integer iadr,sadr
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      if (rhs .ne. 1) then
         call error(39)
         return
      endif
      if (lhs .ne. 1) then
         call error(41)
         return
      endif
c
      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         call putfunnam('inv',top-rhs+1)
         fun=-1
         return
      endif

      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)
      mn=m*n
      nn=n*n

      if (m .ne. n) then
         err=rhs
         call error(20)
         return
      endif
c
      n=abs(n)
      if(mn.le.0) return
      l3 = l + nn*(it+1)
      err = l3+n*(it+1)+sadr(n) - lstk(bot)
      if (err .gt. 0) then
         call error(17)
         return
      endif
      if(it.eq.0) then
         call dlslv(stk(l),n,n,sr,0,0,stk(l3),rcond,err,3)
      else
         call wlslv(stk(l),stk(l+nn),n,n,sr,si,0,0,stk(l3),
     $     rcond,err,3)
      endif
      if (rcond .eq. 0.0d+0) then
         call error(19)
         return
      endif
      t = 1.0d+0 + rcond
      if (t .eq. 1.0d+0) then
         write(buf(1:13),'(1pd13.4)') rcond
c       matrice est quasi singuliere ou mal normalisee')
         call msgs(5,0)
      endif
      return
      end

      subroutine intldiv
c     matrix left division a backslash a2
      include '../stack.h'
      double precision sr,si,rcond,t
      integer iadr,sadr
c
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c     
      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         err=rhs
         call error(53)
         return
      endif
c
      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)
      mn=m*n
      nn=n*n

      top=top-1
      il2=iadr(lstk(top+1))
      if(istk(il2).ne.1) then
         err=rhs
         call error(53)
         return
      endif
      m2=istk(il2+1)
      n2=istk(il2+2)
      it2=istk(il2+3)
      l2=sadr(il2+4)
      mn2=m2*n2
c
      if (m .ne. n) then
         err=rhs
         call error(20)
         return
      endif
      if (mn2 .eq. 1) go to 26
      if (mn2.le.0) then
         err=rhs
         call error(45)
         return
      endif
      if (mn.le.0) then
         lstk(top+1)=l
         return
      endif
      if (m2 .ne. n) then
         call error(12)
         return
      endif
      l3=l2+(max(it,it2)+1)*mn2
      err = l3+n*(it+1)+sadr(n) - lstk(bot)
      if (err .gt. 0) then
         call error(17)
         return
      endif
c
      if(it.eq.1) then
         if(it2.eq.0) call dcopy(mn2,0.0d+0,0,stk(l2+mn2),1)
         call wlslv(stk(l),stk(l+mn),m,n,stk(l2),stk(l2+mn2),
     &        m2,n2,stk(l3),rcond,err,1)
      else
         call dlslv(stk(l),m,n,stk(l2),m2,n2*(it2+1),stk(l3),
     &        rcond,err,1)
      endif
c
      if (rcond .eq. 0.0d+0) then
         call error(19)
         return
      endif
      t = 1.0d+0 + rcond
c
      if (t .eq. 1.0d+0) then
         write(buf(1:13),'(1pd13.4)') rcond
         call msgs(5,0)
      endif
c
      istk(il+2)=n2
      it=max(it,it2)
      istk(il+3)=it
      lstk(top+1)=l+mn2*(it+1)
      call dcopy(mn2*(it+1),stk(l2),1,stk(l),1)
      go to 99
 26   sr = stk(l2)
      si=0.0d+0
      if(it2.eq.1) si = stk(l2+1)

      if (m .ne. n) then
         err=rhs
         call error(20)
         return
      endif
      n=abs(n)
      if(mn.le.0) return
      l3 = l + nn*(it+1)
      err = l3+n*(it+1)+sadr(n) - lstk(bot)
      if (err .gt. 0) then
         call error(17)
         return
      endif
      if(it.eq.0) then
         call dlslv(stk(l),n,n,sr,0,0,stk(l3),rcond,err,3)
      else
         call wlslv(stk(l),stk(l+nn),n,n,sr,si,0,0,stk(l3),
     $     rcond,err,3)
      endif
      if (rcond .eq. 0.0d+0) then
         call error(19)
         return
      endif
      t = 1.0d+0 + rcond
      if (t .eq. 1.0d+0) then
         write(buf(1:13),'(1pd13.4)') rcond
c       matrice est quasi singuliere ou mal normalisee')
         call msgs(5,0)
      endif
      goto(33,34,35) (it+2*it2)
 33   call dscal(nn*(it+1),sr,stk(l),1)
      istk(il+3)=it
      lstk(top+1)=l+m*n*(it+1)
      goto 99
 34   call dcopy(nn,stk(l),1,stk(l+nn),1)
      call dscal(nn,sr,stk(l),1)
      call dscal(nn,si,stk(l+nn),1)
      istk(il+3)=1
      lstk(top+1)=l+2*nn
      goto 99
 35   call wscal(nn,sr,si,stk(l),stk(l+nn),1)
      go to 99
 99   continue
      return
      end

      subroutine intrdiv
      include '../stack.h'
      double precision eps,sr,si,rcond,t
      integer iadr,sadr
c     
      iadr(l)=l+l-1
      sadr(l)=(l/2)+1
c
      eps=stk(leps)

      il=iadr(lstk(top-rhs+1))
      if (istk(il).ne.1) then
         err=rhs
         call error(53)
         return
      endif
      m=istk(il+1)
      n=istk(il+2)
      it=istk(il+3)
      l=sadr(il+4)
      mn=m*n
      nn=n*n
c
      top=top-1
      il2=iadr(lstk(top+1))
      if(istk(il2).ne.1) then
         err=rhs
         call error(53)
         return
      endif
      m2=istk(il2+1)
      n2=istk(il2+2)
      it2=istk(il2+3)
      itr=max(it,it2)
      l2=sadr(il2+4)
      mn2=m2*n2
c
      if (m2 .ne. n2) then
         err=rhs
         call error(20)
         return
      endif
      if (mn .eq. 1) go to 16
      if (mn2.le.0) then
         err=2
         call error(45)
         return
      endif
      if (mn.le.0) then
         lstk(top+1)=l
         return
      endif
      if (n .ne. n2) then
         call error(11)
         return
      endif
      l3=max(l+(itr+1)*mn,l2)+(it2+1)*mn2
      err=l3+n2*(it2+1)+(n2+1)/2-lstk(bot)
      if(err.gt.0) then
         call error(17)
         return
      endif
c
      if(it.eq.1.or.it2.eq.0) goto 9
      inc=1
      if(l2.le.l+2*mn) inc=-1
      call dcopy(mn2*(it2+1),stk(l2),inc,stk(l+2*mn),inc)
      call dcopy(mn,0.0d+0,0,stk(l+mn),1)
      istk(il+3)=1
      l2=l+2*mn
      lstk(top+1)=l2
    9 continue
      if(it2.eq.1) call wlslv(stk(l2),stk(l2+mn2),m2,n2,
     $     stk(l),stk(l+mn),m,m,stk(l3),rcond,err,2)
      if(it2.eq.0) call dlslv(stk(l2),m2,n2,stk(l),m,m,stk(l3),
     $     rcond,err,2)
      if(it2.eq.0.and.it.eq.1) call dlslv(stk(l2),m2,n2,stk(l+mn),m,m,
     $     stk(l3),rcond,err,-2)
      if (rcond.eq.0.0d+0) then
         call error(19)
         return
      endif
      t = 1.0d+0 + rcond
      if (t.eq.1.0d+0 .and. fun.ne.21) then
         write(buf(1:13),'(1pd13.4)') rcond
         call msgs(5,0)
      endif
      if (t.eq.1.0d+0 .and. fun.eq.21) then
         write(buf(1:13),'(1pd13.4)') rcond
         call msgs(6,0)
      endif
c
c     check for imaginary roundoff in matrix functions
      if(it2.eq.0.and.it.eq.0) goto 99
      do 13 i=1,nn
         sr=abs(stk(l+i-1))
         si=abs(stk(l+mn+i-1))
         if(si.gt.eps*sr) goto 99
 13   continue
      istk(il+3)=0
      lstk(top+1)=l+mn
      go to 99
c
 16   sr = stk(l)
      si=0.0d+0
      if(it.eq.1) si = stk(l+1)
      n = n2
      m = n
      mn=m*n
      nn=n*n
      istk(il+1)=n
      istk(il+2)=n
      istk(il+3)=it2
      lstk(top+1)=l+nn*(it2+1)
      call dcopy(nn*(it2+1),stk(l2),1,stk(l),1)
      it2=it
      it=istk(il+3)

      if (m .ne. n) then
         err=rhs
         call error(20)
         return
      endif
      n=abs(n)
      if(mn.le.0) return
      l3 = l + nn*(it+1)
      err = l3+n*(it+1)+sadr(n) - lstk(bot)
      if (err .gt. 0) then
         call error(17)
         return
      endif
      if(it.eq.0) then
         call dlslv(stk(l),n,n,sr,0,0,stk(l3),rcond,err,3)
      else
         call wlslv(stk(l),stk(l+nn),n,n,sr,si,0,0,stk(l3),
     $     rcond,err,3)
      endif
      if (rcond .eq. 0.0d+0) then
         call error(19)
         return
      endif
      t = 1.0d+0 + rcond
      if (t .eq. 1.0d+0) then
         write(buf(1:13),'(1pd13.4)') rcond
c       matrice est quasi singuliere ou mal normalisee')
         call msgs(5,0)
      endif
      goto(33,34,35) (it+2*it2)
 33   call dscal(nn*(it+1),sr,stk(l),1)
      istk(il+3)=it
      lstk(top+1)=l+m*n*(it+1)
      goto 99
 34   call dcopy(nn,stk(l),1,stk(l+nn),1)
      call dscal(nn,sr,stk(l),1)
      call dscal(nn,si,stk(l+nn),1)
      istk(il+3)=1
      lstk(top+1)=l+2*nn
      goto 99
 35   call wscal(nn,sr,si,stk(l),stk(l+nn),1)
      go to 99
 99   continue
      return
      end