File: fscislicot.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 (1128 lines) | stat: -rw-r--r-- 35,490 bytes parent folder | download | duplicates (2)
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
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
      subroutine intmb03od(fname)
      INCLUDE '../stack.h'
      character fname*(*)
      logical createvar, getrhsvar, checklhs, checkrhs
c     
      integer A,RCOND,RANK,SVAL,JPVT,TAU,R,Q,DWORK
      integer ptrA,ptrRCOND,ptrJPVT,ptrSVAL,ptrTAU,ptrRANK
      integer ptrDWORK,ptrR,ptrQ
      double precision RCONDdef,SLVMAX
      character*(1) JOBQR
      double precision ZERO
      parameter ( ZERO = 0.0D0)

c     [Q,R,JPVT,RANK,SVAL]=rankqr(A,[RCOND,JPVT])

      minrhs=1
      maxrhs=3
      minlhs=1
      maxlhs=5
      if(.not.checklhs(fname,minlhs,maxlhs)) return
      if(.not.checkrhs(fname,minrhs,maxrhs)) return


      JOBQR='Q'
      SLVMAX=0.0d0
      RCONDdef=0.0d0

      A=1
      RCOND=2
      JPVT=3
      SVAL=4
      TAU=5
      RANK=6
      R=7
      Q=8
      DWORK=9

      if(.not.getrhsvar(A,'d',M,N,ptrA)) return

      if(rhs.eq.1) then
c                 rankqr(A)
c     create RCOND=0.0,JPVT=[0,..,0]
         if(.not.createvar(RCOND,'d',1,1,ptrRCOND)) return
         stk(ptrRCOND)=RCONDdef
         if(.not.createvar(JPVT,'i',1,N,ptrJPVT)) return
         call icopy(N,0,0,istk(ptrJPVT),1)
      elseif(rhs.eq.2) then
c                 rankqr(A,RCOND)
c     get RCOND, create JPVT=[0,..,0]
         if(.not.getrhsvar(RCOND,'d',mR,nR,ptrRCOND)) return
         if(mR*nR.ne.1) then 
            buf=fname//': 2nd parameter (RCOND) has wrong dimension'
            call error(998)
            return
         endif
         if(.not.createvar(JPVT,'i',1,N,ptrJPVT)) return
         call icopy(N,0,0,istk(ptrJPVT),1)
      elseif(rhs.eq.3) then
c                 rankqr(A,RCOND,JPVT)
c     get  RCOND, JPVT
         if(.not.getrhsvar(RCOND,'d',mR,nR,ptrRCOND)) return
         if(mR*nR.ne.1) then 
            buf=fname//': 2nd parameter (RCOND) has wrong dimension'
            call error(998)
            return
         endif
         if(.not.getrhsvar(JPVT,'i',mJ,nJ,ptrJPVT)) return
         if(mJ*nJ.ne.N) then
            buf=fname//': JPVT must have same column dim. as A'
            call error(998)
            return
         endif
      endif

c    Creating  SVAL,TAU,RANK,R,Q,DWORK
      
      if(.not.createvar(SVAL,'d',1,3,ptrSVAL)) return
      if(.not.createvar(TAU,'d',1,min(M,N),ptrTAU)) return
      if(.not.createvar(RANK,'i',1,1,ptrRANK)) return
      if(.not.createvar(R,'d',M,N,ptrR)) return
      if(.not.createvar(Q,'d',M,M,ptrQ)) return

      LDWORKMIN=max(1,3*N)
      LDWORK=maxvol(DWORK,'d')
      if(LDWORK.le.LDWORKMIN) then
         buf=fname//': not enough memory (use stacksize)'
         call error(998)
         return
      endif
      if(.not.createvar(DWORK,'d',1,LDWORK,ptrDWORK)) return

      LDA=max(1,M)
      call MB03OD(JOBQR, M, N, stk(ptrA), LDA, istk(ptrJPVT),
     &  stk(ptrRCOND), SLVMAX, stk(ptrTAU), istk(ptrRANK),
     &  stk(ptrSVAL), stk(ptrDWORK), INFO)

      if(INFO.ne.0) then
         call errorinfo(fname,INFO)
         return
      endif

c     Save R (=current A)
      call dcopy(M*N,stk(ptrA),1,stk(ptrR),1)

c     Set to zero lower trapezoidal part of R:
      IRANK=istk(ptrRANK)
      IR=IRANK-M
      do 10 K=1,N
         II=II+1
         NB=M-IRANK
         IR=IR+M
         NB1=NB
         IR1=IR
         if(K.lt.IRANK) then
           IR1=IR-(IRANK-K)
           NB1=NB+(IRANK-K)
         endif
         call dcopy(NB1,ZERO,0,stk(ptrR+IR1),1)
 10   continue

c     Make Q
      if(M.le.N) then
c     A is fat
      CALL DORGQR( M, M, M, stk(ptrA), LDA, stk(ptrTAU), 
     &   stk(ptrDWORK), LDWORK, INFO )
      call dcopy(M*M,stk(ptrA),1,stk(ptrQ),1)
      else
c     A is tall => Q=[A,0]
      call dcopy(M*N,stk(ptrA),1,stk(ptrQ),1)
      call dcopy(M*(M-N),0.d0,0,stk(ptrQ+M*N),1)
      CALL DORGQR( M, M, min(M,N), stk(ptrQ), LDA, stk(ptrTAU), 
     &   stk(ptrDWORK), LDWORK, INFO )
      endif

      if(INFO.ne.0) then
         call errorinfo(fname,INFO)
         return
      endif

