starlite79
Technical User
Hi,
I am trying to modify code that is using go to statements everywhere. I want to use something more standard and also easier to read, but I am giving myself a headache trying to sort this out. Here is what I have:
I started to rewrite using IF ELSE statements, but I am not sure when one if-else-if should end and another begins. Code someone offer help to get me started?
I am trying to modify code that is using go to statements everywhere. I want to use something more standard and also easier to read, but I am giving myself a headache trying to sort this out. Here is what I have:
Code:
IMPLICIT NONE
INTEGER i,igap,iex,ik,imax,ipl,j,k,l,n
DOUBLE PRECISION sv,x(n),k(n)
* dimension x(n),k(n)
igap = n
DO 1 i = 1,n
1 k(i) = i
* 5 if(igap.le.1) go to 25
IF(igap.le.1) THEN
* now sort k's (for identical values of x, if any)
j = 1
ELSE
igap = igap/2
imax = n - igap
END IF
10 iex = 0
do 20 i = 1,imax
ipl = i + igap
IF(x(i).LE.x(ipl)) GO TO 20
sv = x(i)
ik = k(i)
x(i) = x(ipl)
k(i) = k(ipl)
x(ipl) = sv
k(ipl) = ik
iex = iex + 1
20 CONTINUE
if(iex.gt.0) go to 10
go to 5
c
c now sort k's (for identical values of x, if any)
c
25 j = 1
30 if(j.ge.n) return
if(x(j).eq.x(j+1)) go to 33
j = j + 1
go to 30
c have at least two x's with the same value - see how long this is true
33 l = j
35 if(x(l).ne.x(l+1)) go to 38
l = l + 1
if(l.lt.n) go to 35
c j and l are the indices within which x(i) does not change - sort k
38 igap = l - j + 1
40 if(igap.le.1) j = l + 1
if(igap.le.1) go to 30
igap = igap/2
imax = l-j+1 - igap
45 iex = 0
do 50 i=1,imax
ipl = i + igap + j - 1
if(k(i+j-1).le.k(ipl)) go to 50
ik = k(i+j-1)
k(i+j-1) = k(ipl)
k(ipl) = ik
iex = iex + 1
50 continue
if(iex.gt.0) go to 45
go to 40
I started to rewrite using IF ELSE statements, but I am not sure when one if-else-if should end and another begins. Code someone offer help to get me started?