Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

qsort can't operate on loc(array), need to change to array

Status
Not open for further replies.

efoss

Technical User
Nov 27, 2005
16
US
I'm sure there is an incredibly simple answer to this, but I'm a complete beginner at Fortran and I'm having trouble figuring it out. I received code from someone that I need to implement. The code includes a step where the author uses the sortqq function in MSFLIB to sort the elements in an array:

call Sortqq (Loc(SFile),m,SRT$REAL4)

SFile is an array of real*4 numbers.

I can't use MSFLIB, but I have a library that has a sort function called qsort. So I tried to change the code to use qsort. I can sort an array of numbers, so I've pretty much got it, but I can't deal with this "Loc(SFile)". The qsort function doesn't like that - it wants just the name of an array in there. So I would try things like declaring an array (ary) and then saying

ary = Loc(SFile)

but then I get error message.



To summarize, here are three observations (m is the size of the array, 4 needs to be there because the syntax demands that you put it there if the array is made of real*4 numbers, real4_compare is a reference to a comparison function that is elsewhere in the program and that you need to make qsort work):

1. This works to sort an array (ary) of numbers:
call qsort(ary, m, 4, real4_compare)

2. This does not work:
call qsort(Loc(SFile), m, 4, real4_compare)

3. This does not work either:
ary = Loc(SFile)
call qsort(ary, m, 4, real4_compare)



I'd appreciate any suggestions.

Thanks!

Eric
 
What's it: SFile? Is it an array name? If so, pass SFile to qsort directly (w/o Loc function).
 
Wow, do I ever feel stupid! I thought that the "loc" was somehow required for the program to "locate" the array. I got rid of it and everything worked fine.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top