Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,100 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,657 people online right now. Registration is fast and FREE... Join Now!




Sort data & binary search FORTRAN 77

 
Reply to this topicStart new topic

Sort data & binary search FORTRAN 77

juabupe
27 Nov, 2007 - 11:10 AM
Post #1

New D.I.C Head
*

Joined: 24 Nov, 2007
Posts: 1


My Contributions
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.
My code is as follows...
CODE


PROGRAM SEARCHBIO
    
      INTEGER HEIGHT, WEIGHT, I, STATUS
      CHARACTER *15, NAME
      DIMENSION NAME(10), HEIGHT(10), WEIGHT(10)

      *TO READ RECORDS FROM FILE
      OPEN (UNIT = 10, FILE = 'biometric.dat', STATUS = 'OLD')
      I = 1
READ (UNIT = 10, IOSTAT = STATUS, FMT = 100) NAME(I), HEIGHT(I),                                                    WEIGHT(I)
      
100      FORMAT (A16, 3X, I5, 3X, I5)
        
      DO WHILE (STATUS .GE. O .AND. I .LE. 10)
READ (UNIT = 10, IOSTAT = STATUS, FMT = 100) NAME(I), HEIGHT(I),    WEIGHT(I)
        I = I + 1
      END DO
      
      * TO SORT THE RECORDS READ FROM FILE
      LOOP = 1
      COUNT = 0
    
      DO WHILE (LOOP .LE. 10-COUNT)
        IF (NAME(LOOP) .GT. NAME(LOOP+1)) THEN
    * HERE I TRIED TO USE SUBROUTINE SWAP
          CALL SWAP (NAME(LOOP), NAME(LOOP+1))
          PRINT *, NAME(LOOP)
           LOOP = LOOP + 1
          COUNT = COUNT + 1
        
        END IF
      END DO
      
    END
      
      SUBROUTINE SWAP (A,B)
      
      CHARACTER A, B, TMP
      TMP = A
      A = B
      B = TMP
      
    END



I get only 1 record and it is not sorted.
What's wrong? any help is deeeeeply appreciated.

Juan
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:50PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month