Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird Runtime Error 1

Status
Not open for further replies.

hyungsup

MIS
Feb 8, 2007
2
IE
I'm getting runtime error in this.
The code is from a journal which is couple of years old and it seems that it has errors in it.
I did use a program to copy the pdf file to text but there were some few errors and I did clean it up.
I'm getting a runtime error on the line above 37
P(J)=DNML(ZB)-DNML(ZA)
Can someone help me out here?
I do not have any knowledge in FORTRAN and I need this program working to do a project.
If you cannot help me could you at least tell me what part to study to solve the problem?
I studied C++ but all this declaring thingy is confusing me..
Anyway thanks in advanced and hope you can help me!

The code is here and it may be copyrighted so you may not be able to use for your own profit.....

C
C PART 1
C
C FIND THE STATES OF A MARKOV CHAIN
C REPRESENTATION OF A SHEWHART CONTROL CHART WITH
C SUPPLEMENTARY RUNS RULES OF THE FORM T(K,M,A,B).
C
INTEGER H,CK,CX,QH,SG,TMP,D,QQNS,DI(20),PS(58),L2(20)
INTEGER X(20,10),Q(400,10),QQ(400),S(20)
DOUBLE PRECISION ARL,CDF(41),CUM,LR(400)
DOUBLE PRECISION LH,LP,P(10),R(41),SHIFT
DOUBLE PRECISION STD,U(400),ZA,ZB,DNML
CHARACTER*1 ANS
CHARACTER*54 FNAME
DIMENSION K(20),M(20),NX(58),A(20),B(20)
C
C INPUT THE RULES DEFINING THE CHART
C
WRITE(*,*) 'HOW MANY RUNS RULES ARE DESIRED?'
READ(*,*) NT
DO 1 I=1,NT
WRITE(*,499) I
1 READ(*,*) K(I),M(I),A(I),B(I)
C
C FIND THE REGIONS OF THE CHART
C
R(1)=-9
DO 2 I=1,NT
R(2*I)=A(I)
2 R(2*I+1)=B(I)
R(2*NT+2)=9
MR1=2*NT
MR=MR1+1
NR=MR
3 CK=0
DO 5 J=1,MR
IF(R(J).EQ.R(J+1).AND.J.LE.NR) THEN
DO 4 L=J,NR
4 R(L)=R(L+1)
NR=NR-1
CK=1
ENDIF
IF(R(J).GT.R(J+1)) THEN
TP=R(J)
R(J)=R(J+1)
R(J+1)=TP
CK=1
ENDIF
5 CONTINUE
MR=MR-1
IF(MR.GT.NR) MR=NR
IF(CK.EQ.1.AND.MR.GE.1) GO TO 3
C
C FIND THE LENGTH OF THE STATE VECTOR
C AND THE POINTERS TO THE END OF THE SUBVECTOR
C ASSOCIATED WITH EACH RUNS RULE.
C
CK=0
NV=0
DO 6 I=1,NT
NV=NV+M(I)-1
IF(K(I).LT.M(I)) CK=1
6 CONTINUE
IF(CK.EQ.0) NV=NV+1
DI(1)=M(1)-1
DO 7 I=2,NT
DI(I)=DI(I-1)+M(I)-1
IF(M(I).EQ.1) DI(I)=0
7 CONTINUE
C
C DETERMINE THE VALUE OF THE PRESENT
C INDICATOR VARIABLE BY RUNS RULE AND REGION
C COMBINATION.
C
DO 9 I=1,NT
DO 8 J=1,NR
X(I,J)=0
IF(A(I).LE.R(J).AND.R(J+1).LE.B(I)) X(I,J)=1
8 CONTINUE
9 CONTINUE
C
C DETERMINE THE STATE TO STATE
C TRANSITIONS BY REGIONS.
C
QQ(1)=0
QQNS=2**NV-1
NS=1
H=1
10 QH=QQ(H)
DO 11 L=1,NV
PS(L)=QH-2*(QH/2)
11 QH=QH/2
DO 13 I=1,NT
S(I)=0
IF(M(I).GT.1) THEN
DO 12 L=DI(I)-M(I)+2,DI(I)
12 S(I)=S(I)+PS(L)
ENDIF
13 CONTINUE
DO 19 J=1,NR
SG=0
DO 16 I=1,NT
IF(SG.EQ.0) THEN
IF(S(I)+X(I,J).GE.K(I)) THEN
SG=1
ELSE
IF(M(I).GT.1) NX(DI(I)-M(I)+2)=X(I,J)
IF (M(I).GT.2) THEN
DO 14 L=DI(I)-M(I)+3,DI(I)
14 NX(L)=PS(L-1)
ENDIF
ENDIF
IF(X(I,J).EQ.0.AND.M(I).GT.1) THEN
TMP=S(I)-PS(DI(I))+1
L=DI(I)
CK=0
15 IF(NX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 CONTINUE
31 CONTINUE
NS=NS-1
CK=1
ENDIF
H=H+1
IF(H.LT.NS) GO TO 26
I=I+1
IF(I.LT.NS-1) GO TO 25
IF(CK.EQ.1) GO TO 24
C
C NUMBER THE NEXT-STATE TRANSITIONS
C
DO 34 I=1,NS
DO 33 J=1,NR
IF(Q(I,J).LT.QQNS) THEN
CK=0
L=1
32 IF(Q(I,J).EQ.QQ(L)) THEN
Q(I,J)=L
CK=1
ENDIF
L=L+1
IF(CK.EQ.0.AND.L.LT.NS) GO TO 32
ELSE
Q(I,J)=NS
ENDIF
33 CONTINUE
34 CONTINUE
C
C OUTPUT THE STATE, NEXT-STATE TRANSITION MATRIX
C
WRITE(*,*) 'OUTPUT THE (STATE, NEXT-STATE) MATRIX?'
READ(*,100) ANS
IF(ANS.EQ.'N'.OR.ANS.EQ.'n') GO TO 36
WRITE(*,*) 'NAME OF OUTPUT FILE? '
READ(*,101) FNAME
OPEN (50,FILE=FNAME)
WRITE(50,500) NS,NR
WRITE(50,501) (R(J),J=1,NR+1)
DO 35 I=1,NS
35 WRITE(50,502) I,(Q(I,J),J=1,NR)
CLOSE (50)
C
C PART 2
C
C COMPUTE THE CUMULATIVE DISTRIBUTION
C FUNCTION, THE AVERAGE RUN LENGTHn(ARL) AND THE
C STANDARD DEVIATION (STD) OF THE RUN LENGTH FOR A
C GIVEN (INPUTED) STANDARDIZED SHIFT IN THE MEAN.
C
36 WRITE(*,*) 'STANDARDIZED SHIFT DESIRED?'
READ(*,*) SHIFT
IST=1
DO 37 J=1,NR
ZA=R(J)-SHIFT
ZB=R(J+1)-SHIFT
P(J)=DNML(ZB)-DNML(ZA)
37 CONTINUE
DO 39 I=1,NS-1
U(I)=0.D0
DO 38 J=1,NR
IF(Q(I,J).NE.NS) U(I)=U(I)+P(J)
38 CONTINUE
39 U(I)=1.D0-U(I)
N=1
CUM=U(IST)
CDF(1)=CUM
ARL=CUM
STD=CUM
CK=0
40 N=N+1
DO 42 I=1,NS-1
LR(I)=0
DO 41 J=1,NR
IF(Q(I,J).NE.NS) LR(I)=LR(I)+P(J)*U(Q(I,J))
41 CONTINUE
42 CONTINUE
IF(U(IST).NE.0.0.AND.CUM.NE.1.0) THEN
LH=LR(IST)/U(IST)
LP=(1-CUM-LR(IST))/(1-CUM)
TP=ABS(LH-LP)
IF(N.GT.9.AND.TP.LT.0.000001) CK=1
ENDIF
IF(CUM.EQ.1.0D0) CK=1
IF(N.GT.40) CK=1
ARL=ARL+N*LR(IST)
STD=STD+N*N*LR(IST)
IF(CK.EQ.1) THEN
TP=N/(1-LH)+1/((1-LH)*(1-LH))
ARL=ARL+LH*LR(IST)*TP
TP=1-LH
TP=N*N/TP+(2*N-1)/(TP*TP)+2/(TP*TP*TP)
STD=STD+LH*LR(IST)*TP
ENDIF
DO 43 I=1,NS-1
43 U(I)=LR(I)
CUM=CUM+LR(IST)
CDF(N)=CUM
IF(CK.EQ.0) GO TO 40
STD=DSQRT(STD-ARL*ARL)
C
C PRINT THE CDF, ARL AND STD OF THE
C RUN LENGTH FOR THE GIVEN STANDARDIZED
C SHIFT IN THE MEAN.
C
WRITE(*,*) 'DO YOU WANT THE OUTPUT WRITTEN TO A FILE?'
READ(*,100) ANS
IF(ANS.EQ.'y') ANS='Y'
IF(ANS.EQ.'Y') THEN
WRITE(*,*) 'ENTER NAME OF OUTPUT FILE: '
READ(*,101) FNAME
OPEN(60,FILE=FNAME)
WRITE(60,503) SHIFT
DO 44 I=1,N
44 WRITE(60,504) I,CDF(I)
WRITE(60,505) N,N,N
WRITE(60,506) LH
WRITE(60,507) ARL,STD
CLOSE (60)
ENDIF
WRITE(*,503) SHIFT
DO 45 I=1,N
45 WRITE(*,504) I,CDF(I)
WRITE(*,505) N,N,N
WRITE(*,506) LH
WRITE(*,507) ARL,STD
100 FORMAT(A1)
101 FORMAT(A54)
499 FORMAT(' ENTER K,M,A,B FOR RULE',I3,':')
500 FORMAT(2(I4,1X))
501 FORMAT(10(F7.2))
502 FORMAT(12(1X,I4))
WRITE(*,503)'CUMULATIVE DISTRIBUTION FUNCTION','-- SHIFT ='
503 FORMAT(F5.2)
504 FORMAT(5X,'P[N<=',I2,'] =',F17.15)
C O=P[N<=+N]=P[N<=] + L*P[N=]*[1-L**N]/[1-L]
505 FORMAT(/16X,'.',/5X,'P[N<=',A2,'+N]=P[N<=',A2,']+L*P[N=',A2,
& ']*[1-L**N]/[1-L],',A10)
506 FORMAT(/5X,'WHERE N = 1,2,3, ... AND L=',F17.15,'.')
507 FORMAT(/5X,'ARL = ',F8.2/5X,'STD = ',F8.2)
STOP
END
 
Oh Hell,

does it get into fashion to have progs of a couple of hundred lines of code in here and ask other guys to do your analyzing ??? This is the third piece of code in this forum here in a very short piece of time that exceeds any decent limit. Do you really expect a stranger to do your analyzing of code for a couple of hours out of sheer kindness or what ? A thing that apparently you are not willing to do yourself ? Why should I do it ?

My recommendations

Step one: Check your compiler's documentations on what could cause a runtime error.

Step two: Check what of this could be valid for the subtraction of two array elements

Step three: Check the values of the variables involved either by using a debugger or by printing them to your screen

Step four: If your variables look strange, go back and find out where they start to look strange and why. Apply step three over and over again to find out (as all other programmers do).

Step five: After a couple of hours (in tough cases it can be days) you will have hunted down your bug and will feel like a real programmer and not like a sucker who lets other people do his job.

Sorry for being rude - but I was starting to get choking.

Norbert
 
hahaha sorry if you felt that way....
I know how it feels...
If any of you guys don't feel like helping me that's totally fine with me....
I never asked you guys to solve all the problems and I never expected anyone to solve all the problems for me...
But I never expected you to be rude....
Anyway I was just stuck and I just don't have a clue about FORTRAN and I just want some help to keep on working with it....
Anyway the advice you gave me is enough to do some work....
Could you at least tell me what's the difference between
DNML(ZB) and ZB?
I mean DNML was declared at the start of the program as double but it wasn't used till the error line which means that it's not doing anything right?
 
Check if DNML external function presents at all in your project.
If you know C++,
Code:
DOUBLE PRECISION ..., DNML
...
DOUBLE PRECISION P(10)
...
P(J)=DNML(ZB)-DNML(ZA)
[code]
is the same as
[code]
double DNMZ(double);
...
double P[10]
...
P(J)=DNML(ZB)-DNML(ZA);
Run time error message depends on your Fortran implementation, of course. For example, Silverfrost FTN95 says *** Error 29, Call to missing routine:....
Strictly speaking, it's not a run-time error: it's incomplete build.
 
Sorry, I apologise.

Wasn't the best of my days.

According to your declarations DNML is not an array but a scalar (only one value).

DNML(ZB) indicates element number ZB (should be integer) of an array DNML. As DNML is declared scalar only this is to cause an error. It is strange that you do not receive an error during the compilation - but this might depend on your compiler settings.

What DNML should be - scalar or array - I am not to know.

Norbert
 
I have to add:

There is the other possibility, which ArkM is referring to, that DNML is meant to be a function routine, to evaluate a result from the dummy variable, ZB in this case. ZB in the call must match the type declaration within the function.

As DNML is not an intrinsic function - at least it is not on my compiler - this routine should be included in your code or linked from some source on your computer. But again here, as ArkM pointed out, it is strange that you get a runtime error only. The linker should have indicated that the object DNML is missing. And some compilers would require to specify DNML as external if it was not part of the project.

Strange, strange ...

Norbert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top