home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Crawly Crypt Collection 1
/
crawlyvol1.bin
/
apps
/
math
/
matlab
/
src
/
mat4.f
< prev
next >
Wrap
Text File
|
1992-04-21
|
29KB
|
996 lines
SUBROUTINE MATFN4
C
C EVALUATE FUNCTIONS INVOLVING QR DECOMPOSITION (LEAST SQUARES)
C
DOUBLE PRECISION STKR(50005),STKI(50005)
INTEGER IDSTK(4,48),LSTK(48),MSTK(48),NSTK(48),VSIZE,LSIZE,BOT,TOP
INTEGER DDT,ERR,FMT,LCT(4),LIN(1024),LPT(6),RIO,WIO,RTE,WTE,HIO
INTEGER SYM,SYN(4),BUF(256),CHAR,FLP(2),FIN,FUN,LHS,RHS,RAN(2)
COMMON /VSTK/ STKR,STKI,IDSTK,LSTK,MSTK,NSTK,VSIZE,LSIZE,BOT,TOP
COMMON /IOP/ DDT,ERR,FMT,LCT,LIN,LPT,RIO,WIO,RTE,WTE,HIO
COMMON /COM/ SYM,SYN,BUF,CHAR,FLP,FIN,FUN,LHS,RHS,RAN
DOUBLE PRECISION S,T,TOL,EPS,FLOP
INTEGER QUOTE
DATA QUOTE/49/
C
IF (DDT .EQ. 1) WRITE(WTE,100) FIN
100 FORMAT(0X,'MATFN4',I4)
C
L = LSTK(TOP)
M = MSTK(TOP)
N = NSTK(TOP)
IF (FIN .EQ. -1) GO TO 10
IF (FIN .EQ. -2) GO TO 20
GO TO 40
C
C RECTANGULAR MATRIX RIGHT DIVISION, A/A2
10 L2 = LSTK(TOP+1)
M2 = MSTK(TOP+1)
N2 = NSTK(TOP+1)
TOP = TOP + 1
IF (N.GT.1 .AND. N.NE.N2) CALL ERROR(11)
IF (ERR .GT. 0) RETURN
CALL STACK1(QUOTE)
IF (ERR .GT. 0) RETURN
LL = L2+M2*N2
CALL WCOPY(M*N,STKR(L),STKI(L),1,STKR(LL),STKI(LL),1)
CALL WCOPY(M*N+M2*N2,STKR(L2),STKI(L2),1,STKR(L),STKI(L),1)
LSTK(TOP) = L+M2*N2
MSTK(TOP) = M
NSTK(TOP) = N
CALL STACK1(QUOTE)
IF (ERR .GT. 0) RETURN
TOP = TOP - 1
M = N2
N = M2
GO TO 20
C
C RECTANGULAR MATRIX LEFT DIVISION A BACKSLASH A2
C
20 L2 = LSTK(TOP+1)
M2 = MSTK(TOP+1)
N2 = NSTK(TOP+1)
IF (M2*N2 .GT. 1) GO TO 21
M2 = M
N2 = M
ERR = L2+M*M - LSTK(BOT)
IF (ERR .GT. 0) CALL ERROR(17)
IF (ERR .GT. 0) RETURN
CALL WSET(M*M-1,0.0D0,0.0D0,STKR(L2+1),STKI(L2+1),1)
CALL WCOPY(M,STKR(L2),STKI(L2),0,STKR(L2),STKI(L2),M+1)
21 IF (M2 .NE. M) CALL ERROR(12)
IF (ERR .GT. 0) RETURN
L3 = L2 + MAX0(M,N)*N2
L4 = L3 + N
ERR = L4 + N - LSTK(BOT)
IF (ERR .GT. 0) CALL ERROR(17)
IF (ERR .GT. 0) RETURN
IF (M .GT. N) GO TO 23
DO 22 JB = 1, N2
J = N+1-JB
LS = L2 + (J-1)*M
LL = L2 + (J-1)*N
CALL WCOPY(M,STKR(LS),STKI(LS),-1,STKR(LL),STKI(LL),-1)
22 CONTINUE
23 DO 24 J = 1, N
BUF(J) = 0
24 CONTINUE
CALL WQRDC(STKR(L),STKI(L),M,M,N,STKR(L4),STKI(L4),
$ BUF,STKR(L3),STKI(L3),1)
K = 0
EPS = STKR(VSIZE-4)
S = MAX0(M,N)
T = DABS(STKR(L))+DABS(STKI(L))
TOL = FLOP(EPS*S*T)
MN = MIN0(M,N)
DO 27 J = 1, MN
LS = L+J-1+(J-1)*M
T = DABS(STKR(LS)) + DABS(STKI(LS))
IF (T .GT. TOL) K = J
27 CONTINUE
IF (K .LT. MN) WRITE(WTE,28) K,TOL
IF (K.LT.MN .AND. WIO.NE.0) WRITE(WIO,28) K,TOL
28 FORMAT(0X,'RANK DEFICIENT, RANK =',I4,', TOL =',1PD13.4)
MN = MAX0(M,N)
DO 29 J = 1, N2
LS = L2+(J-1)*MN
CALL WQRSL(STKR(L),STKI(L),M,M,K,STKR(L4),STKI(L4),
$ STKR(LS),STKI(LS),T,T,STKR(LS),STKI(LS),
$ STKR(LS),STKI(LS),T,T,T,T,100,INFO)
LL = LS+K
CALL WSET(N-K,0.0D0,0.0D0,STKR(LL),STKI(LL),1)
29 CONTINUE
DO 31 J = 1, N
BUF(J) = -BUF(J)
31 CONTINUE
DO 35 J = 1, N
IF (BUF(J) .GT. 0) GO TO 35
K = -BUF(J)
BUF(J) = K
33 CONTINUE
IF (K .EQ. J) GO TO 34
LS = L2+J-1
LL = L2+K-1
CALL WSWAP(N2,STKR(LS),STKI(LS),MN,STKR(LL),STKI(LL),MN)
BUF(K) = -BUF(K)
K = BUF(K)
GO TO 33
34 CONTINUE
35 CONTINUE
DO 36 J = 1, N2
LS = L2+(J-1)*MN
LL = L+(J-1)*N
CALL WCOPY(N,STKR(LS),STKI(LS),1,STKR(LL),STKI(LL),1)
36 CONTINUE
MSTK(TOP) = N
NSTK(TOP) = N2
IF (FIN .EQ. -1) CALL STACK1(QUOTE)
IF (ERR .GT. 0) RETURN
GO TO 99
C
C QR
C
40 MM = MAX0(M,N)
LS = L + MM*MM
IF (LHS.EQ.1 .AND. FIN.EQ.1) LS = L
LE = LS + M*N
L4 = LE + MM
ERR = L4+MM - LSTK(BOT)
IF (ERR .GT. 0) CALL ERROR(17)
IF (ERR .GT. 0) RETURN
IF (LS.NE.L) CALL WCOPY(M*N,STKR(L),STKI(L),1,STKR(LS),STKI(LS),1)
JOB = 1
IF (LHS.LT.3) JOB = 0
DO 42 J = 1, N
BUF(J) = 0
42 CONTINUE
CALL WQRDC(STKR(LS),STKI(LS),M,M,N,STKR(L4),STKI(L4),
$ BUF,STKR(LE),STKI(LE),JOB)
IF (LHS.EQ.1 .AND. FIN.EQ.1) GO TO 99
CALL WSET(M*M,0.0D0,0.0D0,STKR(L),STKI(L),1)
CALL WSET(M,1.0D0,0.0D0,STKR(L),STKI(L),M+1)
DO 43 J = 1, M
LL = L+(J-1)*M
CALL WQRSL(STKR(LS),STKI(LS),M,M,N,STKR(L4),STKI(L4),
$ STKR(LL),STKI(LL),STKR(LL),STKI(LL),T,T,
$ T,T,T,T,T,T,10000,INFO)
43 CONTINUE
IF (FIN .EQ. 2) GO TO 99
NSTK(TOP) = M
DO 45 J = 1, N
LL = LS+J+(J-1)*M
CALL WSET(M-J,0.0D0,0.0D0,STKR(LL),STKI(LL),1)
45 CONTINUE
IF (TOP+1 .GE. BOT) CALL ERROR(18)
IF (ERR .GT. 0) RETURN
TOP = TOP+1
LSTK(TOP) = LS
MSTK(TOP) = M
NSTK(TOP) = N
IF (LHS .EQ. 2) GO TO 99
CALL WSET(N*N,0.0D0,0.0D0,STKR(LE),STKI(LE),1)
DO 47 J = 1, N
LL = LE+BUF(J)-1+(J-1)*N
STKR(LL) = 1.0D0
47 CONTINUE
IF (TOP+1 .GE. BOT) CALL ERROR(18)
IF (ERR .GT. 0) RETURN
TOP = TOP+1
LSTK(TOP) = LE
MSTK(TOP) = N
NSTK(TOP) = N
GO TO 99
C
99 RETURN
END
SUBROUTINE MATFN5
C
C FILE HANDLING AND OTHER I/O
C
DOUBLE PRECISION STKR(50005),STKI(50005)
INTEGER IDSTK(4,48),LSTK(48),MSTK(48),NSTK(48),VSIZE,LSIZE,BOT,TOP
INTEGER ALFA(52),ALFB(52),ALFL,CASE
INTEGER IDS(4,32),PSTK(32),RSTK(32),PSIZE,PT,PTZ
INTEGER DDT,ERR,FMT,LCT(4),LIN(1024),LPT(6),RIO,WIO,RTE,WTE,HIO
INTEGER SYM,SYN(4),BUF(256),CHAR,FLP(2),FIN,FUN,LHS,RHS,RAN(2)
COMMON /VSTK/ STKR,STKI,IDSTK,LSTK,MSTK,NSTK,VSIZE,LSIZE,BOT,TOP
COMMON /ALFS/ ALFA,ALFB,ALFL,CASE
COMMON /RECU/ IDS,PSTK,RSTK,PSIZE,PT,PTZ
COMMON /IOP/ DDT,ERR,FMT,LCT,LIN,LPT,RIO,WIO,RTE,WTE,HIO
COMMON /COM/ SYM,SYN,BUF,CHAR,FLP,FIN,FUN,LHS,RHS,RAN
INTEGER EOL,CH,BLANK,FLAG,TOP2,PLUS,MINUS,QUOTE,SEMI,LRAT,MRAT
CHARACTER CCH,MYCHAR,CBUF(256)
INTEGER ID(4)
DOUBLE PRECISION EPS,B,S,T,FLOP,WASUM
LOGICAL TEXT
DATA EOL/99/,BLANK/36/,PLUS/41/,MINUS/42/,QUOTE/49/,SEMI/39/
DATA LRAT/5/,MRAT/100/
C
IF (DDT .EQ. 1) WRITE(WTE,100) FIN
100 FORMAT(0X,'MATFN5',I4)
C FUNCTIONS/FIN
C EXEC SAVE LOAD PRIN DIAR DISP BASE LINE CHAR PLOT RAT DEBU
C 1 2 3 4 5 6 7 8 9 10 11 12
L = LSTK(TOP)
M = MSTK(TOP)
N = NSTK(TOP)
IF (FIN .GT. 5) GO TO 15
C
C CONVERT FILE NAME
MN = M*N
FLAG = 3
IF (SYM .EQ. SEMI) FLAG = 0
IF (RHS .LT. 2) GO TO 12
FLAG = IDINT(STKR(L))
TOP2 = TOP
TOP = TOP-1
L = LSTK(TOP)
MN = MSTK(TOP)*NSTK(TOP)
12 LUN = -1
IF (MN.EQ.1 .AND. STKR(L).LT.10.0D0) LUN = IDINT(STKR(L))
IF (LUN .EQ. RTE .AND. FIN .NE. 1) CALL ERROR(7)
IF (LUN .EQ. WTE .OR. LUN .EQ. HIO) CALL ERROR(7)
IF (ERR .GT. 0) RETURN
IF (LUN .GE. 0) GO TO 15
DO 14 J = 1, 64
LS = L+J-1
IF (J .LE. MN) CH = IDINT(STKR(LS))
IF (J .GT. MN) CH = BLANK
IF (CH.LT.0 .OR. CH.GE.ALFL) CALL ERROR(38)
IF (ERR .GT. 0) RETURN
IF (CASE .EQ. 0) BUF(J) = ALFA(CH+1)
IF (CASE .EQ. 1) BUF(J) = ALFB(CH+1)
14 CONTINUE
IOSTAT = 0
GO TO 15
C
15 GO TO (20,30,35,25,27,60,65,70,50,80,40,95),FIN
C
C EXEC
20 IF (LUN .EQ. 0) GO TO 23
K = LPT(6)
LIN(K+1) = LPT(1)
LIN(K+2) = LPT(3)
LIN(K+3) = LPT(6)
LIN(K+4) = PTZ
LIN(K+5) = RIO
LIN(K+6) = LCT(4)
LPT(1) = K + 7
LCT(4) = FLAG
PTZ = PT - 4
IF (RIO .EQ. RTE) RIO = 10
RIO = RIO + 1
IF (LUN .GT. 0) RIO = LUN
IF (LUN .LT. 0) CALL FILES(RIO,BUF,IOSTAT)
IF (IOSTAT .NE. 0) CALL ERROR(7)
IF (ERR .GT. 0) GO TO 23
IF (FLAG .GE. 4) WRITE(WTE,22)
22 FORMAT(0X,'PAUSE MODE. ENTER BLANK LINES.')
SYM = EOL
MSTK(TOP) = 0
GO TO 99
C
C EXEC(0)
23 RIO = RTE
ERR = 99
GO TO 99
C
C PRINT
25 IF (LUN .LT. 0) CALL FILES(7,BUF,IOSTAT)
IF (IOSTAT .NE. 0) CALL ERROR(7)
IF (ERR .GT. 0) RETURN
K = WTE
IF (LUN .LT. 0) WTE = 7
IF (LUN .GT. 0) WTE = LUN
L = LCT(2)
LCT(2) = 9999
IF (RHS .GT. 1) CALL PRINT(SYN,TOP2)
IF (LUN .LT. 0) CALL FILES(-WTE,BUF,IOSTAT)
WTE = K
LCT(2) = L
MSTK(TOP) = 0
GO TO 99
C
C DIARY
27 IF (WIO .NE. 0 .AND. WIO .NE. LUN) CALL FILES(-WIO,BUF,IOSTAT)
IF (WIO .NE. LUN) WIO = 0
IF (LUN .LT. 0) CALL FILES(8,BUF,IOSTAT)
IF (IOSTAT .NE. 0) CALL ERROR(7)
IF (ERR .GT. 0) RETURN
IF (LUN .LT. 0) WIO = 8
IF (LUN .GT. 0) WIO = LUN
MSTK(TOP) = 0
GO TO 99
C
C SAVE
30 IF (LUN .LT. 0) LUNIT = 1
IF (LUN .LT. 0) CALL FILES(LUNIT,BUF,IOSTAT)
IF (IOSTAT .NE. 0) CALL ERROR(7)
IF (ERR .GT. 0) RETURN
IF (LUN .GT. 0) LUNIT = LUN
K = LSIZE-4
IF (K .LT. BOT) K = LSIZE
IF (RHS .EQ. 2) K = TOP2
IF (RHS .EQ. 2) CALL PUTID(IDSTK(1,K),SYN)
32 L = LSTK(K)
M = MSTK(K)
N = NSTK(K)
DO 34 I = 1, 4
J = IDSTK(I,K)+1
BUF(I) = ALFA(J)
34 CONTINUE
IMG = 0
IF (WASUM(M*N,STKI(L),STKI(L),1) .NE. 0.0D0) IMG = 1
CALL SAVLOD(LUNIT,BUF,M,N,IMG,0,STKR(L),STKI(L))
K = K-1
IF (K .GE. BOT) GO TO 32
CALL FILES(-LUNIT,BUF,IOSTAT)
MSTK(TOP) = 0
GO TO 99
C
C LOAD
35 IF (LUN .LT. 0) LUNIT = 2
IF (LUN .LT. 0) CALL FILES(LUNIT,BUF,IOSTAT)
IF (IOSTAT .NE. 0) CALL ERROR(7)
IF (ERR .GT. 0) RETURN
IF (LUN .GT. 0) LUNIT = LUN
36 JOB = LSTK(BOT) - L
CALL SAVLOD(LUNIT,ID,MSTK(TOP),NSTK(TOP),IMG,JOB,STKR(L),STKI(L))
MN = MSTK(TOP)*NSTK(TOP)
IF (MN .EQ. 0) GO TO 39
IF (IMG .EQ. 0) CALL RSET(MN,0.0D0,STKI(L),1)
DO 38 I = 1, 4
J = 0
37 J = J+1
IF (ID(I).NE.ALFA(J) .AND. J.LE.BLANK) GO TO 37
ID(I) = J-1
38 CONTINUE
SYM = SEMI
RHS = 0
CALL STACKP(ID)
TOP = TOP + 1
GO TO 36
39 CALL FILES(-LUNIT,BUF,IOSTAT)
MSTK(TOP) = 0
GO TO 99
C
C RAT
40 IF (RHS .EQ. 2) GO TO 44
MN = M*N
L2 = L
IF (LHS .EQ. 2) L2 = L + MN
LW = L2 + MN
ERR = LW + LRAT - LSTK(BOT)
IF (ERR .GT. 0) CALL ERROR(17)
IF (ERR .GT. 0) RETURN
IF (LHS .EQ. 2) TOP = TOP + 1
LSTK(TOP) = L2
MSTK(TOP) = M
NSTK(TOP) = N
CALL RSET(LHS*MN,0.0D0,STKI(L),1)
DO 42 I = 1, MN
CALL RAT(STKR(L),LRAT,MRAT,S,T,STKR(LW))
STKR(L) = S
STKR(L2) = T
IF (LHS .EQ. 1) STKR(L) = FLOP(S/T)
L = L + 1
L2 = L2 + 1
42 CONTINUE
GO TO 99
44 MRAT = IDINT(STKR(L))
LRAT = IDINT(STKR(L-1))
TOP = TOP - 1
MSTK(TOP) = 0
GO TO 99
C
C CHAR
50 K = IABS(IDINT(STKR(L)))
IF (M*N.NE.1 .OR. K.GE.ALFL) CALL ERROR(36)
IF (ERR .GT. 0) RETURN
CH = ALFA(K+1)
IF (STKR(L) .LT. 0.0D0) CH = ALFB(K+1)
CCH=MYCHAR(CH)
WRITE(WTE,51) CCH
51 FORMAT(0X,'REPLACE CHARACTER ',A1)
READ(RTE,52) CCH
CH=ICHAR(CCH)
52 FORMAT(A1)
IF (STKR(L) .GE. 0.0D0) ALFA(K+1) = CH
IF (STKR(L) .LT. 0.0D0) ALFB(K+1) = CH
MSTK(TOP) = 0
GO TO 99
C
C DISP
60 WRITE(WTE,61)
IF (WIO .NE. 0) WRITE(WIO,61)
61 FORMAT(0X,80A1)
IF (RHS .EQ. 2) GO TO 65
MN = M*N
TEXT = .TRUE.
DO 62 I = 1, MN
LS = L+I-1
CH = IDINT(STKR(LS))
T = CH
TEXT = TEXT .AND. (CH.GE.0) .AND. (CH.LT.ALFL)
TEXT = TEXT .AND. (T.EQ.STKR(LS))
62 CONTINUE
DO 64 I = 1, M
DO 63 J = 1, N
LS = L+I-1+(J-1)*M
IF (STKR(LS) .EQ. 0.0D0) CH = BLANK
IF (STKR(LS) .GT. 0.0D0) CH = PLUS
IF (STKR(LS) .LT. 0.0D0) CH = MINUS
IF (TEXT) CH = IDINT(STKR(LS))
BUF(J) = ALFA(CH+1)
63 CONTINUE
DO 1010 J=1,N
CBUF(J)=MYCHAR(BUF(J))
1010 CONTINUE
WRITE(WTE,61) (CBUF(J),J=1,N)
IF (WIO .NE. 0) WRITE(WIO,61) (CBUF(J),J=1,N)
64 CONTINUE
MSTK(TOP) = 0
GO TO 99
C
C BASE
65 IF (RHS .NE. 2) CALL ERROR(39)
IF (STKR(L) .LE. 1.0D0) CALL ERROR(36)
IF (ERR .GT. 0) RETURN
B = STKR(L)
L2 = L
TOP = TOP-1
RHS = 1
L = LSTK(TOP)
M = MSTK(TOP)*NSTK(TOP)
EPS = STKR(VSIZE-4)
DO 66 I = 1, M
LS = L2+(I-1)*N
LL = L+I-1
CALL BASE(STKR(LL),B,EPS,STKR(LS),N)
66 CONTINUE
CALL RSET(M*N,0.0D0,STKI(L2),1)
CALL WCOPY(M*N,STKR(L2),STKI(L2),1,STKR(L),STKI(L),1)
MSTK(TOP) = N
NSTK(TOP) = M
CALL STACK1(QUOTE)
IF (FIN .EQ. 6) GO TO 60
GO TO 99
C
C LINES
70 LCT(2) = IDINT(STKR(L))
MSTK(TOP) = 0
GO TO 99
C
C PLOT
80 IF (RHS .GE. 2) GO TO 82
N = M*N
DO 81 I = 1, N
LL = L+I-1
STKI(LL) = I
81 CONTINUE
CALL PLOT(WTE,STKI(L),STKR(L),N,T,0,BUF)
IF (WIO .NE. 0) CALL PLOT(WIO,STKI(L),STKR(L),N,T,0,BUF)
MSTK(TOP) = 0
GO TO 99
82 IF (RHS .EQ. 2) K = 0
IF (RHS .EQ. 3) K = M*N
IF (RHS .GT. 3) K = RHS - 2
TOP = TOP - (RHS - 1)
N = MSTK(TOP)*NSTK(TOP)
IF (MSTK(TOP+1)*NSTK(TOP+1) .NE. N) CALL ERROR(5)
IF (ERR .GT. 0) RETURN
LX = LSTK(TOP)
LY = LSTK(TOP+1)
IF (RHS .GT. 3) L = LSTK(TOP+2)
CALL PLOT(WTE,STKR(LX),STKR(LY),N,STKR(L),K,BUF)
IF (WIO .NE. 0) CALL PLOT(WIO,STKR(LX),STKR(LY),N,STKR(L),K,BUF)
MSTK(TOP) = 0
GO TO 99
C
C DEBUG
95 DDT = IDINT(STKR(L))
WRITE(WTE,96) DDT
96 FORMAT(0X,'DEBUG ',I4)
MSTK(TOP) = 0
GO TO 99
C
99 RETURN
END
SUBROUTINE MATFN6
C
C EVALUATE UTILITY FUNCTIONS
C
DOUBLE PRECISION STKR(50005),STKI(50005)
INTEGER IDSTK(4,48),LSTK(48),MSTK(48),NSTK(48),VSIZE,LSIZE,BOT,TOP
INTEGER DDT,ERR,FMT,LCT(4),LIN(1024),LPT(6),RIO,WIO,RTE,WTE,HIO
INTEGER SYM,SYN(4),BUF(256),CHAR,FLP(2),FIN,FUN,LHS,RHS,RAN(2)
COMMON /VSTK/ STKR,STKI,IDSTK,LSTK,MSTK,NSTK,VSIZE,LSIZE,BOT,TOP
COMMON /IOP/ DDT,ERR,FMT,LCT,LIN,LPT,RIO,WIO,RTE,WTE,HIO
COMMON /COM/ SYM,SYN,BUF,CHAR,FLP,FIN,FUN,LHS,RHS,RAN
INTEGER SEMI,ID(4),UNIFOR(4),NORMAL(4),SEED(4)
DOUBLE PRECISION EPS0,EPS,S,SR,SI,T
DOUBLE PRECISION FLOP,URAND
LOGICAL EQID
DATA SEMI/39/
DATA UNIFOR/30,23,18,15/,NORMAL/23,24,27,22/,SEED/28,14,14,13/
C
IF (DDT .EQ. 1) WRITE(WTE,100) FIN
100 FORMAT(0X,'MATFN6',I4)
C FUNCTIONS/FIN
C MAGI DIAG SUM PROD USER EYE RAND ONES CHOP SIZE KRON TRIL TRIU
C 1 2 3 4 5 6 7 8 9 10 11-13 14 15
L = LSTK(TOP)
M = MSTK(TOP)
N = NSTK(TOP)
GO TO (75,80,65,67,70,90,90,90,60,77,50,50,50,80,80),FIN
C
C KRONECKER PRODUCT
50 IF (RHS .NE. 2) CALL ERROR(39)
IF (ERR .GT. 0) RETURN
TOP = TOP - 1
L = LSTK(TOP)
MA = MSTK(TOP)
NA = NSTK(TOP)
LA = L + MAX0(M*N*MA*NA,M*N+MA*NA)
LB = LA + MA*NA
ERR = LB + M*N - LSTK(BOT)
IF (ERR .GT. 0) CALL ERROR(17)
IF (ERR .GT. 0) RETURN
C MOVE A AND B ABOVE RESULT
CALL WCOPY(MA*NA+M*N,STKR(L),STKI(L),1,STKR(LA),STKI(LA),1)
DO 54 JA = 1, NA
DO 53 J = 1, N
LJ = LB + (J-1)*M
DO 52 IA = 1, MA
C GET J-TH COLUMN OF B
CALL WCOPY(M,STKR(LJ),STKI(LJ),1,STKR(L),STKI(L),1)
C ADDRESS OF A(IA,JA)
LS = LA + IA-1 + (JA-1)*MA
DO 51 I = 1, M
C A(IA,JA) OP B(I,J)
IF (FIN .EQ. 11) CALL WMUL(STKR(LS),STKI(LS),
$ STKR(L),STKI(L),STKR(L),STKI(L))
IF (FIN .EQ. 12) CALL WDIV(STKR(LS),STKI(LS),
$ STKR(L),STKI(L),STKR(L),STKI(L))
IF (FIN .EQ. 13) CALL WDIV(STKR(L),STKI(L),
$ STKR(LS),STKI(LS),STKR(L),STKI(L))
IF (ERR .GT. 0) RETURN
L = L + 1
51 CONTINUE
52 CONTINUE
53 CONTINUE
54 CONTINUE
MSTK(TOP) = M*MA
NSTK(TOP) = N*NA
GO TO 99
C
C CHOP
60 EPS0 = 1.0D0
61 EPS0 = EPS0/2.0D0
T = FLOP(1.0D0 + EPS0)
IF (T .GT. 1.0D0) GO TO 61
EPS0 = 2.0D0*EPS0
FLP(2) = IDINT(STKR(L))
IF (SYM .NE. SEMI) WRITE(WTE,62) FLP(2)
62 FORMAT(/0X,'CHOP ',I2,' PLACES.')
EPS = 1.0D0
63 EPS = EPS/2.0D0
T = FLOP(1.0D0 + EPS)
IF (T .GT. 1.0D0) GO TO 63
EPS = 2.0D0*EPS
T = STKR(VSIZE-4)
IF (T.LT.EPS .OR. T.EQ.EPS0) STKR(VSIZE-4) = EPS
MSTK(TOP) = 0
GO TO 99
C
C SUM
65 SR = 0.0D0
SI = 0.0D0
MN = M*N
DO 66 I = 1, MN
LS = L+I-1
SR = FLOP(SR+STKR(LS))
SI = FLOP(SI+STKI(LS))
66 CONTINUE
GO TO 69
C
C PROD
67 SR = 1.0D0
SI = 0.0D0
MN = M*N
DO 68 I = 1, MN
LS = L+I-1
CALL WMUL(STKR(LS),STKI(LS),SR,SI,SR,SI)
68 CONTINUE
69 STKR(L) = SR
STKI(L) = SI
MSTK(TOP) = 1
NSTK(TOP) = 1
GO TO 99
C
C USER
70 S = 0.0D0
T = 0.0D0
IF (RHS .LT. 2) GO TO 72
IF (RHS .LT. 3) GO TO 71
T = STKR(L)
TOP = TOP-1
L = LSTK(TOP)
M = MSTK(TOP)
N = NSTK(TOP)
71 S = STKR(L)
TOP = TOP-1
L = LSTK(TOP)
M = MSTK(TOP)
N = NSTK(TOP)
72 CALL USER(STKR(L),M,N,S,T)
CALL RSET(M*N,0.0D0,STKI(L),1)
MSTK(TOP) = M
NSTK(TOP) = N
GO TO 99
C
C MAGIC
75 N = MAX0(IDINT(STKR(L)),0)
IF (N .EQ. 2) N = 0
IF (N .GT. 0) CALL MAGIC(STKR(L),N,N)
CALL RSET(N*N,0.0D0,STKI(L),1)
MSTK(TOP) = N
NSTK(TOP) = N
GO TO 99
C
C SIZE
77 STKR(L) = M
STKR(L+1) = N
STKI(L) = 0.0D0
STKI(L+1) = 0.0D0
MSTK(TOP) = 1
NSTK(TOP) = 2
IF (LHS .EQ. 1) GO TO 99
NSTK(TOP) = 1
TOP = TOP + 1
LSTK(TOP) = L+1
MSTK(TOP) = 1
NSTK(TOP) = 1
GO TO 99
C
C DIAG, TRIU, TRIL
80 K = 0
IF (RHS .NE. 2) GO TO 81
K = IDINT(STKR(L))
TOP = TOP-1
L = LSTK(TOP)
M = MSTK(TOP)
N = NSTK(TOP)
81 IF (FIN .GE. 14) GO TO 85
IF (M .EQ. 1 .OR. N .EQ. 1) GO TO 83
IF (K.GE.0) MN=MIN0(M,N-K)
IF (K.LT.0) MN=MIN0(M+K,N)
MSTK(TOP) = MAX0(MN,0)
NSTK(TOP) = 1
IF (MN .LE. 0) GO TO 99
DO 82 I = 1, MN
IF (K.GE.0) LS = L+(I-1)+(I+K-1)*M
IF (K.LT.0) LS = L+(I-K-1)+(I-1)*M
LL = L+I-1
STKR(LL) = STKR(LS)
STKI(LL) = STKI(LS)
82 CONTINUE
GO TO 99
83 N = MAX0(M,N)+IABS(K)
ERR = L+N*N - LSTK(BOT)
IF (ERR .GT. 0) CALL ERROR(17)
IF (ERR .GT. 0) RETURN
MSTK(TOP) = N
NSTK(TOP) = N
DO 84 JB = 1, N
DO 84 IB = 1, N
J = N+1-JB
I = N+1-IB
SR = 0.0D0
SI = 0.0D0
IF (K.GE.0) LS = L+I-1
IF (K.LT.0) LS = L+J-1
LL = L+I-1+(J-1)*N
IF (J-I .EQ. K) SR = STKR(LS)
IF (J-I .EQ. K) SI = STKI(LS)
STKR(LL) = SR
STKI(LL) = SI
84 CONTINUE
GO TO 99
C
C TRIL, TRIU
85 DO 87 J = 1, N
LD = L + J - K - 1 + (J-1)*M
IF (FIN .EQ. 14) LL = J - K - 1
IF (FIN .EQ. 14) LS = LD - LL
IF (FIN .EQ. 15) LL = M - J + K
IF (FIN .EQ. 15) LS = LD + 1
IF (LL .GT. 0) CALL WSET(LL,0.0D0,0.0D0,STKR(LS),STKI(LS),1)
87 CONTINUE
GO TO 99
C
C EYE, RAND, ONES
90 IF (M.GT.1 .OR. RHS.EQ.0) GO TO 94
IF (RHS .NE. 2) GO TO 91
NN = IDINT(STKR(L))
TOP = TOP-1
L = LSTK(TOP)
N = NSTK(TOP)
91 IF (FIN.NE.7 .OR. N.LT.4) GO TO 93
DO 92 I = 1, 4
LS = L+I-1
ID(I) = IDINT(STKR(LS))
92 CONTINUE
IF (EQID(ID,UNIFOR).OR.EQID(ID,NORMAL)) GO TO 97
IF (EQID(ID,SEED)) GO TO 98
93 IF (N .GT. 1) GO TO 94
M = MAX0(IDINT(STKR(L)),0)
IF (RHS .EQ. 2) N = MAX0(NN,0)
IF (RHS .NE. 2) N = M
ERR = L+M*N - LSTK(BOT)
IF (ERR .GT. 0) CALL ERROR(17)
IF (ERR .GT. 0) RETURN
MSTK(TOP) = M
NSTK(TOP) = N
IF (M*N .EQ. 0) GO TO 99
94 DO 96 J = 1, N
DO 96 I = 1, M
LL = L+I-1+(J-1)*M
STKR(LL) = 0.0D0
STKI(LL) = 0.0D0
IF (I.EQ.J .OR. FIN.EQ.8) STKR(LL) = 1.0D0
IF (FIN.EQ.7 .AND. RAN(2).EQ.0) STKR(LL) = FLOP(URAND(RAN(1)))
IF (FIN.NE.7 .OR. RAN(2).EQ.0) GO TO 96
95 SR = 2.0D0*URAND(RAN(1))-1.0D0
SI = 2.0D0*URAND(RAN(1))-1.0D0
T = SR*SR + SI*SI
IF (T .GT. 1.0D0) GO TO 95
STKR(LL) = FLOP(SR*DSQRT(-2.0D0*DLOG(T)/T))
96 CONTINUE
GO TO 99
C
C SWITCH UNIFORM AND NORMAL
97 RAN(2) = ID(1) - UNIFOR(1)
MSTK(TOP) = 0
GO TO 99
C
C SEED
98 IF (RHS .EQ. 2) RAN(1) = NN
STKR(L) = RAN(1)
MSTK(TOP) = 1
IF (RHS .EQ. 2) MSTK(TOP) = 0
NSTK(TOP) = 1
GO TO 99
C
99 RETURN
END
SUBROUTINE ERROR(N)
INTEGER N
DOUBLE PRECISION STKR(50005),STKI(50005)
INTEGER IDSTK(4,48),LSTK(48),MSTK(48),NSTK(48),VSIZE,LSIZE,BOT,TOP
INTEGER IDS(4,32),PSTK(32),RSTK(32),PSIZE,PT,PTZ
INTEGER ALFA(52),ALFB(52),ALFL,CASE
INTEGER DDT,ERR,FMT,LCT(4),LIN(1024),LPT(6),RIO,WIO,RTE,WTE,HIO
INTEGER SYM,SYN(4),BUF(256),CHAR,FLP(2),FIN,FUN,LHS,RHS,RAN(2)
COMMON /VSTK/ STKR,STKI,IDSTK,LSTK,MSTK,NSTK,VSIZE,LSIZE,BOT,TOP
COMMON /RECU/ IDS,PSTK,RSTK,PSIZE,PT,PTZ
COMMON /ALFS/ ALFA,ALFB,ALFL,CASE
COMMON /IOP/ DDT,ERR,FMT,LCT,LIN,LPT,RIO,WIO,RTE,WTE,HIO
COMMON /COM/ SYM,SYN,BUF,CHAR,FLP,FIN,FUN,LHS,RHS,RAN
CHARACTER CBUF(256),MYCHAR
CHARACTER ERRMSG(8),BLH,BEL
DATA ERRMSG /'/','-','-','E','R','R','O','R'/,BLH/' '/,BEL/'◆'/
C SET BEL TO CTRL-G IF POSSIBLE
C
K = LPT(2) - LPT(1)
IF (K .LT. 1) K = 1
LUNIT = WTE
98 WRITE(LUNIT,100) (BLH,I=1,K),(ERRMSG(I),I=1,8),BEL
100 FORMAT(0X,80A1)
GO TO (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),N
C
1 WRITE(LUNIT,101)
101 FORMAT(0X,'IMPROPER MULTIPLE ASSIGNMENT')
GO TO 99
2 WRITE(LUNIT,102)
102 FORMAT(0X,'IMPROPER FACTOR')
GO TO 99
3 WRITE(LUNIT,103)
103 FORMAT(0X,'EXPECT RIGHT PARENTHESIS')
GO TO 99
4 DO 94 I = 1, 4
K = IDS(I,PT+1)
BUF(I) = ALFA(K+1)
CBUF(I)=MYCHAR(BUF(I))
94 CONTINUE
WRITE(LUNIT,104) (CBUF(I),I=1,4)
104 FORMAT(0X,'UNDEFINED VARIABLE: ',4A1)
GO TO 99
5 WRITE(LUNIT,105)
105 FORMAT(0X,'COLUMN LENGTHS DO NOT MATCH')
GO TO 99
6 WRITE(LUNIT,106)
106 FORMAT(0X,'ROW LENGTHS DO NOT MATCH')
GO TO 99
7 K = 65
77 K = K-1
IF (BUF(K) .EQ. ICHAR(BLH)) GO TO 77
DO 1075 I=1,K
CBUF(I)=MYCHAR(BUF(I))
1075 CONTINUE
WRITE(LUNIT,107) (CBUF(I),I=1,K)
107 FORMAT(0X,'CAN NOT OPEN FILE: ',64A1)
GO TO 99
8 WRITE(LUNIT,108)
108 FORMAT(0X,'INCOMPATIBLE FOR ADDITION')
GO TO 99
9 WRITE(LUNIT,109)
109 FORMAT(0X,'INCOMPATIBLE FOR SUBTRACTION')
GO TO 99
10 WRITE(LUNIT,110)
110 FORMAT(0X,'INCOMPATIBLE FOR MULTIPLICATION')
GO TO 99
11 WRITE(LUNIT,111)
111 FORMAT(0X,'INCOMPATIBLE FOR RIGHT DIVISION')
GO TO 99
12 WRITE(LUNIT,112)
112 FORMAT(0X,'INCOMPATIBLE FOR LEFT DIVISION')
GO TO 99
13 WRITE(LUNIT,113)
113 FORMAT(0X,'IMPROPER ASSIGNMENT TO PERMANENT VARIABLE')
GO TO 99
14 WRITE(LUNIT,114)
114 FORMAT(0X,'EYE-DENTITY UNDEFINED BY CONTEXT')
GO TO 99
15 WRITE(LUNIT,115)
115 FORMAT(0X,'IMPROPER ASSIGNMENT TO SUBMATRIX')
GO TO 99
16 WRITE(LUNIT,116)
116 FORMAT(0X,'IMPROPER COMMAND')
GO TO 99
17 LB = VSIZE - LSTK(BOT) + 1
LT = ERR + LSTK(BOT)
WRITE(LUNIT,117) LB,LT,VSIZE
117 FORMAT(0X,'TOO MUCH MEMORY REQUIRED'
$ /0X,' ',I7,' VARIABLES,',I7,' TEMPORARIES,',I7,' AVAILABLE.')
GO TO 99
18 WRITE(LUNIT,118)
118 FORMAT(0X,'TOO MANY NAMES')
GO TO 99
19 WRITE(LUNIT,119)
119 FORMAT(0X,'MATRIX IS SINGULAR TO WORKING PRECISION')
GO TO 99
20 WRITE(LUNIT,120)
120 FORMAT(0X,'MATRIX MUST BE SQUARE')
GO TO 99
21 WRITE(LUNIT,121)
121 FORMAT(0X,'SUBSCRIPT OUT OF RANGE')
GO TO 99
22 WRITE(LUNIT,122) (RSTK(I),I=1,PT)
122 FORMAT(0X,'RECURSION DIFFICULTIES',10I4)
GO TO 99
23 WRITE(LUNIT,123)
123 FORMAT(0X,'ONLY 1, 2 OR INF NORM OF MATRIX')
GO TO 99
24 WRITE(LUNIT,124)
124 FORMAT(0X,'NO CONVERGENCE')
GO TO 99
25 WRITE(LUNIT,125)
125 FORMAT(0X,'CAN NOT USE FUNCTION NAME AS VARIABLE')
GO TO 99
26 WRITE(LUNIT,126)
126 FORMAT(0X,'TOO COMPLICATED (STACK OVERFLOW)')
GO TO 99
27 WRITE(LUNIT,127)
127 FORMAT(0X,'DIVISION BY ZERO IS A NO-NO')
GO TO 99
28 WRITE(LUNIT,128)
128 FORMAT(0X,'EMPTY MACRO')
GO TO 99
29 WRITE(LUNIT,129)
129 FORMAT(0X,'NOT POSITIVE DEFINITE')
GO TO 99
30 WRITE(LUNIT,130)
130 FORMAT(0X,'IMPROPER EXPONENT')
GO TO 99
31 WRITE(LUNIT,131)
131 FORMAT(0X,'IMPROPER STRING')
GO TO 99
32 WRITE(LUNIT,132)
132 FORMAT(0X,'SINGULARITY OF LOG OR ATAN')
GO TO 99
33 WRITE(LUNIT,133)
133 FORMAT(0X,'TOO MANY COLONS')
GO TO 99
34 WRITE(LUNIT,134)
134 FORMAT(0X,'IMPROPER FOR CLAUSE')
GO TO 99
35 WRITE(LUNIT,135)
135 FORMAT(0X,'IMPROPER WHILE OR IF CLAUSE')
GO TO 99
36 WRITE(LUNIT,136)
136 FORMAT(0X,'ARGUMENT OUT OF RANGE')
GO TO 99
37 WRITE(LUNIT,137)
137 FORMAT(0X,'IMPROPER MACRO')
GO TO 99
38 WRITE(LUNIT,138)
138 FORMAT(0X,'IMPROPER FILE NAME')
GO TO 99
39 WRITE(LUNIT,139)
139 FORMAT(0X,'INCORRECT NUMBER OF ARGUMENTS')
GO TO 99
40 WRITE(LUNIT,140)
140 FORMAT(0X,'EXPECT STATEMENT TERMINATOR')
GO TO 99
C
99 ERR = N
IF (LUNIT.EQ.WIO .OR. WIO.EQ.0) RETURN
LUNIT = WIO
GO TO 98
END
DOUBLE PRECISION FUNCTION PYTHAG(A,B)
DOUBLE PRECISION A,B
C
C FINDS DSQRT(A**2+B**2) WITHOUT OVERFLOW OR DESTRUCTIVE UNDERFLOW
C
INTEGER DDT,ERR,FMT,LCT(4),LIN(1024),LPT(6),RIO,WIO,RTE,WTE,HIO
COMMON /IOP/ DDT,ERR,FMT,LCT,LIN,LPT,RIO,WIO,RTE,WTE,HIO
DOUBLE PRECISION P,R,S,T,U
P = DMAX1(DABS(A),DABS(B))
IF (P .EQ. 0.0D0) GO TO 20
R = (DMIN1(DABS(A),DABS(B))/P)**2
IF (DDT .EQ. 25) WRITE(WTE,1)
IF (DDT .EQ. 25) WRITE(WTE,2) P,R
1 FORMAT(0X,'PYTHAG',1P2D23.15)
2 FORMAT(0X,1P2D23.15)
10 CONTINUE
T = 4.0D0 + R
IF (T .EQ. 4.0D0) GO TO 20
S = R/T
U = 1.0D0 + 2.0D0*S
P = U*P
R = (S/U)**2 * R
IF (DDT .EQ. 25) WRITE(WTE,2) P,R
GO TO 10
20 PYTHAG = P
RETURN
END
SUBROUTINE RAT(X,LEN,MAXD,A,B,D)
INTEGER LEN,MAXD
DOUBLE PRECISION X,A,B,D(LEN)
C
C A/B = CONTINUED FRACTION APPROXIMATION TO X
C USING LEN TERMS EACH LESS THAN MAXD
C
INTEGER DDT,ERR,FMT,LCT(4),LIN(1024),LPT(6),RIO,WIO,RTE,WTE,HIO
COMMON /IOP/ DDT,ERR,FMT,LCT,LIN,LPT,RIO,WIO,RTE,WTE,HIO
DOUBLE PRECISION S,T,Z,ROUND
Z = X
S = MAXD
DO 10 I = 1, LEN
K = I
D(K) = ROUND(Z)
Z = Z - D(K)
IF (S*DABS(Z) .LE. 1.0D0) GO TO 20
Z = 1.0D0/Z
10 CONTINUE
20 T = D(K)
S = 1.0D0
IF (K .LT. 2) GO TO 40
DO 30 IB = 2, K
I = K+1-IB
Z = T
T = D(I)*T + S
S = Z
30 CONTINUE
40 IF (S .LT. 0.0D0) T = -T
IF (S .LT. 0.0D0) S = -S
IF (DDT .EQ. 27) WRITE(WTE,50) X,T,S,(D(I),I=1,K)
50 FORMAT(/0X,1PD23.15,0PF8.0,' /',F8.0,4X,6F5.0/(0X,45X,6F5.0))
A = T
B = S
RETURN
END