c     [Q,R,JPVT,RANK,SVAL]=rankqr(A,[RCOND,JPVT])

      lhsvar(1)=Q
      lhsvar(2)=R
      lhsvar(3)=JPVT
      lhsvar(4)=RANK
      lhsvar(5)=SVAL

      end

      subroutine intzb03od(fname)
      INCLUDE '../stack.h'
      character fname*(*)
      logical createvar, getrhsvar, checklhs, checkrhs
c     
      integer A,RCOND,RANK,SVAL,JPVT,TAU,R,Q,RWORK,DWORK
      integer ptrA,ptrRCOND,ptrJPVT,ptrSVAL,ptrTAU,ptrRANK
      integer ptrDWORK,ptrR,ptrQ,ptrRWORK
      double precision RCONDdef,SLVMAX
      character*(1) JOBQR
      complex*16 ZERO
      parameter( ZERO=(0.0D0,0.0D0) )

c     [Q,R,JPVT,RANK,SVAL]=rankqr(A,[RCOND,JPVT])

      minrhs=1
      maxrhs=3
      minlhs=1
      maxlhs=5
      if(.not.checklhs(fname,minlhs,maxlhs)) return
      if(.not.checkrhs(fname,minrhs,maxrhs)) return

      JOBQR='Q'
      RCONDdef=0.0d0
      SLVMAX=0.0d0

      A=1
      RCOND=2
      JPVT=3
      SVAL=4
      TAU=5
      RANK=6
      R=7
      Q=8
      RWORK=9
      DWORK=10
 
      if(.not.getrhsvar(A,'z',M,N,ptrA)) return

      if(rhs.eq.1) then
c                 rankqr(A)
c     create RCOND=0.0,JPVT=[0,..,0]
         if(.not.createvar(RCOND,'d',1,1,ptrRCOND)) return
         stk(ptrRCOND)=RCONDdef
         if(.not.createvar(JPVT,'i',1,N,ptrJPVT)) return
         call icopy(N,0,0,istk(ptrJPVT),1)
      elseif(rhs.eq.2) then
c                 rankqr(A,RCOND)
c     get RCOND, create JPVT=[0,..,0]
         if(.not.getrhsvar(RCOND,'d',mR,nR,ptrRCOND)) return
         if(mR*nR.ne.1) then 
            buf=fname//': 2nd parameter (RCOND) has wrong dimension'
            call error(998)
            return
         endif
         if(.not.createvar(JPVT,'i',1,N,ptrJPVT)) return 
         call icopy(N,0,0,istk(ptrJPVT),1)
      elseif(rhs.eq.3) then
c                 rankqr(A,RCOND,JPVT)
c     get  RCOND, JPVT
         if(.not.getrhsvar(RCOND,'d',mR,nR,ptrRCOND)) return
         if(mR*nR.ne.1) then 
            buf=fname//': 2nd parameter (RCOND) has wrong dimension'
            call error(998)
            return
         endif
         if(.not.getrhsvar(JPVT,'i',mJ,nJ,ptrJPVT)) return
         if(mJ*nJ.ne.N) then
            buf=fname//': JPVT must have same column dim. as A'
            call error(998)
            return
         endif
      endif



c    Creating  SVAL,RANK,R,Q,RWORK,DWORK
      
      if(.not.createvar(SVAL,'d',1,3,ptrSVAL)) return
      if(.not.createvar(TAU,'z',1,min(M,N),ptrTAU)) return
      if(.not.createvar(RANK,'i',1,1,ptrRANK)) return
      if(.not.createvar(R,'z',M,N,ptrR)) return
      if(.not.createvar(Q,'z',M,M,ptrQ)) return
      if(.not.createvar(RWORK,'d',1,2*N,ptrRWORK)) return

      LDWORKMIN=max(2*min(M,N),N+1)
      LDWORK=maxvol(DWORK,'z')
      if(LDWORK.le.LDWORKMIN) then
         buf=fname//': not enough memory (use stacksize)'
         call error(998)
         return
      endif
      if(.not.createvar(DWORK,'z',1,LDWORK,ptrDWORK)) return

      LDA=max(1,M)
      call ZB03OD(JOBQR, M, N, zstk(ptrA), LDA, istk(ptrJPVT),
     &  stk(ptrRCOND), SLVMAX, zstk(ptrTAU), istk(ptrRANK),
     &  stk(ptrSVAL), zstk(ptrDWORK), LDWORK, stk(ptrRWORK), INFO)
      if(INFO.ne.0) then
         call errorinfo(fname,INFO)
         return
      endif

c     Save R (=current A)
      call zcopy(M*N,zstk(ptrA),1,zstk(ptrR),1)
c     Set to zero lower trapezoidal part of R:
      IRANK=istk(ptrRANK)
      IR=IRANK-M
      do 10 K=1,N
         II=II+1
         NB=M-IRANK
         IR=IR+M
         NB1=NB
         IR1=IR
         if(K.lt.IRANK) then
           IR1=IR-(IRANK-K)
           NB1=NB+(IRANK-K)
         endif
         call zcopy(NB1,ZERO,0,zstk(ptrR+IR1),1)
 10   continue

c     Make Q
      if(M.le.N) then
c     A is fat
      CALL ZUNGQR( M, M, M, zstk(ptrA), LDA, zstk(ptrTAU), 
     &   zstk(ptrDWORK), LDWORK, INFO )
      call zcopy(M*M,zstk(ptrA),1,zstk(ptrQ),1)
      else
