- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
UBROUTINE call_qsort
I'm having some problems with the QSORT subroutine. I have some code along the lines of the given below. The user-defined ordering function is called "compare".
SUBROUTINE call_qsort
USE IFPORT
IMPLICIT NONE
INTEGER :: nlett
CHARACTER (3), ALLOCATABLE :: templett(:)
INTEGER (kind=2), EXTERNAL :: compare
! ..
! .. External Functions ..
nlett = 10
ALLOCATE(templett(nlett))
templett = ...
CALL qsort(templett,nlett,3,compare)
…
…
END SUBROUTINE call_qsort
FUNCTION compare(a,b)
IMPLICIT NONE
INTEGER (kind=2) :: compare
CHARACTER (3) :: a, b
INTRINSIC LGT
! ..
IF (LGT(a,b)) THEN
compare = 5
ELSE IF (LGT(b,a)) THEN
compare = -5
ELSE
compare = 0
END IF
END FUNCTION compare
When I run the code I get the error
Fort: (18): Dummy character variable ‘B’ has length 3 which is greater than actual variable length 1
Does anyone have an idea of what is going wrong - have I missed something obvious?!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your compare routine is being called with a single character passed for the second argument. Offhand I don't see why that would happen but my guess is that it relates to code you omitted. Ordinarily I'd recommend using CHARACTER(*) in the dummy argument declaration of B, but you should try to figure out why it is getting only one character.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page