forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sorting an array

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
AKS



Joined: 19 Mar 2008
Posts: 24

PostPosted: Wed Jul 01, 2020 5:25 pm    Post subject: Sorting an array Reply with quote

Would anyone know of a simple, free sort routine for Fortran 95?
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 331
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Wed Jul 01, 2020 5:36 pm    Post subject: Reply with quote

The following data sorting routines are available within FTN95:

CHSORT@ Sorts an array of characters.

DSORT@ Sorts a REAL(KIND=2) array.

ISORT@ Sorts an integer array.

RSORT@ Sorts a REAL(KIND=1) array.

See the following link for more information:-

https://silverfrost.com/ftn95-help/sort/idh_sorting_routines.aspx
Back to top
View user's profile Send private message Visit poster's website
mecej4



Joined: 31 Oct 2006
Posts: 1327

PostPosted: Wed Jul 01, 2020 5:52 pm    Post subject: Reply with quote

AKS,

Please list more detailed specifications for what you want from the sort routine. Does it have to be stable? Do you want a sort index returned? Is there an associated array to reorder? How big are the unsorted data sets? What are the types of the data to be sorted? Are there sorted runs already present in the data?
Back to top
View user's profile Send private message
AKS



Joined: 19 Mar 2008
Posts: 24

PostPosted: Wed Jul 01, 2020 10:55 pm    Post subject: Sorting an array Reply with quote

Thanks all for your response. I didn't know FTN95 had its own sort routines. I made some online searches, but musn't have used the right keywords. I have a program which has X and Y values in an array. I wanted to sort the X,Y pairs in ascending order for X and find the corresponding Y values. I found a routine on the web for sorting a single array (X) - bubble sort- and modified it to give me X sorted with the corresponding Y values. Thank everyone for your help. It's nice to know that this forum and you guys are so supportive. EJY
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1327

PostPosted: Wed Jul 01, 2020 11:23 pm    Post subject: Reply with quote

Bubble sort is simple to program, but it is among the worst in terms of performance. Insertion sort is about the same in complexity, but performs better in most cases.

Try one of the built-in sort routines that Kenneth mentioned.

If you are going to sort arrays larger than about 100 or you are going to sort many times, use mergesort. If you don't care for stability (i.e., if the order of equal items need not be preserved), use quicksort or a variant.

You can find code in many languages for the various sort algorithms at http://rosettacode.org/wiki/Category:Sorting_Algorithms .
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group