c     A is tall => Q=[A,0]
      call zcopy(M*N,zstk(ptrA),1,zstk(ptrQ),1)
      call zcopy(M*(M-N),ZERO,0,zstk(ptrQ+M*N),1)
      CALL ZUNGQR( M, M, min(M,N), zstk(ptrQ), LDA, zstk(ptrTAU), 
     &   zstk(ptrDWORK), LDWORK, INFO )
      endif

      if(INFO.ne.0) then
         call errorinfo(fname,INFO)
         return
      endif

c     [Q,R,JPVT,RANK,SVAL]=rankqr(A,[RCOND,JPVT])

      lhsvar(1)=Q
      lhsvar(2)=R
      lhsvar(3)=JPVT
      lhsvar(4)=RANK
      lhsvar(5)=SVAL

      end


      subroutine intmucomp(fname)

c     [bound,D,G] = mucomp(Z,K,T)
c     [bound,D] = mucomp(Z,K,T)
c     bound = mucomp(Z,K,T)

      include '../stack.h'
      logical getrhsvar,createvar
      logical checklhs,checkrhs
      character fname*(*)

       minrhs=3
       maxrhs=3
       minlhs=1
       maxlhs=3
c
       if(.not.checkrhs(fname,minrhs,maxrhs)) return
       if(.not.checklhs(fname,minlhs,maxlhs)) return 

       if(.not.getrhsvar(1,'z', M, N, lZ)) return
       if(M.ne.N) then
         buf='mucomp'//': the matrix must be square'
         call error(998)
         return
       endif
       if(N.eq.0) then
         if(lhs.eq.1) then
           if(.not.createvar(2,'d', N, 1, lBOUND)) return
           lhsvar(1) = 2
           return
         else if(lhs.eq.2) then
           if(.not.createvar(2,'d', N, 1, lBOUND)) return
           if(.not.createvar(3,'d', N, 1, lD)) return
           lhsvar(1)=2
           lhsvar(2)=3
           return
         else if(lhs.eq.3) then
           if(.not.createvar(2,'d', N, 1, lBOUND)) return
           if(.not.createvar(3,'d', N, 1, lD)) return
           if(.not.createvar(4,'d', N, 1, lG)) return 
           lhsvar(1)=2
           lhsvar(2)=3
           lhsvar(3)=4
           return
         endif
       endif
       if(.not.getrhsvar(2,'i', M1, N1, lK)) return
       if(.not.getrhsvar(3,'i', M2, N2, lT)) return
       if(M1*N1.ne.M2*N2) then
         buf='mucomp'//': K and T must have equal lengths'
         call error(998)
         return
       endif
       M = M1*N1
       if(.not.createvar(4,'d', 1, 1, lBOUND)) return
       if(.not.createvar(5,'d', N, 1, lD)) return
       if(.not.createvar(6,'d', N, 1, lG)) return 
       if(.not.createvar(7,'d', 2*N-1, 1, lX)) return
       if(.not.createvar(8,'i', 4*N-2, 1, lIWORK)) return 
       LRWRK = 2*N*N*N + 9*N*N +  44*N - 11
       if(.not.createvar(9,'d', LRWRK, 1, lRWORK)) return
       LZWRKMIN  = 6*N*N*N + 12*N*N + 12*N - 3
       LZWRK=maxvol(10,'z')
       if(LZWRK.le.LZWRKMIN) then
         buf='mucomp'//': not enough memory (use stacksize)'
         call error(998)
         return
       endif
       if(.not.createvar(10,'z',1,LZWRK,lZWORK)) return 
    
       call AB13MD( 'N', N, zstk(lZ), N, M, istk(lK), istk(lT),
     $    stk(lX), stk(lBOUND), stk(lD), stk(lG), istk(lIWORK),
     $    stk(lRWORK), LRWRK, zstk(lZWORK), LZWRK, INFO )
c       SUBROUTINE AB13MD( FACT, N, Z, N, M, NBLOCK, ITYPE, X,
c     $    BOUND, D, G, IWORK, DWORK, LDWORK, ZWORK, LZWORK,
c     $    INFO )
      if(info.ne.0) then
        call errorinfo("mucomp",info)
        return
      endif
    
      if(lhs.eq.1) then
        lhsvar(1) = 4
      else if(lhs.eq.2) then
        lhsvar(1)=4
        lhsvar(2)=5
      else if(lhs.eq.3) then
        lhsvar(1)=4
        lhsvar(2)=5
        lhsvar(3)=6
      endif
c
       end



      SUBROUTINE ZB03OD( JOBQR, M, N, A, LDA, JPVT, RCOND, SVLMAX, TAU,
     $                   RANK, SVAL, WORK, LWORK, RWORK, INFO )
*
*     .. Scalar Arguments ..
      CHARACTER*1        JOBQR
      INTEGER            INFO, LDA, LWORK, M, N,  RANK
      DOUBLE PRECISION   RCOND, SVLMAX
*     ..
*     .. Array Arguments ..
      INTEGER            JPVT( * )
      DOUBLE PRECISION   SVAL(3), RWORK( * )
      COMPLEX*16         A( LDA, * ), TAU( * ), WORK( * )
