diff --git a/data/combination.lisp b/data/combination.lisp
index 823959957e75ab79bdd62fea771bd71450870022..a43b3de070c5a4f2db4a1bfea797583c245676e4 100644
--- a/data/combination.lisp
+++ b/data/combination.lisp
@@ -1,6 +1,6 @@
 ;; Combinations
 ;; Liam Healy, Sun Mar 26 2006 - 11:51
-;; Time-stamp: <2008-07-06 10:11:25EDT combination.lisp>
+;; Time-stamp: <2008-07-14 23:02:03EDT combination.lisp>
 ;; $Id$
 
 (in-package :gsl)
@@ -174,23 +174,23 @@
 
 #|
 (make-tests combination
- (letm ((comb (combination 4 2 t)))	; combination-range
+ (letm ((comb (combination '(4 2) t)))	; combination-range
    (combination-range comb))
- (letm ((comb (combination 4 2 t)))	; combination-size
+ (letm ((comb (combination '(4 2) t)))	; combination-size
    (combination-size comb))
- (letm ((comb (combination 4 2 t)))	; init-first, combination-next
+ (letm ((comb (combination '(4 2) t)))	; init-first, combination-next
    (init-first comb)
-   (loop collect (data comb)
+   (loop collect (copy-seq (cl-array comb))
 	 while (combination-next comb)))
- (letm ((comb (combination 4 2 t)))  ; init-last, combination-previous
+ (letm ((comb (combination '(4 2) t)))  ; init-last, combination-previous
    (init-last comb)
-   (loop collect (data comb)
+   (loop collect (copy-seq (cl-array comb))
 	 while (combination-previous comb)))
  (loop for i from 0 to 4		; combination-next
        append
-       (letm ((comb (combination 4 i t)))
+       (letm ((comb (combination (list 4 i) t)))
 	 (init-first comb)
-	 (loop collect (data comb)
+	 (loop collect (copy-seq (cl-array comb))
 	       while (combination-next comb)))))
 |#
 
diff --git a/gsll.asd b/gsll.asd
index 07410e5bc762292043b87c6b2eb48e7048e7efa9..9ddbb7b00c1f136eb65ccff6b6177406e54c2f42 100644
--- a/gsll.asd
+++ b/gsll.asd
@@ -1,6 +1,6 @@
 ;; Definition of GSLL system 
 ;; Liam Healy
-;; Time-stamp: <2008-07-12 14:20:01EDT gsll.asd>
+;; Time-stamp: <2008-07-15 22:24:27EDT gsll.asd>
 ;; $Id$
 
 (asdf:defsystem "gsll"
@@ -75,7 +75,6 @@
 	     (:file "transport" :depends-on (return-structures))
 	     (:file "trigonometry" :depends-on (return-structures))
 	     (:file "zeta" :depends-on (return-structures))))
-   #+no
    (:file "sorting" :depends-on (init data))
    #+no
    (:module linear-algebra
diff --git a/sorting.lisp b/sorting.lisp
index e352122ade9ed4187b05737012124c87915cfbdc..31c0f2fd767e3d2428860e0f08ab142069f1fa07 100644
--- a/sorting.lisp
+++ b/sorting.lisp
@@ -1,6 +1,6 @@
 ;; Sorting
 ;; Liam Healy, Fri Apr 14 2006 - 20:20
-;; Time-stamp: <2008-03-15 22:09:56EDT sorting.lisp>
+;; Time-stamp: <2008-07-15 23:00:29EDT sorting.lisp>
 ;; $Id$
 
 (in-package :gsl)
@@ -18,7 +18,7 @@
 
 (defmfun heapsort (array count size function)
   "gsl_heapsort"
-  ((array :pointer) (count size) (size size) (function :pointer))
+  ((array :pointer) (count sizet) (size sizet) (function :pointer))
   :documentation			; FDL
   "Sort the count elements of the array of size specified
    into ascending order using the comparison
@@ -31,7 +31,7 @@
 
 (defmfun heapsort-index (p array count size function)
   "gsl_heapsort_index"
-  ((p size) (array :pointer) (count size) (size size) (function :pointer))
+  ((p sizet) (array :pointer) (count sizet) (size sizet) (function :pointer))
   :documentation			; FDL
   "Indirectly sort the count elements of the array
    array, each of size given, into ascending order using the
@@ -44,110 +44,200 @@
    array.  The array itself is not changed.")
 
 ;;;;****************************************************************************
-;;;; Vector sort
+;;;; Sorting vectors
 ;;;;****************************************************************************
 
-;;; Port only _vector_ sort functions?
+;;; The GSL vector sorting routines come in two forms, those that sort
+;;; on GSL vectors (with "vector" in the name), and those that sort on
+;;; C arrays.  From the point of view of GSLL, it makes little sense
+;;; to have both, since we can always use the C form, and if we don't
+;;; need the GSL vector, it won't be constructed.  However, it is
+;;; trivial to make both forms, so they are both defined here.
 
-(export 'sort-vector)
-(defgeneric sort-vector (vector)
-  (:documentation			; FDL
-   "Sort the elements of the vector into ascending numerical order."))
+;;; It ought to be possible to provide a stride argument, but this
+;;; gives an error:
+;;;(defmfun msort ((v vector) &optional (stride 1))
 
-(defmfun-vdsf sort-vector ((vector vector))
-  "gsl_sort_vector" (((pointer vector) gsl-vector-c))
-  :c-return :void)
+(defmfun msort ((v vector))
+  ("gsl_sort" :type)
+  (((c-pointer v) :pointer) (1 sizet) ((dim0 v) sizet))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :outputs (v)
+  :documentation			; FDL
+  "Sort the n elements of the array data with stride stride into
+   ascending numerical order.")
+
+(defmfun sort-vector ((v vector))
+  ("gsl_sort_vector" :type)
+  (((mpointer v) :pointer))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :outputs (v)
+  :documentation			; FDL
+  "Sort the elements of the vector v into ascending numerical order.")
+
+(defmfun sort-vector-index ((permutation permutation) (vector vector))
+  ("gsl_sort" :type "_index")
+  (((mpointer permutation) :pointer)
+   ((c-pointer vector) :pointer)
+   (1 sizet) ((dim0 vector) sizet))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :inputs (vector)
+  :outputs (permutation)
+  :documentation			; FDL
+  "Indirectly sort the n elements of the array vector with stride stride
+   into ascending order, storing the resulting permutation.  The latter
+   must be created with the same size as the vector.
+   The elements of permutation give the index of the
+   array element which would have been stored in that position if the
+   array had been sorted in place. The array data is not changed.")
 
-(export 'sort-vector-index)
-(defgeneric sort-vector-index (permutation vector)
-  (:documentation			; FDL
-   "Indirectly sort the elements of the vector v into
+(defmfun sort-vector-index ((permutation permutation) (vector vector))
+  ("gsl_sort_vector" :type "_index")
+  (((mpointer permutation) :pointer)
+   ((mpointer vector) :pointer))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :inputs (vector)
+  :outputs (permutation)
+  :documentation			; FDL
+  "Indirectly sort the elements of the vector v into
    ascending order, storing the resulting permutation in p.  The
    elements of p give the index of the vector element which would
    have been stored in that position if the vector had been sorted in
    place.  The first element of p gives the index of the least element
    in v and the last element of p gives the index of the
-   greatest element in v.  The vector v is not changed."))
-
-(defmfun-vdsf sort-vector-index (permutation (vector vector))
-  "gsl_sort_vector_index"
-  (((pointer permutation) gsl-permutation-c)
-   ((pointer vector) gsl-vector-c)))
-
-(export 'sort-vector-smallest)
-(defgeneric sort-vector-smallest (destination vector)
-  (:documentation			; FDL
-   "Find the smallest elements of the vector v and put them into dest,
-   which must be shorter than v."))
-
-(defmfun-vdsf sort-vector-smallest (dest (v vector))
-  "gsl_sort_vector_smallest"
-  (((gsl-array dest) :pointer) ((dim0 dest) size)
-   ((pointer v) gsl-vector-c))
+   greatest element in v.  The vector v is not changed.")
+
+;;;;****************************************************************************
+;;;; Selecting the k smallest or largest elements
+;;;;****************************************************************************
+
+(defmfun sort-vector-smallest (dest (v vector))
+  ("gsl_sort_vector" :type "_smallest")
+  (((c-pointer dest) :pointer) ((dim0 dest) sizet)
+   ((mpointer v) :pointer))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :outputs (dest)
+  :documentation			; FDL
+  "Find the smallest elements of the vector v and put them into dest,
+   which must be shorter than v.")
+
+(defmfun sort-smallest (dest (v vector))
+  ("gsl_sort" :type "_smallest")
+  (((c-pointer dest) :pointer) ((dim0 dest) sizet)
+   ((c-pointer v) :pointer))
+  :definition :generic
+  :element-types :no-complex
   :c-return :void
-  :invalidate (dest))
+  :outputs (dest)
+  :documentation			; FDL
+  "Find the smallest elements of the vector v and put them into dest,
+   which must be shorter than v.")
 
-(export 'sort-vector-smallest-index)
-(defgeneric sort-vector-smallest-index (indices vector)
-  (:documentation
-   "The indices of the smallest elements of the vector stored,
+(defmfun sort-vector-smallest-index
+    (combination (v vector))
+  ("gsl_sort_vector" :type "_smallest_index")
+  (((c-pointer combination) :pointer) ((total-size combination) sizet)
+   ((mpointer v) :pointer)
+   (1 sizet)				; stride, set to 1 for now
+   ((first (dimensions combination)) sizet))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :return (combination)
+  :documentation
+  "The indices of the smallest elements of the vector stored,
     returned as a CL vector of element type fixnum.  If
     indices is a positive initeger, a vector will be
     allocated and returned.  If it is a CL vector,
-    it will be filled with the indices."))
-
-(defmfun-vdsf sort-vector-smallest-index
-    (indices (v vector))
-  "gsl_sort_vector_smallest_index"
-  ((p (size number)) (number size) ((pointer v) :pointer))
-  :type :method
-  :global ((number (if (numberp indices) indices (length indices))))
+    it will be filled with the indices.")
+
+(defmfun sort-smallest-index
+    (combination (v vector))
+  ("gsl_sort" :type "_smallest_index")
+  (((c-pointer combination) :pointer) ((total-size combination) sizet)
+   ((c-pointer v) :pointer)
+   (1 sizet)				; stride, set to 1 for now
+   ((first (dimensions combination)) sizet))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :return (combination)
+  :documentation
+  "The indices of the smallest elements of the vector stored,
+    returned as a CL vector of element type fixnum.  If
+    indices is a positive initeger, a vector will be
+    allocated and returned.  If it is a CL vector,
+    it will be filled with the indices.")
+
+(defmfun sort-vector-largest (dest (v vector))
+  ("gsl_sort_vector" :type "_largest")
+  (((c-pointer dest) :pointer) ((dim0 dest) sizet)
+   ((mpointer v) :pointer))
+  :definition :generic
+  :element-types :no-complex
+  :c-return :void
+  :outputs (dest)
+  :documentation			; FDL
+  "Find the largest elements of the vector v and put them into dest,
+   which must be shorter than v.")
+
+(defmfun sort-largest (dest (v vector))
+  ("gsl_sort" :type "_largest")
+  (((c-pointer dest) :pointer) ((dim0 dest) sizet)
+   ((c-pointer v) :pointer))
+  :definition :generic
+  :element-types :no-complex
   :c-return :void
-  :return
-  ((let* ((vector
-	   (if (numberp indices)
-	       (make-array (list indices) :element-type 'fixnum)
-	       indices)))
-     (dotimes (i number vector)
-       (setf (aref vector i) (scref p i))))))
-
-(export 'sort-vector-largest)
-(defgeneric sort-vector-largest (dest vector)
-  (:documentation			; FDL
-  "Find the largest elements of the vector and put them into dest,
-   which must be shorter than the vector."))
-
-(defmfun-vdsf sort-vector-largest (dest (v vector))
-  "gsl_sort_vector_largest"
-  (((gsl-array dest) :pointer) ((dim0 dest) size)
-   ((pointer v) gsl-vector-c))
+  :outputs (dest)
+  :documentation			; FDL
+  "Find the largest elements of the vector v and put them into dest,
+   which must be shorter than v.")
+
+(defmfun sort-vector-largest-index
+    (combination (v vector))
+  ("gsl_sort_vector" :type "_largest_index")
+  (((c-pointer combination) :pointer) ((total-size combination) sizet)
+   ((mpointer v) :pointer)
+   (1 sizet)				; stride, set to 1 for now
+   ((first (dimensions combination)) sizet))
+  :definition :generic
+  :element-types :no-complex
   :c-return :void
-  :invalidate (dest))
-
-(export 'sort-vector-largest-index)
-;;; p should be gsl-vector-unsigned-fixnum, if that can be made to
-;;; work (see vector.lisp).
-(defgeneric sort-vector-largest-index (indices vector)
-  (:documentation		
-   "The indices of the largest elements of the vector stored,
+  :return (combination)
+  :documentation
+  "The indices of the largest elements of the vector stored,
     returned as a CL vector of element type fixnum.  If
     indices is a positive initeger, a vector will be
     allocated and returned.  If it is a CL vector,
-    it will be filled with the indices."))
+    it will be filled with the indices.")
 
-(defmfun-vdsf sort-vector-largest-index (indices (v vector))
-  "gsl_sort_vector_largest_index"
-  ((p (size number)) (number size) ((pointer v) :pointer))
-  :type :method
-  :global ((number (if (numberp indices) indices (length indices))))
+(defmfun sort-largest-index
+    (combination (v vector))
+  ("gsl_sort" :type "_largest_index")
+  (((c-pointer combination) :pointer) ((total-size combination) sizet)
+   ((c-pointer v) :pointer)
+   (1 sizet)				; stride, set to 1 for now
+   ((first (dimensions combination)) sizet))
+  :element-types :no-complex
+  :definition :generic
   :c-return :void
-  :return
-  ((let* ((vector
-	   (if (numberp indices)
-	       (make-array (list indices) :element-type 'fixnum)
-	       indices)))
-     (dotimes (i number vector)
-       (setf (aref vector i) (scref p i))))))
+  :return (combination)
+  :documentation
+  "The indices of the largest elements of the vector stored,
+    returned as a CL vector of element type fixnum.  If
+    indices is a positive initeger, a vector will be
+    allocated and returned.  If it is a CL vector,
+    it will be filled with the indices.")
 
 ;;;;****************************************************************************
 ;;;; Examples and unit test
@@ -168,6 +258,9 @@
    (data smallest))
  (letm ((vec (vector-double-float #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))))
    (sort-vector-smallest-index 3 vec))
+ (letm ((vec (vector-double-float (a 7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))
+	(sm (combination '(5 3))))
+   (sort-smallest-index sm vec))
  (letm ((vec (vector-double-float #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0)))
 	(largest (vector-double-float 3)))
    (sort-vector-largest largest vec)
@@ -177,6 +270,7 @@
 |#
 
 
+#|
 (LISP-UNIT:DEFINE-TEST SORTING
   (LISP-UNIT::ASSERT-NUMERICAL-EQUAL
    (LIST #(-3.21d0 -2.0d0 1.0d0 7.1d0 12.8d0))
@@ -216,3 +310,4 @@
    (MULTIPLE-VALUE-LIST
     (LETM ((VEC (VECTOR-DOUBLE-FLOAT #(7.1d0 -2.0d0 12.8d0 -3.21d0 1.0d0))))
       (SORT-VECTOR-LARGEST-INDEX 3 VEC)))))
+|#