I have an 10 element array containing numbers, I want the start and end index in the array for which the values lie between DIST1 and DIST2. It is not working quite right. I also might want a value of 0 if I cannot find an index.
V=(/10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,100.0/)
PRINT *, V
PRINT *, DIST1, DIST2
I = 1
ISTART = 0
DO WHILE ((V(I) < DIST1).AND.(I <= 10))
ISTART = ISTART + 1
I = I + 1
END DO
I = 0
IEND = 0
DO WHILE ((V(I) <= DIST2).AND.(I <= 10))
IEND = IEND + 1
I = I + 1
END DO
IEND = IEND - 1
Add some print statements in the do while loop to show I, ISTART, and V(I)
Add a print statement after the end do as well.
You should also add a routine to make sure that V is in ascending order, and that DIST1 is not greater than DIST2
Sort an array. Univac Fortran V. I don't think that the implicit statement is still supported though, and I don't have a compiler to confirm that there are no typos in the following code.
*DIMENSION TABLE (14,500)
*FILL TABLE WITH DATA AND SORT ON COLUMNS 2,1,3
SUBROUTINE TXSORT
IMPLICIT INTEGER (A-Y)
X0=TABCTR * TABCTR IS ONE MORE THAN NUMBER OF ENTRIES IN THE TABLE.
10 X0=X0/2
IF (X0) 15,70,15
15 X1=TABCTR-X0
X2=1
20 X3=X2
30 X4=X3+X0
IF (TABLE(2,X3)-TABLE(2,X4)) 60,45,40
45 IF (TABLE(1,X3)-TABLE(1,X4)) 40,46,60
46 IF (TABLE(3,X3)-TABLE(3,X4)) 60,60,40
40 DO 50 I=1,14
X5=TABLE(I,X3)
TABLE(I,X3)=TABLE(I,X4)
TABLE(I,X4)=X5
50 CONTINUE
X3=X3-X0
IF (X3-1) 60,30,30
60 X2=X1
IF (X2-X1) 20,20,10
70 RETURN
Have written a subroutine that gives an error if values are not in ascending order. In my case, I do not sort the array. This is because should the values not be in ascending order, then there must be a problem with the data.