*     ..
*
*  Purpose
*  =======
*
C
C     RELEASE 4.0, WGS COPYRIGHT 2001.
C
C     PURPOSE
C
C     To compute (optionally) a rank-revealing QR factorization of a 
C     real general M-by-N matrix  A,  which may be rank-deficient,
C     and estimate its effective rank using incremental condition 
C     estimation.
C
C     The routine uses a QR factorization with column pivoting:
C        A * P = Q * R,  where  R = [ R11 R12 ],
C                                   [  0  R22 ]
C     with R11 defined as the largest leading submatrix whose estimated
C     condition number is less than 1/RCOND.  The order of R11, RANK,
C     is the effective rank of A.
C
C     ZB03OD  does not perform any scaling of the matrix A.
*
*  Arguments
*  =========
*
C    Mode Parameters
C
C    JOBQR   CHARACTER*1
C            = 'Q': Perform a QR factorization with column pivoting;
C            = 'N': Do not perform the QR factorization (but ssumes
C                   that it has been done outside).
*
*  M       (input) INTEGER
*          The number of rows of the matrix A.  M >= 0.
*
*  N       (input) INTEGER
*          The number of columns of the matrix A.  N >= 0.
*
*  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
*          On entry, the M-by-N matrix A.
*          On exit, A has been overwritten by details of its
*          complete orthogonal factorization.
*
*  LDA     (input) INTEGER
*          The leading dimension of the array A.  LDA >= max(1,M).
*
*  LDB     (input) INTEGER
*          The leading dimension of the array B. LDB >= max(1,M,N).
*
*  JPVT    (input/output) INTEGER array, dimension (N)
*          On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted
*          to the front of AP, otherwise column i is a free column.
*          On exit, if JPVT(i) = k, then the i-th column of A*P
*          was the k-th column of A.
*
*  RCOND   (input) DOUBLE PRECISION
*          RCOND is used to determine the effective rank of A, which
*          is defined as the order of the largest leading triangular
*          submatrix R11 in the QR factorization with pivoting of A,
*          whose estimated condition number < 1/RCOND.
*
C            
C     TAU     (output) COMPLEX*16 array, dimension ( MIN( M, N ) )
C             On exit with JOBQR = 'Q', the leading min(M,N) elements of
C             TAU contain the scalar factors of the elementary 
C             reflectors.
C             Array TAU is not referenced when JOBQR = 'N'.
C            
*  RANK    (output) INTEGER
*          The effective rank of A, i.e., the order of the submatrix
*          R11.  This is the same as the order of the submatrix T11
*          in the complete orthogonal factorization of A.
*
C     SVAL    (output) DOUBLE PRECISION array, dimension ( 3 )
C             The estimates of some of the singular values of the 
C             triangular factor R:
C             SVAL(1): largest singular value of R(1:RANK,1:RANK);
C             SVAL(2): smallest singular value of R(1:RANK,1:RANK);
C             SVAL(3): smallest singular value of R(1:RANK+1,1:RANK+1),
C                      if RANK < MIN( M, N ), or of R(1:RANK,1:RANK),
C                      otherwise.
C             If the triangular factorization is a rank-revealing one
C             (which will be the case if the leading columns were well-
C             conditioned), then SVAL(1) will also be an estimate for
C             the largest singular value of A, and SVAL(2) and SVAL(3)
C             will be estimates for the RANK-th and (RANK+1)-st singular
C             values of A, respectively.
C             By examining these values, one can confirm that the rank
C             is well defined with respect to the chosen value of RCOND.
C             The ratio SVAL(1)/SVAL(2) is an estimate of the condition
C             number of R(1:RANK,1:RANK).
C
*  WORK    (workspace/output) COMPLEX*16 array, dimension (LWORK)
*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
*
*  LWORK   (input) INTEGER
*          The dimension of the array WORK.
*
*          If JOBQR = 'Q':
*             The unblocked strategy requires that:
*               LWORK >= MAX( 2*MN, N+1 )
*             where MN = min(M,N).
*             The block algorithm requires that:
*               LWORK >= MAX( 2*MN, NB*(N+1) )
*             where NB is an upper bound on the blocksize returned
*             by ILAENV for the routines ZGEQP3 and ZUNMQR.
*
*          LDWORK = max( 1, 2*min( M, N ) ), if JOBQR = 'N'.        
*
*          If LWORK = -1, then a workspace query is assumed; the routine
*          only calculates the optimal size of the WORK array, returns
*          this value as the first entry of the WORK array, and no error
*          message related to LWORK is issued by XERBLA.
*
*  RWORK   (workspace) DOUBLE PRECISION array, dimension (2*N)
*
*  INFO    (output) INTEGER
*          = 0: successful exit
*          < 0: if INFO = -i, the i-th argument had an illegal value
*
C     METHOD
C
C     The routine computes or uses a QR factorization with column 
C     pivoting of A,  A * P = Q * R,  with  R  defined above, and then
C     finds the largest leading submatrix whose estimated condition
C     number is less than 1/RCOND, taking the possible positive value of
C     SVLMAX into account.  This is performed using the LAPACK
C     incremental condition estimation scheme and a slightly modified
C     rank decision test.
C
C     CONTRIBUTOR
C
C     Complex version of MB03OD
C
*
*  =====================================================================
*
*     .. Parameters ..
      INTEGER            IMAX, IMIN
      PARAMETER          ( IMAX = 1, IMIN = 2 )
      DOUBLE PRECISION   ZERO, ONE
      PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
      COMPLEX*16         CZERO, CONE
      PARAMETER          ( CZERO = ( 0.0D+0, 0.0D+0 ),
     $                   CONE = ( 1.0D+0, 0.0D+0 ) )
*     ..
*     .. Local Scalars ..
      LOGICAL            LJOBQR,  LQUERY
      INTEGER            I, ISMAX, ISMIN, J, LWKOPT, MN,
     $                   NB, NB1, NB2
      DOUBLE PRECISION   SMAX, SMAXPR, SMIN, SMINPR
      COMPLEX*16         C1, C2, S1, S2
*     ..
*     .. External Subroutines ..
      EXTERNAL           XERBLA, ZGEQP3, ZLAIC1
*     ..
*     .. External Functions ..
      LOGICAL            LSAME
      INTEGER            ILAENV
      EXTERNAL           ILAENV, LSAME
