Sort data & binary search FORTRAN 77

liunx

Guest
Hi, I am new at programming (very hard), anyway I am supposed to load data from an existing file (10 records) the records contain name, height, weight, into 3 arrays (I successfully did it); then sort the data first by name, then by height (I am trying to use bubble sort, and a subroutine) I haven't successfully done that; after the data is sorted, I am to implement a binary search to find all the records that are above a certain height. <br />My code is as follows...<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br /><br />PROGRAM SEARCHBIO <br />    <br />      INTEGER HEIGHT, WEIGHT, I, STATUS<br />      CHARACTER *15, NAME<br />      DIMENSION NAME(10), HEIGHT(10), WEIGHT(10)<br /><br />      *TO READ RECORDS FROM FILE<br />      OPEN (UNIT = 10, FILE = 'biometric.dat', STATUS = 'OLD')<br />      I = 1<br /> READ (UNIT = 10, IOSTAT = STATUS, FMT = 100) NAME(I), HEIGHT(I),                                                    WEIGHT(I)<br />      <br />100      FORMAT (A16, 3X, I5, 3X, I5)<br />        <br />      DO WHILE (STATUS .GE. O .AND. I .LE. 10)<br />READ (UNIT = 10, IOSTAT = STATUS, FMT = 100) NAME(I), HEIGHT(I),    WEIGHT(I) <br />        I = I + 1<br />      END DO<br />      <br />      * TO SORT THE RECORDS READ FROM FILE<br />      LOOP = 1<br />      COUNT = 0<br />    <br />      DO WHILE (LOOP .LE. 10-COUNT)<br />        IF (NAME(LOOP) .GT. NAME(LOOP+1)) THEN<br />    * HERE I TRIED TO USE SUBROUTINE SWAP<br />          CALL SWAP (NAME(LOOP), NAME(LOOP+1))<br />          PRINT *, NAME(LOOP)<br />           LOOP = LOOP + 1<br />          COUNT = COUNT + 1<br />         <br />        END IF<br />      END DO<br />      <br />    END<br />      <br />      SUBROUTINE SWAP (A,B)<br />      <br />      CHARACTER A, B, TMP<br />      TMP = A<br />      A = B<br />      B = TMP<br />      <br />    END<br /><br /><!--c2--></div><!--ec2--><br /><br />I get only 1 record and it is not sorted. <br />What's wrong? any help is deeeeeply appreciated.<br /><br />Juan
</div>
 
Back
Top