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
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