*     ..
*     .. Intrinsic Functions ..
      INTRINSIC          ABS, DBLE, DCMPLX, MAX, MIN
*     ..
*     .. Executable Statements ..
*
      LJOBQR = LSAME( JOBQR, 'Q' )
      MN = MIN( M, N )
      ISMIN = 1
      ISMAX = MN + 1
*
*     Test the input arguments.
*
      INFO = 0
      NB1 = ILAENV( 1, 'ZGEQRF', ' ', M, N, -1, -1 )
      NB2 = ILAENV( 1, 'ZUNMQR', ' ', M, N, NRHS, -1 )
      NB = MAX( NB1, NB2 )
      LWKOPT = MAX( 1, 2*N+NB*( N+1 ) )
      WORK( 1 ) = DCMPLX( LWKOPT )
      LQUERY = ( LWORK.EQ.-1 )
C
      IF( .NOT.LJOBQR .AND. .NOT.LSAME( JOBQR, 'N' ) ) THEN
         INFO = -1
      ELSE IF( M.LT.0 ) THEN
         INFO = -2
      ELSE IF( N.LT.0 ) THEN
         INFO = -3
      ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
         INFO = -5
      ELSE IF( RCOND.LT.ZERO ) THEN
         INFO = -7
      ELSE IF( SVLMAX.LT.ZERO ) THEN
         INFO = -8
      ELSE IF( LWORK.LT.( MAX( 2*MN, N+1 ) ) .AND. .NOT.
     $         LQUERY ) THEN
         INFO = -13
      END IF
*
      IF( INFO.NE.0 ) THEN
         CALL XERBLA( 'ZB03OD', -INFO )
         RETURN
      END IF
*
*     Quick return if possible
*
      IF( MN.EQ.0 ) THEN
         SVAL( 1 ) = ZERO
         SVAL( 2 ) = ZERO
         SVAL( 3 ) = ZERO
         RANK = 0
         RETURN
      END IF
C
      IF( LJOBQR ) THEN
*
*        Compute QR factorization with column pivoting of A:
*           A * P = Q * R
*
         CALL ZGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK,
     $                RWORK, INFO )    
*
*        complex workspace: MN+NB*(N+1). real workspace 2*N.
*        Details of Householder rotations stored in WORK(1:MN).
      END IF
*
*     Determine RANK using incremental condition estimation
*
      WORK( ISMIN ) = CONE
      WORK( ISMAX ) = CONE
      SMAX = ABS( A( 1, 1 ) )
      SMIN = SMAX
      IF( SMAX.EQ.ZERO .OR. SVLMAX*RCOND.GT.SMAX) THEN
         RANK = 0
         SVAL( 1 ) = SMAX
         SVAL( 2 ) = ZERO
         SVAL( 3 ) = ZERO
      ELSE
         RANK = 1
         SMINPR = SMIN
*
   10    CONTINUE
         IF( RANK.LT.MN ) THEN
            I = RANK + 1
            CALL ZLAIC1( IMIN, RANK, WORK( ISMIN ), SMIN, A( 1, I ),
     $                   A( I, I ), SMINPR, S1, C1 )
            CALL ZLAIC1( IMAX, RANK, WORK( ISMAX ), SMAX, A( 1, I ),
     $                   A( I, I ), SMAXPR, S2, C2 )
*
            IF( SVLMAX*RCOND.LE.SMAXPR ) THEN
               IF( SVLMAX*RCOND.LE.SMINPR ) THEN
                  IF( SMAXPR*RCOND.LE.SMINPR ) THEN
                     DO 20 I = 1, RANK
                        WORK( ISMIN+I-1 ) = S1*WORK( ISMIN+I-1 )
                        WORK( ISMAX+I-1 ) = S2*WORK( ISMAX+I-1 )
   20                CONTINUE
                     WORK( ISMIN+RANK ) = C1
                     WORK( ISMAX+RANK ) = C2
                     SMIN = SMINPR
                     SMAX = SMAXPR
                     RANK = RANK + 1
                     GO TO 10
                  END IF
               END IF
            END IF
         END IF
         SVAL( 1 ) = SMAX
         SVAL( 2 ) = SMIN
         SVAL( 3 ) = SMINPR
      END IF
      WORK( 1 ) = DCMPLX( LWKOPT )
C
      RETURN
C *** Last line of ZB03OD ***
      END


      subroutine intricc2(fname)

c     [X,RCOND,FERR]=ricc(A,C,D,'type','method')
c     [X,RCOND]=ricc(A,C,D,'type','method')
c     X = riccsl(A,C,D,'type','method')
c     'type' is 'continuous' or 'discrete'
c     'method' is 'schr' or 'sign' for continuous-time systems
c             and 'schr' or 'invf' for discrete-tyme systems 

      include '../stack.h'
      logical getrhsvar,createvar
      logical checklhs,checkrhs

      character fname*(*)
      character*4 TYPE, METHOD 
      logical WANTC, WANTD, WSCHUR, WSIGN, WINVF
 
      minrhs=4
      maxrhs=5
      minlhs=1
      maxlhs=3
