×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# FORTRAN PROBLEM

## FORTRAN PROBLEM

(OP)
Hello I'm new here i just needed some help with a program i am working at. I take a specific data apply some boundary conditions and then on the results i try to sort it in ascending order. I try to print my results all the way so i can know where I'm wrong if I'm wrong. My problem is that even though my original array doesn't contain any zero elements my sorted one does and a lot of them. Any help would be appreciated. Here is the code

DO k=1,927550
count2=count2+1
END IF
END DO
write(6,*) count2
DO k=1,927550
END IF
END DO
WRITE(6,*) "THIS IS RADIUSABS UNSORTED WITH LESS ELEMENTS"

DO k=1,count2-1
DO m=k+1,count2
END IF
END DO
END DO

DO k=1,count2
END DO
write(6,*) " =sorted array"

### RE: FORTRAN PROBLEM

#### CODE

DO k=1,927550
count2=count2+1
END IF
END DO
write(6,*) count2 
And remove your second loop. Say you counted 20 non zero values. What the second loop does is it loops through the first 20 values copying the non zero values to the second array in the same index positions so you not only have zero values in the same positions, but everything beyond position 20 will retain their original value (which, in your case is probably zero).

The code for your selection sort is OK but not the most efficient way of doing it - it would be better if you only did one exchange at the end of the selection

#### CODE

DO k=1,count2-1
! To start, assume k is the lowest
low = k
DO m=k+1,count2
! Don't do exchange here - just save the index of the lowest
END DO
! Found the lowest: now do the exchange
IF (low /= k) THEN
END IF
END DO 

### RE: FORTRAN PROBLEM

(OP)
Thank you very much it worked!I've been stuck on that for weeks. Cant thank you enough

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!