c
       if(.not.checkrhs(fname,minrhs,maxrhs)) return
       if(.not.checklhs(fname,minlhs,maxlhs)) return 

       if(.not.getrhsvar(1,'d', MA, NA, lA)) return
       if(MA.ne.NA) then
         buf='ricc'//': the matrix A must be square'
         call error(998)
         return
       endif       
       if(.not.getrhsvar(2,'d', MD, ND, lD)) return
       if(MD.ne.ND) then
         buf='ricc'//': the matrix D must be square'
         call error(998)
         return
       endif
       if(.not.getrhsvar(3,'d', MC, NC, lC)) return
       if(MC.ne.NC) then
         buf='ricc'//': the matrix C must be square'
         call error(998)
         return
       endif
       if(MA.ne.MC .or. MC.ne.MD .or. MA.ne.MD) then
         buf='ricc'//
     $     ': the matrices A, C and D must have the same order'
         call error(998)
         return

       endif
       N = MA

       if(.not.getrhsvar(4,'c', M1, N1, lTYPE)) return
       TYPE(1:4) = cstk(lTYPE:lTYPE+4)
       WANTC = (TYPE(1:4).eq.'cont' .or. TYPE(1:4).eq.'CONT')
       WANTD = (TYPE(1:4).eq.'disc' .or. TYPE(1:4).eq.'DISC')
       if(.not.WANTC .and. .not.WANTD) then
         buf='ricc'//': type must be continuous or discrete'
         call error(998)
         return
       endif
       
       k = 5
       WSCHUR = .TRUE.
       if(rhs.eq.5) then
         if(.not.getrhsvar(5,'c', M1, N1, lMETHOD)) return
         METHOD(1:4) = cstk(lMETHOD:lMETHOD+4)
         if(WANTC) then
           WSCHUR = (METHOD(1:4).eq.'schr' .or. METHOD(1:4).eq.'SCHR')
           WSIGN = (METHOD(1:4).eq.'sign' .or. METHOD(1:4).eq.'SIGN')
           if(.not.WSCHUR .and. .not.WSIGN) then
             buf='ricc'//': method must be schur or sign'
             call error(998)
             return
           endif
         else
           WSCHUR = (METHOD(1:4).eq.'schr' .or. METHOD(1:4).eq.'SCHR')
           WINVF = (METHOD(1:4).eq.'invf' .or. METHOD(1:4).eq.'INVF')
           if(.not.WSCHUR .and. .not.WINVF) then
             buf='ricc'//': method must be schur or invf'
             call error(998)
             return
           endif
         endif
         k = 6
       endif
       if(.not.createvar(k,'d', N, N, lX)) return      
       if(.not.createvar(k+1,'d', N, 1, lWR)) return
       if(.not.createvar(k+2,'d', N, 1, lWI)) return
       if(.not.createvar(k+3,'d', 1, 1, lRCOND)) return
       if(.not.createvar(k+4,'d', 1, 1, lFERR)) return 
       if(.not.createvar(k+5,'i', 1, max(2*N,N*N), lIWORK)) return       
       if(.not.createvar(k+6,'i', 1, 2*N, lBWORK)) return
       if(WANTC) then
         if(WSCHUR) then
           LWORKMIN = 9*N*N + 4*N + max(1,6*N)
         else if(WSIGN) then
           LWORKMIN = 9*N*N + 7*N + 1
         endif
       else
         if(WSCHUR) then
           LWORKMIN = 12*N*N + 22*N + max(16,4*N)
         else if(WINVF) then
           LWORKMIN = 28*N*N + 2*N + max(1,2*N) 
         endif
       endif
       LWORK=maxvol(k+7,'d')
       if(LWORK.le.LWORKMIN) then
         buf='ricc'//': not enough memory (use stacksize)'
         call error(998)
         return
       endif
       if(.not.createvar(k+7,'d',1,LWORK,lDWORK)) return

       if(WANTC) then
         if(WSCHUR) then 
            call RICCSL( 'N', N, stk(lA), N, 'U', stk(lC), N, stk(lD), 
     $        N, stk(lX), N, stk(lWR), stk(lWI), stk(lRCOND), 
     $        stk(lFERR), stk(lDWORK), LWORK, istk(lIWORK),
     $        istk(lBWORK), INFO )
c            SUBROUTINE RICCSL( TRANS, N, A, LDA, C, LDC, D, LDD, X, LDX,
c     $        WR, WI, RCOND, FERR, WORK, LWORK, IWORK, BWORK, INFO )
         else if(WSIGN) then
            call RICCMS( 'N', N, stk(lA), N, 'U', stk(lC), N, stk(lD),
     $        N, stk(lX), N, stk(lWR), stk(lWI), stk(lRCOND),
     $        stk(lFERR), stk(lDWORK), LWORK, istk(lIWORK), INFO )
c            SUBROUTINE RICCMS( TRANS, N, A, LDA, C, LDC, D, LDD, X, LDX,
c     $        WR, WI, RCOND, FERR, WORK, LWORK, IWORK, INFO )
         endif
       else
         if(WSCHUR) then
            call RICDSL( 'N', N, stk(lA), N, 'U', stk(lC), N, stk(lD),
     $        N, stk(lX), N, stk(lWR), stk(lWI), stk(lRCOND),
     $        stk(lFERR), stk(lDWORK), LWORK, istk(lIWORK),
     $        istk(lBWORK), INFO )
c            SUBROUTINE RICDSL( TRANS, N, A, LDA, C, LDC, D, LDD, X, LDX,
C     $        WR, WI, RCOND, FERR, WORK, LWORK, IWORK, BWORK, INFO )
         else if (WINVF) then
            call RICDMF( 'N', N, stk(lA), N, 'U', stk(lC), N, stk(lD),
     $        N, stk(lX), N, stk(lWR), stk(lWI), stk(lRCOND),
     $        stk(lFERR), stk(lDWORK), LWORK, istk(lIWORK), INFO )
c            SUBROUTINE RICDMF( TRANS, N, A, LDA, C, LDC, D, LDD, X, LDX,
C     $        WR, WI, RCOND, FERR, WORK, LWORK, IWORK, INFO )
         endif
      endif
      if(info.ne.0) then
        call errorinfo("ricc",info)
        return
      endif
   
    
      if(lhs.eq.1) then
        lhsvar(1)=k
      else if(lhs.eq.2) then
        lhsvar(1)=k
        lhsvar(2)=k+3
      else if(lhs.eq.3) then 
          lhsvar(1)=k
          lhsvar(2)=k+3
          lhsvar(3)=k+4
      endif
c
       end

      subroutine inthinf(fname)

c     [Ak,Bk,Ck,Dk,RCOND]=hinf(A,B,C,D,ncon,nmeas,gamma)

      include '../stack.h'
      logical getrhsvar,createvar
      logical checklhs,checkrhs
      character fname*(*)
      double precision GAMMA, TOL, EPS
      integer N, M, R, Q
      double precision dlamch
      external dlamch
c
       minrhs=7
       maxrhs=7
       minlhs=4
       maxlhs=5
c
       if(.not.checkrhs(fname,minrhs,maxrhs)) return
       if(.not.checklhs(fname,minlhs,maxlhs)) return
        
       if(.not.getrhsvar(1,'d', MA, NA, lA)) return
       if(MA .ne. NA) then
         buf='hinf'//': A must be a square matrix'
         call error(998)
         return
       endif
       if(.not.getrhsvar(2,'d', MB, NB, lB)) return
       if(MA .ne. MB) then
         buf='hinf'//': A and B must have equal number of rows'
         call error(998)
         return
       endif
       if(.not.getrhsvar(3,'d', MC, NC, lC)) return
       if(NA .ne. NC) then
         buf='hinf'//': A and C must have equal number of columns'
         call error(998)
         return
       endif
       if(.not.getrhsvar(4,'d', MD, ND, lD)) return
       if(NB .ne. ND) then
         buf='hinf'//': B and D must have equal number of columns'
         call error(998)
         return
       endif
       if(MC .ne. MD) then
         buf='hinf'//': C and D must have equal number of rows'
         call error(998)
         return
       endif
       N = MA
       M = NB
       R = MC
       if(N.eq.0 .or. M.eq.0 .or. R.eq.0) then
         if(.not.createvar(5,'d', 0, 0, lAK)) return
         if(.not.createvar(6,'d', 0, 0, lBK)) return
         if(.not.createvar(7,'d', 0, 0, lCK)) return
         if(.not.createvar(8,'d', 0, 0, lDK)) return
         if(.not.createvar(9,'d', 0, 0, lRCOND)) return
         lhsvar(1) = 5
         lhsvar(2) = 6
         lhsvar(3) = 7
         lhsvar(4) = 8
         lhsvar(5) = 9
         return
       endif
       if(.not.getrhsvar(5,'i', M1, N1, lNCON)) return
       if(M1.ne.1 .or. N1.ne.1 ) then
         buf='hinf'//': NCON must be a scalar'
         call error(998)
         return
       endif
       NCON = istk(lNCON)

       if(.not.getrhsvar(6,'i', M2, N2, lNMEAS)) return
       if(M2.ne.1 .or. N2.ne.1 ) then
         buf='hinf'//': NMEAS must be a scalar'
         call error(998)
         return
       endif
       NMEAS = istk(lNMEAS)

       if(.not.getrhsvar(7,'d', M3, N3, lGAMMA)) return
       if(M3.ne.1 .or. N3.ne.1 ) then
         buf='hinf'//': GAMMA must be a scalar'
         call error(998)
         return
       endif
       GAMMA = stk(lGAMMA)
       EPS = dlamch('eps')
       TOL = sqrt(EPS)
       
       if(.not.createvar(8,'d', N, N, lAK)) return
       if(.not.createvar(9,'d', N, NMEAS, lBK)) return
       if(.not.createvar(10,'d', NCON, N, lCK)) return
       if(.not.createvar(11,'d', NCON, NMEAS, lDK)) return
       if(.not.createvar(12,'d', 4, 1, lRCOND)) return
       LINTWORK = max(2*max(N,M-NCON,R-NMEAS,NCON),N*N)

       if(.not.createvar(13,'i', LINTWORK, 1, lIWORK)) return
       if(.not.createvar(14,'i', 2*N, 1, lBWORK)) return

       Q = MAX( M - NCON, NCON, R - NMEAS, NMEAS )
       LWORKMIN = 2*Q*( 3*Q + 2*N ) + 
     $          MAX( 1, ( N + Q )*( N + Q + 6 ), 
     $               Q*( Q + MAX( N, Q, 5 ) + 1 ), 2*N*( N + 2*Q ) +
     $               MAX( 1, 4*Q*Q +
     $                    MAX( 2*Q, 3*N*N + 
     $                         MAX( 2*N*Q, 10*N*N + 12*N + 5 ) ),
     $                         Q*( 3*N + 3*Q + 
     $                             MAX( 2*N, 4*Q + max( N, Q ) ) ) ) )
       LWORK=maxvol(15,'d')
       if(LWORK.le.LWORKMIN) then
         buf='hinf'//': not enough memory (use stacksize)'
         call error(998)
         return
      endif
      if(.not.createvar(15,'d',1,LWORK,lDWORK)) return
      
      CALL SB10FD( N, M, R, NCON, NMEAS, GAMMA, stk(lA), N,
     $             stk(lB), N, stk(lC), R, stk(lD), R, stk(lAK),
     $             N, stk(lBK), N, stk(lCK), NCON, stk(lDK),
     $             NCON, stk(lRCOND), TOL, istk(lIWORK),
     $             stk(lDWORK), LDWORK, istk(lBWORK), INFO )
      if(info.ne.0) then
        call errorinfo("hinf",info)
        return
      endif      

      lhsvar(1) = 8
      lhsvar(2) = 9
      lhsvar(3) = 10
      lhsvar(4) = 11
      if(lhs.eq.5) lhsvar(5) = 12

c
       end


      subroutine intdhinf(fname)

c     [Ak,Bk,Ck,Dk,RCOND]=dhinf(A,B,C,D,ncon,nmeas,gamma)

      include '../stack.h'
      logical getrhsvar,createvar
      logical checklhs,checkrhs
      character fname*(*)
      double precision GAMMA, TOL, EPS
      integer N, M, R, Q
      double precision dlamch
      external dlamch
c
       minrhs=7
       maxrhs=7
       minlhs=4
       maxlhs=5
c
       if(.not.checkrhs(fname,minrhs,maxrhs)) return
       if(.not.checklhs(fname,minlhs,maxlhs)) return
        
       if(.not.getrhsvar(1,'d', MA, NA, lA)) return
       if(MA .ne. NA) then
         buf='dhinf'//': A must be a square matrix'
         call error(998)
         return
       endif
       if(.not.getrhsvar(2,'d', MB, NB, lB)) return
       if(MA .ne. MB) then
         buf='dhinf'//': A and B must have equal number of rows'
         call error(998)
         return
       endif
       if(.not.getrhsvar(3,'d', MC, NC, lC)) return
       if(NA .ne. NC) then
         buf='dhinf'//': A and C must have equal number of columns'
         call error(998)
         return
       endif
       if(.not.getrhsvar(4,'d', MD, ND, lD)) return
       if(NB .ne. ND) then
         buf='dhinf'//': B and D must have equal number of columns'
         call error(998)
         return
       endif
       if(MC .ne. MD) then
         buf='dhinf'//': C and D must have equal number of rows'
         call error(998)
         return
       endif
       N = MA
       M = NB
       R = MC
       if(N.eq.0 .or. M.eq.0 .or. R.eq.0) then
         if(.not.createvar(5,'d', 0, 0, lAK)) return
         if(.not.createvar(6,'d', 0, 0, lBK)) return
         if(.not.createvar(7,'d', 0, 0, lCK)) return
         if(.not.createvar(8,'d', 0, 0, lDK)) return
         if(.not.createvar(9,'d', 0, 0, lRCOND)) return
         lhsvar(1) = 5
         lhsvar(2) = 6
         lhsvar(3) = 7
         lhsvar(4) = 8
         lhsvar(5) = 9
         return
       endif
       if(.not.getrhsvar(5,'i', M1, N1, lNCON)) return
       if(M1.ne.1 .or. N1.ne.1 ) then
         buf='dhinf'//': NCON must be a scalar'
         call error(998)
         return
       endif
       NCON = istk(lNCON)

       if(.not.getrhsvar(6,'i', M2, N2, lNMEAS)) return
       if(M2.ne.1 .or. N2.ne.1 ) then
         buf='dhinf'//': NMEAS must be a scalar'
         call error(998)
         return
       endif
       NMEAS = istk(lNMEAS)

       if(.not.getrhsvar(7,'d', M3, N3, lGAMMA)) return
       if(M3.ne.1 .or. N3.ne.1 ) then
         buf='dhinf'//': GAMMA must be a scalar'
         call error(998)
         return
       endif
       GAMMA = stk(lGAMMA)
       EPS = dlamch('eps')
       TOL = sqrt(EPS)
       
       if(.not.createvar(8,'d', N, N, lAK)) return
       if(.not.createvar(9,'d', N, NMEAS, lBK)) return
       if(.not.createvar(10,'d', NCON, N, lCK)) return
       if(.not.createvar(11,'d', NCON, NMEAS, lDK)) return
       if(.not.createvar(12,'d', N, N, lX)) return
       if(.not.createvar(13,'d', N, N, lZ)) return
       if(.not.createvar(14,'d', 8, 1, lRCOND)) return
       LINTWORK = max(2*max(NCON,N),M,NCON+NMEAS,N*N)
       if(.not.createvar(15,'i', LINTWORK, 1, lIWORK)) return
       if(.not.createvar(16,'i', 2*N, 1, lBWORK)) return

       Q = MAX( M - NCON, NCON, R - NMEAS, NMEAS )
       LWORKMIN = max((N+Q)*(N+Q+6),13*N*N + M*M + 2*Q*Q + N*(M+Q) +
     $            max(M*(M+7*N),2*Q*(8*N+M+2*Q)) + 6*N + 
     $            max(14*N+23,16*N,2*N+max(M,2*Q),3*max(M,2*Q)))
       LWORK=maxvol(17,'d')
       if(LWORK.le.LWORKMIN) then
         buf='dhinf'//': not enough memory (use stacksize)'
         call error(998)
         return
      endif
      if(.not.createvar(17,'d',1,LWORK,lDWORK)) return
      
      CALL SB10DD( N, M, R, NCON, NMEAS, GAMMA, stk(lA), N,
     $             stk(lB), N, stk(lC), R, stk(lD), R, stk(lAK),
     $             N, stk(lBK), N, stk(lCK), NCON, stk(lDK),
     $             NCON, stk(lX), N, stk(lZ), N, stk(lRCOND), TOL,
     $             istk(lIWORK), stk(lDWORK), LDWORK, istk(lBWORK),
     $             INFO )
      if(info.ne.0) then
        call errorinfo("dhinf",info)
        return
      endif      

      lhsvar(1) = 8
      lhsvar(2) = 9
      lhsvar(3) = 10
      lhsvar(4) = 11
      if(lhs.eq.5) lhsvar(5) = 14

c
       end