? Syntax1.SPS
? case.h.gcov
? diffs
? out.txt
? patch
? pspp-0.4.2.tar.gz
? pspp.list
? rank-1.patch
? rank-draft-2.patch
? rank.c.gcov
? rank.patch
? rank.q.gcov
? rank.sps
? small2e.aux
? small2e.dvi
? small2e.log
? doc/.dirstamp
? doc/pspp.dvi
? gl/Makefile
? gl/Makefile.am
? gl/Makefile.in
? gl/alloca.c
? gl/alloca.h
? gl/alloca_.h
? gl/asnprintf.c
? gl/asprintf.c
? gl/c-ctype.c
? gl/c-ctype.h
? gl/c-strtod.c
? gl/c-strtod.h
? gl/charset.alias
? gl/config.charset
? gl/doc
? gl/error.c
? gl/error.h
? gl/exit.h
? gl/exitfail.c
? gl/exitfail.h
? gl/full-read.c
? gl/full-read.h
? gl/full-write.c
? gl/full-write.h
? gl/getdelim.c
? gl/getdelim.h
? gl/gethostname.c
? gl/getline.c
? gl/getline.h
? gl/getlogin_r.c
? gl/getlogin_r.h
? gl/getopt.c
? gl/getopt1.c
? gl/getopt_.h
? gl/getopt_int.h
? gl/gettext.h
? gl/intprops.h
? gl/lbrkprop.h
? gl/linebreak.c
? gl/linebreak.h
? gl/localcharset.c
? gl/localcharset.h
? gl/mbchar.c
? gl/mbchar.h
? gl/mbuiter.h
? gl/memcasecmp.c
? gl/memcasecmp.h
? gl/memchr.c
? gl/memcmp.c
? gl/memmem.c
? gl/memmem.h
? gl/memmove.c
? gl/memset.c
? gl/minmax.h
? gl/printf-args.c
? gl/printf-args.h
? gl/printf-parse.c
? gl/printf-parse.h
? gl/progname.c
? gl/progname.h
? gl/readlink.c
? gl/ref-add.sed
? gl/ref-add.sin
? gl/ref-del.sed
? gl/ref-del.sin
? gl/safe-read.c
? gl/safe-read.h
? gl/safe-write.c
? gl/safe-write.h
? gl/size_max.h
? gl/snprintf.c
? gl/snprintf.h
? gl/stat-macros.h
? gl/stdbool_.h
? gl/stdint.h
? gl/stdint_.h
? gl/stpcpy.c
? gl/stpcpy.h
? gl/strcase.h
? gl/strcasecmp.c
? gl/strcspn.c
? gl/strerror.c
? gl/strftime.c
? gl/strftime.h
? gl/strncasecmp.c
? gl/strndup.c
? gl/strndup.h
? gl/strnlen.c
? gl/strnlen.h
? gl/strnlen1.c
? gl/strnlen1.h
? gl/strpbrk.c
? gl/strpbrk.h
? gl/strsep.c
? gl/strsep.h
? gl/strstr.c
? gl/strstr.h
? gl/strtod.c
? gl/strtok_r.c
? gl/strtok_r.h
? gl/strtol.c
? gl/strtoul.c
? gl/time_r.c
? gl/time_r.h
? gl/utf16-ucs4.h
? gl/utf8-ucs4.h
? gl/vasnprintf.c
? gl/vasnprintf.h
? gl/vasprintf.c
? gl/vasprintf.h
? gl/vsnprintf.c
? gl/vsnprintf.h
? gl/wcwidth.h
? gl/xalloc-die.c
? gl/xalloc.h
? gl/xasprintf.c
? gl/xmalloc.c
? gl/xreadlink.c
? gl/xreadlink.h
? gl/xsize.h
? gl/xstrndup.c
? gl/xstrndup.h
? gl/xvasprintf.c
? gl/xvasprintf.h
? gl/m4/absolute-header.m4
? gl/m4/alloca.m4
? gl/m4/assert.m4
? gl/m4/c-strtod.m4
? gl/m4/codeset.m4
? gl/m4/eoverflow.m4
? gl/m4/error.m4
? gl/m4/exitfail.m4
? gl/m4/extensions.m4
? gl/m4/getdelim.m4
? gl/m4/gethostname.m4
? gl/m4/getline.m4
? gl/m4/getlogin_r.m4
? gl/m4/getopt.m4
? gl/m4/gettext.m4
? gl/m4/glibc2.m4
? gl/m4/glibc21.m4
? gl/m4/gnulib-cache.m4
? gl/m4/gnulib-comp.m4
? gl/m4/gnulib-tool.m4
? gl/m4/iconv.m4
? gl/m4/intdiv0.m4
? gl/m4/intmax.m4
? gl/m4/intmax_t.m4
? gl/m4/inttypes-h.m4
? gl/m4/inttypes-pri.m4
? gl/m4/inttypes_h.m4
? gl/m4/lcmessage.m4
? gl/m4/lib-ld.m4
? gl/m4/lib-link.m4
? gl/m4/lib-prefix.m4
? gl/m4/linebreak.m4
? gl/m4/localcharset.m4
? gl/m4/lock.m4
? gl/m4/longdouble.m4
? gl/m4/longlong.m4
? gl/m4/mbchar.m4
? gl/m4/mbiter.m4
? gl/m4/mbrtowc.m4
? gl/m4/mbstate_t.m4
? gl/m4/memcasecmp.m4
? gl/m4/memchr.m4
? gl/m4/memcmp.m4
? gl/m4/memmem.m4
? gl/m4/memmove.m4
? gl/m4/memset.m4
? gl/m4/minmax.m4
? gl/m4/nls.m4
? gl/m4/onceonly_2_57.m4
? gl/m4/po.m4
? gl/m4/printf-posix.m4
? gl/m4/progtest.m4
? gl/m4/readlink.m4
? gl/m4/restrict.m4
? gl/m4/safe-read.m4
? gl/m4/safe-write.m4
? gl/m4/signed.m4
? gl/m4/size_max.m4
? gl/m4/snprintf.m4
? gl/m4/ssize_t.m4
? gl/m4/stat-macros.m4
? gl/m4/stdarg.m4
? gl/m4/stdbool.m4
? gl/m4/stdint.m4
? gl/m4/stdint_h.m4
? gl/m4/stpcpy.m4
? gl/m4/strcase.m4
? gl/m4/strcspn.m4
? gl/m4/strerror.m4
? gl/m4/strerror_r.m4
? gl/m4/strftime.m4
? gl/m4/strndup.m4
? gl/m4/strnlen.m4
? gl/m4/strpbrk.m4
? gl/m4/strsep.m4
? gl/m4/strstr.m4
? gl/m4/strtod.m4
? gl/m4/strtok_r.m4
? gl/m4/strtol.m4
? gl/m4/strtoul.m4
? gl/m4/time_r.m4
? gl/m4/tm_gmtoff.m4
? gl/m4/uintmax_t.m4
? gl/m4/ulonglong.m4
? gl/m4/unistd_h.m4
? gl/m4/utf-ucs4.m4
? gl/m4/vasnprintf.m4
? gl/m4/vasprintf.m4
? gl/m4/visibility.m4
? gl/m4/vsnprintf.m4
? gl/m4/wchar_t.m4
? gl/m4/wcwidth.m4
? gl/m4/wint_t.m4
? gl/m4/xalloc.m4
? gl/m4/xreadlink.m4
? gl/m4/xsize.m4
? gl/m4/xstrndup.m4
? gl/m4/xvasprintf.m4
? intl/ChangeLog
? intl/Makefile
? intl/Makefile.in
? intl/VERSION
? intl/bindtextdom.c
? intl/config.charset
? intl/dcgettext.c
? intl/dcigettext.c
? intl/dcngettext.c
? intl/dgettext.c
? intl/dngettext.c
? intl/eval-plural.h
? intl/explodename.c
? intl/finddomain.c
? intl/gettext.c
? intl/gettextP.h
? intl/gmo.h
? intl/hash-string.h
? intl/intl-compat.c
? intl/l10nflist.c
? intl/langprefs.c
? intl/libgnuintl.h.in
? intl/loadinfo.h
? intl/loadmsgcat.c
? intl/localcharset.c
? intl/localcharset.h
? intl/locale.alias
? intl/localealias.c
? intl/localename.c
? intl/log.c
? intl/ngettext.c
? intl/os2compat.c
? intl/os2compat.h
? intl/osdep.c
? intl/plural-exp.c
? intl/plural-exp.h
? intl/plural.c
? intl/plural.y
? intl/printf-args.c
? intl/printf-args.h
? intl/printf-parse.c
? intl/printf-parse.h
? intl/printf.c
? intl/ref-add.sin
? intl/ref-del.sin
? intl/relocatable.c
? intl/relocatable.h
? intl/textdomain.c
? intl/vasnprintf.c
? intl/vasnprintf.h
? intl/vasnwprintf.h
? intl/wprintf-parse.h
? intl/xsize.h
? lib/gsl-extras/.deps
? lib/gsl-extras/.dirstamp
? lib/gtksheet/.deps
? lib/gtksheet/.dirstamp
? lib/linreg/.deps
? lib/linreg/.dirstamp
? m4/Makefile.am
? m4/codeset.m4
? m4/gettext.m4
? m4/glibc2.m4
? m4/glibc21.m4
? m4/iconv.m4
? m4/intdiv0.m4
? m4/intmax.m4
? m4/inttypes-pri.m4
? m4/inttypes.m4
? m4/inttypes_h.m4
? m4/isc-posix.m4
? m4/lcmessage.m4
? m4/lib-ld.m4
? m4/lib-link.m4
? m4/lib-prefix.m4
? m4/longdouble.m4
? m4/longlong.m4
? m4/nls.m4
? m4/po.m4
? m4/printf-posix.m4
? m4/progtest.m4
? m4/signed.m4
? m4/size_max.m4
? m4/stdint_h.m4
? m4/uintmax_t.m4
? m4/ulonglong.m4
? m4/wchar_t.m4
? m4/wint_t.m4
? m4/xsize.m4
? po/remove-potcdate.sed
? src/data/.deps
? src/data/.dirstamp
? src/language/.deps
? src/language/.dirstamp
? src/language/control/.deps
? src/language/control/.dirstamp
? src/language/data-io/.deps
? src/language/data-io/.dirstamp
? src/language/data-io/file-handle.c
? src/language/data-io/list.c
? src/language/dictionary/.deps
? src/language/dictionary/.dirstamp
? src/language/expressions/.deps
? src/language/expressions/.dirstamp
? src/language/lexer/.deps
? src/language/lexer/.dirstamp
? src/language/lexer/q2c
? src/language/stats/.deps
? src/language/stats/.dirstamp
? src/language/stats/copy
? src/language/stats/correlations.c
? src/language/stats/crosstabs.c
? src/language/stats/examine.c
? src/language/stats/frequencies.c
? src/language/stats/means.c
? src/language/stats/oneway.c
? src/language/stats/rank.c
? src/language/stats/regression.c
? src/language/stats/src_language_stats_libstats_a-rank.gcda
? src/language/stats/src_language_stats_libstats_a-rank.gcno
? src/language/stats/t-test.c
? src/language/tests/.deps
? src/language/tests/.dirstamp
? src/language/utilities/.deps
? src/language/utilities/.dirstamp
? src/language/utilities/set.c
? src/language/xforms/.deps
? src/language/xforms/.dirstamp
? src/libpspp/.deps
? src/libpspp/.dirstamp
? src/libpspp/version.c
? src/math/.deps
? src/math/.dirstamp
? src/math/linreg/.deps
? src/math/linreg/.dirstamp
? src/math/ts/.deps
? src/math/ts/.dirstamp
? src/output/.deps
? src/output/.dirstamp
? src/output/charts/.deps
? src/output/charts/.dirstamp
? src/ui/.deps
? src/ui/.dirstamp
? src/ui/gui/.deps
? src/ui/gui/.dirstamp
? src/ui/gui/psppire
? src/ui/terminal/.deps
? src/ui/terminal/.dirstamp
? src/ui/terminal/pspp
? tests/libpspp/.deps
? tests/libpspp/.dirstamp
? tests/libpspp/ll-test
? tests/libpspp/llx-test
Index: doc/regression.texi
===================================================================
RCS file: /sources/pspp/pspp/doc/regression.texi,v
retrieving revision 1.4
diff -b -w -U3 -r1.4 regression.texi
--- doc/regression.texi	28 Apr 2006 20:07:04 -0000	1.4
+++ doc/regression.texi	26 Sep 2006 09:59:59 -0000
@@ -1,4 +1,4 @@
-@node REGRESSION, ,ONEWAY, Statistics
+@node REGRESSION, ,RANK, Statistics
 @comment  node-name,  next,  previous,  up
 @section REGRESSION
 
Index: doc/statistics.texi
===================================================================
RCS file: /sources/pspp/pspp/doc/statistics.texi,v
retrieving revision 1.9
diff -b -w -U3 -r1.9 statistics.texi
--- doc/statistics.texi	28 Apr 2006 20:07:04 -0000	1.9
+++ doc/statistics.texi	26 Sep 2006 09:59:59 -0000
@@ -14,6 +14,7 @@
 * CROSSTABS::                   Crosstabulation tables.
 * T-TEST::                      Test hypotheses about means.
 * ONEWAY::                      One way analysis of variance.
+* RANK::                        Compute rank scores.
 * REGRESSION::                  Linear regression.
 @end menu
 
@@ -600,7 +601,7 @@
 @code{WITH} are generated.
 
 
-@node ONEWAY, REGRESSION, T-TEST, Statistics
+@node ONEWAY, RANK, T-TEST, Statistics
 @comment  node-name,  next,  previous,  up
 @section ONEWAY
 
@@ -650,4 +651,68 @@
 to specify different contrast tests.
 @setfilename ignored
 
+@node RANK, REGRESSION, ONEWAY, Statistics
+@comment  node-name,  next,  previous,  up
+@section RANK
+
+@vindex RANK
+@cindex RANK
+
+@display
+RANK
+        [VARIABLES=] var_list [@{A,D@}] [BY var_list]
+        /TIES=@{MEAN,LOW,HIGH,CONDENSE@}
+        /FRACTION=@{BLOM,TUKEY,VW,RANKIT@}
+        /PRINT[=@{YES,NO@}
+        /MISSING=@{EXCLUDE,INCLUDE@}
+
+        /RANK [INTO var_list]
+        /NTILES(k) [INTO var_list]
+        /NORMAL [INTO var_list]
+        /PERCENT [INTO var_list]
+        /RFRACTION [INTO var_list]
+        /PROPORTION [INTO var_list]
+        /N [INTO var_list]
+        /SAVAGE [INTO var_list]
+@end display
+
+The @cmd{RANK} command ranks variables and stores the results into new
+variables. 
+
+The VARIABLES subcommand, which is mandatory, specifies one or
+more variables whose values are to be ranked.  
+After each variable, @samp{A} or @samp{D} may appear, indicating that
+the variable is to be ranked in ascending or descending order.
+Ascending is the default.
+If a BY keyword appears, it should be followed by a list of variables
+which are to serve as group variables.  
+In this case, the cases are gathered into groups, and ranks calculated
+for each group.
+
+The TIES subcommand specifies how tied values are to be treated.  The
+default is to take the mean value of all the tied cases.
+
+The FRACTION subcommand specifies how proportional ranks are to be
+calculated.  This only has any effect if NORMAL or PROPORTIONAL rank
+functions are requested.
+
+The PRINT subcommand may be used to specify that a summary of the rank
+variables created should appear in the output.
+
+The function subcommands are RANK, NTILES, NORMAL, PERCENT, RFRACTION,
+PROPORTION and SAVAGE.  Any number of function subcommands may appear.
+If none are given, then the default is RANK.
+The NTILES subcommand must take an integer specifying the number of
+partitions into which values should be ranked.
+Each subcommand may be followed by the INTO keyword and a list of
+variables which are the variables to be created and receive the rank
+scores.  There may be as many variables specified as there are
+variables named on the VARIABLES subcommand.  If fewer are specified,
+then the variable names are automatically created.
+
+The MISSING subcommand determines how user missing values are to be
+treated. A setting of EXCLUDE means that variables whose values are
+user-missing are to be excluded from the rank scores. A setting of
+INCLUDE means they are to be included.  The default is EXCLUDE.
+
 @include regression.texi
Index: po/de.po
===================================================================
RCS file: /sources/pspp/pspp/po/de.po,v
retrieving revision 1.12
diff -b -w -U3 -r1.12 de.po
--- po/de.po	25 Sep 2006 09:35:15 -0000	1.12
+++ po/de.po	26 Sep 2006 10:00:01 -0000
@@ -10,7 +10,7 @@
 msgstr ""
 "Project-Id-Version: PSPP 0.4.2\n"
 "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n"
-"POT-Creation-Date: 2006-09-25 16:28+0800\n"
+"POT-Creation-Date: 2006-09-25 17:51+0800\n"
 "PO-Revision-Date: 2006-05-26 17:49+0800\n"
 "Last-Translator: John Darrington <john@darrington.wattle.id.au>\n"
 "Language-Team: German <pspp-dev@gnu.org>\n"
@@ -3306,12 +3306,46 @@
 msgid "Does not assume equal"
 msgstr ""
 
-#: src/language/stats/rank.q:247
+#: src/language/stats/rank.q:174
+#, c-format
+msgid "%s of %s BY"
+msgstr ""
+
+#: src/language/stats/rank.q:182
+#, c-format
+msgid "%s of %s"
+msgstr ""
+
+#: src/language/stats/rank.q:638
+msgid "Cannot create new rank variable.  All candidates in use."
+msgstr ""
+
+#: src/language/stats/rank.q:696
+msgid "Variables Created By RANK"
+msgstr ""
+
+#: src/language/stats/rank.q:717
+#, c-format
+msgid "%s into %s(%s of %s BY %s)"
+msgstr ""
+
+#: src/language/stats/rank.q:728
+#, c-format
+msgid "%s into %s(%s of %s)"
+msgstr ""
+
+#: src/language/stats/rank.q:741
+msgid ""
+"FRACTION has been specified, but NORMAL and PROPORTION rank functions have "
+"not been requested.  The FRACTION subcommand will be ignored."
+msgstr ""
+
+#: src/language/stats/rank.q:844
 #, c-format
 msgid "Variable %s already exists."
 msgstr ""
 
-#: src/language/stats/rank.q:252
+#: src/language/stats/rank.q:849
 msgid "Too many variables in INTO clause."
 msgstr ""
 
@@ -3371,7 +3405,7 @@
 msgid "Coefficient Correlations"
 msgstr ""
 
-#: src/language/stats/regression.q:1129
+#: src/language/stats/regression.q:1131
 msgid "Dependent variable must be numeric."
 msgstr ""
 
Index: po/pspp.pot
===================================================================
RCS file: /sources/pspp/pspp/po/pspp.pot,v
retrieving revision 1.97
diff -b -w -U3 -r1.97 pspp.pot
--- po/pspp.pot	25 Sep 2006 09:35:15 -0000	1.97
+++ po/pspp.pot	26 Sep 2006 10:00:02 -0000
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n"
-"POT-Creation-Date: 2006-09-25 16:28+0800\n"
+"POT-Creation-Date: 2006-09-25 17:51+0800\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -3305,12 +3305,46 @@
 msgid "Does not assume equal"
 msgstr ""
 
-#: src/language/stats/rank.q:247
+#: src/language/stats/rank.q:174
+#, c-format
+msgid "%s of %s BY"
+msgstr ""
+
+#: src/language/stats/rank.q:182
+#, c-format
+msgid "%s of %s"
+msgstr ""
+
+#: src/language/stats/rank.q:638
+msgid "Cannot create new rank variable.  All candidates in use."
+msgstr ""
+
+#: src/language/stats/rank.q:696
+msgid "Variables Created By RANK"
+msgstr ""
+
+#: src/language/stats/rank.q:717
+#, c-format
+msgid "%s into %s(%s of %s BY %s)"
+msgstr ""
+
+#: src/language/stats/rank.q:728
+#, c-format
+msgid "%s into %s(%s of %s)"
+msgstr ""
+
+#: src/language/stats/rank.q:741
+msgid ""
+"FRACTION has been specified, but NORMAL and PROPORTION rank functions have "
+"not been requested.  The FRACTION subcommand will be ignored."
+msgstr ""
+
+#: src/language/stats/rank.q:844
 #, c-format
 msgid "Variable %s already exists."
 msgstr ""
 
-#: src/language/stats/rank.q:252
+#: src/language/stats/rank.q:849
 msgid "Too many variables in INTO clause."
 msgstr ""
 
@@ -3370,7 +3404,7 @@
 msgid "Coefficient Correlations"
 msgstr ""
 
-#: src/language/stats/regression.q:1129
+#: src/language/stats/regression.q:1131
 msgid "Dependent variable must be numeric."
 msgstr ""
 
Index: src/language/command.def
===================================================================
RCS file: /sources/pspp/pspp/src/language/command.def,v
retrieving revision 1.6
diff -b -w -U3 -r1.6 command.def
--- src/language/command.def	28 Jun 2006 18:40:21 -0000	1.6
+++ src/language/command.def	26 Sep 2006 10:00:02 -0000
@@ -109,6 +109,7 @@
 DEF_CMD (S_DATA, 0, "MODIFY VARS", cmd_modify_vars)
 DEF_CMD (S_DATA, 0, "ONEWAY", cmd_oneway)
 DEF_CMD (S_DATA, 0, "PEARSON CORRELATIONS", cmd_correlations)
+DEF_CMD (S_DATA, 0, "RANK", cmd_rank)
 DEF_CMD (S_DATA, 0, "REGRESSION", cmd_regression)
 DEF_CMD (S_DATA, 0, "RENAME VARIABLES", cmd_rename_variables)
 DEF_CMD (S_DATA, 0, "SAMPLE", cmd_sample)
@@ -177,7 +178,6 @@
 UNIMPL_CMD ("PROCEDURE OUTPUT", "Specify output file")
 UNIMPL_CMD ("PROXIMITIES", "Pairwise similarity")
 UNIMPL_CMD ("QUICK CLUSTER", "Fast clustering")
-UNIMPL_CMD ("RANK", "Create rank scores")
 UNIMPL_CMD ("RECORD TYPE", "Defines a type of record within FILE TYPE")
 UNIMPL_CMD ("REFORMAT", "Read obsolete files")
 UNIMPL_CMD ("REPEATING DATA", "Specify multiple cases per input record")
Index: src/language/stats/rank.q
===================================================================
RCS file: /sources/pspp/pspp/src/language/stats/rank.q,v
retrieving revision 1.10
diff -b -w -U3 -r1.10 rank.q
--- src/language/stats/rank.q	5 Jul 2006 05:14:31 -0000	1.10
+++ src/language/stats/rank.q	26 Sep 2006 10:00:02 -0000
@@ -1,7 +1,7 @@
 /* PSPP - RANK. -*-c-*-
 
-Copyright (C) 2005 Free Software Foundation, Inc.
-Author: John Darrington 2005
+Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+Author: John Darrington <john@darrington.wattle.id.au>
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
@@ -25,10 +25,20 @@
 #include <data/dictionary.h>
 #include <data/procedure.h>
 #include <data/variable.h>
+#include <data/case.h>
+#include <data/casefile.h>
+#include <data/fastfile.h>
+#include <data/storage-stream.h>
 #include <language/command.h>
 #include <language/stats/sort-criteria.h>
+#include <limits.h>
 #include <libpspp/compiler.h>
 #include <math/sort.h>
+#include <output/table.h>
+#include <output/manager.h>
+
+#include <gsl/gsl_cdf.h>
+#include <math.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -47,11 +57,39 @@
    +n=custom;
    +savage=custom;
    +print=print:!yes/no;
+   +fraction=fraction:!blom/tukey/vw/rankit;
+   +ties=ties:!mean/low/high/condense;
    missing=miss:!exclude/include.
 */
 /* (declarations) */
 /* (functions) */
 
+typedef double (*rank_function_t) (double c, double cc, double cc_1, 
+				 int i, double w);
+
+static double rank_proportion (double c, double cc, double cc_1, 
+			       int i, double w);
+
+static double rank_normal (double c, double cc, double cc_1, 
+			   int i, double w);
+
+static double rank_percent (double c, double cc, double cc_1, 
+			    int i, double w);
+
+static double rank_rfraction (double c, double cc, double cc_1, 
+			      int i, double w);
+
+static double rank_rank (double c, double cc, double cc_1, 
+			 int i, double w);
+
+static double rank_n (double c, double cc, double cc_1, 
+		      int i, double w);
+
+static double rank_savage (double c, double cc, double cc_1, 
+		      int i, double w);
+
+static double rank_ntiles (double c, double cc, double cc_1, 
+		      int i, double w);
 
 
 enum RANK_FUNC
@@ -64,6 +102,30 @@
     N,
     NTILES,
     SAVAGE,
+    n_RANK_FUNCS
+  };
+
+
+static const char *function_name[n_RANK_FUNCS] = {
+  "RANK",
+  "NORMAL",
+  "PERCENT",
+  "RFRACTION",
+  "PROPORTION",
+  "N",
+  "NTILES",
+  "SAVAGE"
+};
+
+static rank_function_t rank_func[n_RANK_FUNCS] = {
+  rank_rank,
+  rank_normal,
+  rank_percent,
+  rank_rfraction,
+  rank_proportion,
+  rank_n,
+  rank_ntiles,
+  rank_savage 
   };
 
 
@@ -71,7 +133,6 @@
 {
   enum RANK_FUNC rfunc;
   struct variable **destvars;
-  struct variable *srcvar;
 };
 
 
@@ -83,42 +144,635 @@
 static struct variable **group_vars;
 static size_t n_group_vars;
 
+static struct variable **src_vars;
+static size_t n_src_vars;
+
+
+static int k_ntiles;
+
 static struct cmd_rank cmd;
 
+static struct casefile *rank_sorted_casefile (struct casefile *cf, 
+					      const struct sort_criteria *, 
+					      const struct rank_spec *rs, 
+					      int n_rank_specs,
+					      int idx
+					      );
+
+
+/* Create a label on DEST_VAR, describing its derivation from SRC_VAR and F */
+static void
+create_var_label (struct variable *dest_var, 
+		  const struct variable *src_var, enum RANK_FUNC f)
+{
+  struct string label;
+  ds_init_empty (&label);
+
+  if ( n_group_vars > 0 ) 
+    {
+      struct string group_var_str;
+      int g;
+
+      ds_init_empty (&group_var_str);
+
+      for (g = 0 ; g < n_group_vars ; ++g ) 
+	{
+	  if ( g > 0 ) ds_put_cstr (&group_var_str, " ");
+	  ds_put_cstr (&group_var_str, group_vars[g]->name);
+	}
+
+      ds_put_format (&label, _("%s of %s by %s"), function_name[f], 
+		     src_var->name, ds_cstr (&group_var_str));
+      ds_destroy (&group_var_str);
+    }
+  else
+    ds_put_format (&label,_("%s of %s"), function_name[f], src_var->name);  
+
+  dest_var->label = strdup (ds_cstr (&label) );
+
+  ds_destroy (&label);
+}
+
+
+static bool 
+rank_cmd (const struct sort_criteria *sc, 
+      const struct rank_spec *rank_specs, int n_rank_specs)
+{
+  struct sort_criteria criteria;
+  bool result = true;
+  int i;
+  const int n_splits = dict_get_split_cnt (default_dict);
+
+  criteria.crit_cnt = n_splits + n_group_vars + 1;
+  criteria.crits = xnmalloc (criteria.crit_cnt, sizeof *criteria.crits);
+  for (i = 0; i < n_splits ; i++) 
+    {
+      struct variable *v = dict_get_split_vars (default_dict)[i];
+      criteria.crits[i].fv = v->fv;
+      criteria.crits[i].width = v->width;
+      criteria.crits[i].dir = SRT_ASCEND;
+    }
+  for (i = 0; i < n_group_vars; i++) 
+    {
+      criteria.crits[i + n_splits].fv = group_vars[i]->fv;
+      criteria.crits[i + n_splits].width = group_vars[i]->width;
+      criteria.crits[i + n_splits].dir = SRT_ASCEND;
+    }
+  for (i = 0 ; i < sc->crit_cnt ; ++i )
+    {
+      struct casefile *out ;
+      struct casefile *cf ; 
+      struct casereader *reader ;
+      struct casefile *sorted_cf ;
+
+      /* Obtain active file in CF. */
+      if (!procedure (NULL, NULL))
+	return false;
+      cf = proc_capture_output ();
+
+      /* Sort CF into SORTED_CF. */
+      reader = casefile_get_destructive_reader (cf) ;
+      criteria.crits[criteria.crit_cnt - 1] = sc->crits[i];
+      sorted_cf = sort_execute (reader, &criteria);
+      casefile_destroy (cf);
+
+      out = rank_sorted_casefile (sorted_cf, &criteria,
+                                  rank_specs, n_rank_specs, i)  ;
+      if ( NULL == out ) 
+	{
+	  result = false ;
+	  continue ;
+	}
+      
+      proc_set_source (storage_source_create (out));
+    }
+  free (criteria.crits);
+
+  return result ; 
+}
+
+/* Hardly a rank function !! */
+static double 
+rank_n (double c UNUSED, double cc UNUSED, double cc_1 UNUSED, 
+	  int i UNUSED, double w)
+{
+  return w;
+}
+
+
+static double 
+rank_rank (double c, double cc, double cc_1, 
+	  int i, double w UNUSED)
+{
+  double rank;
+  if ( c >= 1.0 ) 
+    {
+      switch (cmd.ties)
+	{
+	case RANK_LOW:
+	  rank = cc_1 + 1;
+	  break;
+	case RANK_HIGH:
+	  rank = cc;
+	  break;
+	case RANK_MEAN:
+	  rank = cc_1 + (c + 1.0)/ 2.0;
+	  break;
+	case RANK_CONDENSE:
+	  rank = i;
+	  break;
+	default:
+	  NOT_REACHED ();
+	}
+    }
+  else
+    {
+      switch (cmd.ties)
+	{
+	case RANK_LOW:
+	  rank = cc_1;
+	  break;
+	case RANK_HIGH:
+	  rank = cc;
+	  break;
+	case RANK_MEAN:
+	  rank = cc_1 + c / 2.0 ;
+	  break;
+	case RANK_CONDENSE:
+	  rank = i;
+	  break;
+	default:
+	  NOT_REACHED ();
+	}
+    }
+
+  return rank;
+}
+
+
+static double 
+rank_rfraction (double c, double cc, double cc_1, 
+		int i, double w)
+{
+  return rank_rank (c, cc, cc_1, i, w) / w ;
+}
+
+
+static double 
+rank_percent (double c, double cc, double cc_1, 
+		int i, double w)
+{
+  return rank_rank (c, cc, cc_1, i, w) * 100.0 / w ;
+}
+
+
+static double 
+rank_proportion (double c, double cc, double cc_1, 
+		 int i, double w)
+{
+  const double r =  rank_rank (c, cc, cc_1, i, w) ;
+
+  double f;
+  
+  switch ( cmd.fraction ) 
+    {
+    case RANK_BLOM:
+      f =  (r - 3.0/8.0) / (w + 0.25);
+      break;
+    case RANK_RANKIT:
+      f = (r - 0.5) / w ;
+      break;
+    case RANK_TUKEY:
+      f = (r - 1.0/3.0) / (w + 1.0/3.0);
+      break;
+    case RANK_VW:
+      f = r / ( w + 1.0);
+      break;
+    default:
+      NOT_REACHED ();
+    }
+
+
+  return (f > 0) ? f : SYSMIS;
+}
+
+static double 
+rank_normal (double c, double cc, double cc_1, 
+	     int i, double w)
+{
+  double f = rank_proportion (c, cc, cc_1, i, w);
+  
+  return gsl_cdf_ugaussian_Pinv (f);
+}
+
+static double 
+rank_ntiles (double c, double cc, double cc_1, 
+		int i, double w)
+{
+  double r = rank_rank (c, cc, cc_1, i, w);  
+
+
+  return ( floor (( r * k_ntiles) / ( w + 1) ) + 1);
+}
+
+/* Expected value of the order statistics from an exponential distribution */
+static double
+ee (int j, double w_star)
+{
+  int k;
+  double sum = 0.0;
+  
+  for (k = 1 ; k <= j; k++) 
+    sum += 1.0 / ( w_star + 1 - k );
+
+  return sum;
+}
+
+
+static double 
+rank_savage (double c, double cc, double cc_1, 
+		int i UNUSED, double w)
+{
+  double int_part;
+  const int i_1 = floor (cc_1);
+  const int i_2 = floor (cc);
+
+  const double w_star = (modf (w, &int_part) == 0 ) ? w : floor (w) + 1;
+
+  const double g_1 = cc_1 - i_1;
+  const double g_2 = cc - i_2;
+
+  /* The second factor is infinite, when the first is zero.
+     Therefore, evaluate the second, only when the first is non-zero */
+  const double expr1 =  (1 - g_1) ? (1 - g_1) * ee(i_1+1, w_star) : ( 1 - g_1);
+  const double expr2 =  g_2 ? g_2 * ee (i_2+1, w_star) : g_2 ;
+  
+  if ( i_1 == i_2 ) 
+    return ee (i_1 + 1, w_star) - 1;
+  
+  if ( i_1 + 1 == i_2 )
+    return ( ( expr1 + expr2 )/c ) - 1;
+
+  if ( i_1 + 2 <= i_2 ) 
+    {
+      int j;
+      double sigma = 0.0;
+      for (j = i_1 + 2 ; j <= i_2; ++j )
+	sigma += ee (j, w_star);
+      return ( (expr1 + expr2 + sigma) / c) -1;
+    }
+
+  NOT_REACHED();
+}
+
+
+/* Rank the casefile belonging to CR, starting from the current
+   postition of CR continuing up to and including the ENDth case.
+
+   RS points to an array containing  the rank specifications to
+   use. N_RANK_SPECS is the number of elements of RS.
+   W must contain the cumulative sum of all the weights in the cases.
+
+   The rank values are stored in the DEST_VAR_INDEXth variable of the
+   casefile DEST.
+   
+   Prerequisite: the casefile must be sorted according to CRITERION.
+*/
+static bool
+rank_cases (struct casereader *cr,
+	      unsigned long end,
+	      const struct sort_criterion *criterion,
+              const struct rank_spec *rs, 
+              int n_rank_specs, 
+              int dest_var_index,
+              double w,
+              struct casefile *dest)
+{
+  bool warn = true;
+  double cc = 0.0;
+  double cc_1;
+  int iter = 0;
+
+  const int fv = criterion->fv;
+  const int width = criterion->width;
+
+  printf ("new group (W=%g):\n", w);
+  while (casereader_cnum (cr) < end)
+    {
+      struct casereader *lookahead;
+      const union value *this_value;
+      struct ccase this_case, lookahead_case;
+      double c;
+      int i;
+      size_t n = 0;
+
+      if (!casereader_read_xfer (cr, &this_case))
+        break;
+      
+      this_value = case_data (&this_case, fv);
+      c = dict_get_case_weight (default_dict, &this_case, &warn);
+              
+      lookahead = casereader_clone (cr);
+      n = 0;
+      while (casereader_cnum (lookahead) < end
+             && casereader_read_xfer (lookahead, &lookahead_case))
+        {
+          const union value *lookahead_value = case_data (&lookahead_case, fv);
+          int diff = compare_values (this_value, lookahead_value, width);
+
+          if (diff != 0) 
+            {
+	      /* Make sure the casefile was sorted */
+	      assert ( diff == ((criterion->dir == SRT_ASCEND) ? -1 :1));
+
+              case_destroy (&lookahead_case);
+              break; 
+            }
+
+          c += dict_get_case_weight (default_dict, &lookahead_case, &warn);
+          case_destroy (&lookahead_case);
+          n++;
+        }
+      casereader_destroy (lookahead);
+
+      cc_1 = cc;
+      cc += c;
+      printf ("c=%g cc_1=%g cc=%g iter=%d w=%g n=%d value=%g\n",
+              c, cc_1, cc, iter, w, n, this_value->f);
+
+      do
+        {
+          for (i = 0; i < n_rank_specs; ++i) 
+            {
+              const int dest_idx = rs[i].destvars[dest_var_index]->fv;
+
+              case_data_rw (&this_case, dest_idx)->f = 
+                rank_func[rs[i].rfunc](c, cc, cc_1, iter, w);
+            }
+          casefile_append_xfer (dest, &this_case); 
+        }
+      while (n-- > 0 && casereader_read_xfer (cr, &this_case));
+
+      iter++;
+    }
+
+  /* If this isn't true, then all the results will be wrong */
+  assert ( w == cc );
+
+  return true;
+}
+
+static bool
+same_group (const struct ccase *a, const struct ccase *b,
+            const struct sort_criteria *crit)
+{
+  size_t i;
+
+  for (i = 0; i < crit->crit_cnt - 1; i++)
+    {
+      struct sort_criterion *c = &crit->crits[i];
+      if (compare_values (case_data (a, c->fv), case_data (b, c->fv),
+                          c->width) != 0)
+        return false;
+    }
+
+  return true;
+}
+
+static struct casefile *
+rank_sorted_casefile (struct casefile *cf, 
+		      const struct sort_criteria *crit, 
+		      const struct rank_spec *rs, 
+		      int n_rank_specs, 
+		      int var)
+{
+  struct casefile *dest = fastfile_create (casefile_get_value_cnt (cf));
+  struct casereader *lookahead = casefile_get_reader (cf);
+  struct casereader *pos = casereader_clone (lookahead);
+  struct ccase group_case;
+  bool warn = true;
+
+  struct sort_criterion *ultimate_crit = &crit->crits[crit->crit_cnt - 1];
+
+  if (casereader_read (lookahead, &group_case)) 
+    {
+      struct ccase this_case;
+      double w = dict_get_case_weight (default_dict, &group_case, &warn);
+
+      while (casereader_read (lookahead, &this_case)) 
+        {
+          double c = dict_get_case_weight (default_dict, &this_case, &warn);
+          if (!same_group (&group_case, &this_case, crit)) 
+            {
+              if (!rank_cases (pos, casereader_cnum (lookahead) - 1,
+                                 ultimate_crit, rs, n_rank_specs, var, w, dest))
+                goto error;
+              w = 0.0;
+              case_move (&group_case, &this_case);
+            }
+          w += c;
+        }
+      if (!rank_cases (pos, ULONG_MAX, ultimate_crit, 
+		       rs, n_rank_specs, var, w, dest))
+        goto error;
+    }
+  if (casefile_error (dest))
+    goto error;
+  
+  casefile_destroy (cf);
+  return dest;
+
+ error:
+  casefile_destroy (cf);
+  casefile_destroy (dest);
+  return NULL;
+}
+
+
+/* Transformation function to enumerate all the cases */
+static int 
+create_resort_key (void *key_var_, struct ccase *cc, casenum_t case_num)
+{
+  struct variable *key_var = key_var_;
+
+  case_data_rw(cc, key_var->fv)->f = case_num;
 
+  return TRNS_CONTINUE;
+}
+
+
+/* Create and return a new variable in which to store the ranks of SRC_VAR
+   accoring to the rank function F */
+static struct variable *
+create_rank_variable (enum RANK_FUNC f, const struct variable *src_var)
+{
+  struct variable *var; 
+  char name[SHORT_NAME_LEN + 1];
+
+  snprintf(name, SHORT_NAME_LEN + 1, "%c%s", 
+	   function_name[f][0], src_var->name);
+  
+  var = dict_create_var(default_dict, name, 0);
+
+  if ( NULL == var )
+    {
+      static int i = 1;
+      char func_abb[4];
+      snprintf(func_abb, 4, "%s", function_name[f]);
+      snprintf(name, SHORT_NAME_LEN + 1, "%s%03d", func_abb, 
+	       i);
+
+      var = dict_create_var(default_dict, name, 0);
+      if ( var ) 
+	i++;
+    }
+
+
+  if ( NULL == var )
+    {
+      static int i = 1;
+      char func_abb[3];
+      snprintf(func_abb, 3, "%s", function_name[f]);
+
+      snprintf(name, SHORT_NAME_LEN + 1, 
+	       "RNK%s%02d", func_abb, i);
+
+      var = dict_create_var(default_dict, name, 0);
+      if ( var ) 
+	i++;
+    }
+  
+  if ( NULL == var ) 
+    msg(ME, _("Cannot create new rank variable.  All candidates in use."));
+    
+
+  return var;
+}
 
 int cmd_rank(void);
 
 int
 cmd_rank(void)
 {
+  struct variable *order;
   size_t i;
   n_rank_specs = 0;
 
   if ( !parse_rank(&cmd, NULL) )
     return CMD_FAILURE;
 
-#if 1
-  for (i = 0 ; i <  sc->crit_cnt ; ++i )
+  /* Default to /RANK if no function subcommands are given */
+  if ( !( cmd.sbc_normal  || cmd.sbc_ntiles || cmd.sbc_proportion || 
+	  cmd.sbc_rfraction || cmd.sbc_savage || cmd.sbc_n || 
+	  cmd.sbc_percent || cmd.sbc_rank ) )
+    {
+      assert ( n_rank_specs == 0 );
+      
+      rank_specs = xmalloc (sizeof (*rank_specs));
+      rank_specs[0].rfunc = RANK;
+      rank_specs[0].destvars = 
+	xcalloc (sc->crit_cnt, sizeof (struct variable *));
+
+      n_rank_specs = 1;
+    }
+
+  assert ( sc->crit_cnt == n_src_vars);
+
+  /* Create variables for all rank destinations which haven't
+     already been created with INTO.
+     Add labels to all the destination variables.
+  */
+  for ( i = 0 ; i < n_rank_specs ; ++i ) 
+    {
+      int v;
+      for ( v = 0 ; v < n_src_vars ;  v ++ ) 
     {
-      struct sort_criterion *crit = &sc->crits[i];
+	  if ( rank_specs[i].destvars[v] == NULL ) 
+	    rank_specs[i].destvars[v] = 
+	      create_rank_variable (rank_specs[i].rfunc, src_vars[v]);
       
-      printf("Dir: %d; Index: %d\n", crit->dir, crit->fv);
+	  create_var_label ( rank_specs[i].destvars[v],
+			     src_vars[v],
+			     rank_specs[i].rfunc);
     }
+    }
+
+  if ( cmd.sbc_print )
+    {
+      int v;
 
-  for (i = 0 ; i <  n_group_vars ; ++i )
-    printf("Group var: %s\n",group_vars[0]->name);
+      tab_output_text (0, _("Variables Created By RANK"));
+      tab_output_text (0, "\n");
 
   for (i = 0 ; i <  n_rank_specs ; ++i )
     {
-      int j;
-      printf("Ranks spec %d; Func: %d\n",i, rank_specs[i].rfunc);
+	  for ( v = 0 ; v < n_src_vars ;  v ++ ) 
+	    {
+	      if ( n_group_vars > 0 )
+		{
+		  char varlist[200];
+		  int g;
       
-      for (j=0; j < sc->crit_cnt ; ++j )
-	printf("Dest var is \"%s\"\n", rank_specs[i].destvars[j]->name);
+		  strcpy (varlist, "");
+		  for ( g = 0 ; g < n_group_vars ; ++g ) 
+		    {
+		      strcat (varlist, group_vars[g]->name);
+		      if ( g < n_group_vars - 1)
+			strcat (varlist, " ");
     }
-#endif 
 
+		  tab_output_text (TAT_PRINTF,
+				   _("%s into %s(%s of %s BY %s)"), 
+				   src_vars[v]->name,
+				   rank_specs[i].destvars[v]->name,
+				   function_name[rank_specs[i].rfunc],
+				   src_vars[v]->name,
+				   varlist
+				   );
+		}
+	      else
+		{
+		  tab_output_text (TAT_PRINTF,
+				  _("%s into %s(%s of %s)"), 
+				  src_vars[v]->name,
+				  rank_specs[i].destvars[v]->name,
+				  function_name[rank_specs[i].rfunc],
+				  src_vars[v]->name
+				  );
+		}
+	    }
+	}
+    }
+
+  if ( cmd.sbc_fraction && 
+       ( ! cmd.sbc_normal && ! cmd.sbc_proportion) )
+    msg(MW, _("FRACTION has been specified, but NORMAL and PROPORTION rank functions have not been requested.  The FRACTION subcommand will be ignored.") );
+
+  /* Add a variable which we can sort by to get back the original
+     order */
+  order = dict_create_var_assert (default_dict, "$ORDER_", 0);
+
+  add_transformation (create_resort_key, 0, order);
+
+  /* Do the ranking */
+  rank_cmd (sc, rank_specs, n_rank_specs);
+
+  /* Put the active file back in its original order */
+  {
+    struct sort_criteria criteria;
+    struct sort_criterion restore_criterion ;
+    restore_criterion.fv = order->fv;
+    restore_criterion.width = 0;
+    restore_criterion.dir = SRT_ASCEND;
+
+    criteria.crits = &restore_criterion;
+    criteria.crit_cnt = 1;
+    
+    sort_active_file_in_place (&criteria);
+  }
+
+  /* ... and we don't need our sort key anymore. So delete it */
+  dict_delete_var (default_dict, order);
 
   free(group_vars);
   
@@ -149,7 +803,8 @@
       && token != T_ALL)
       return 2;
 
-  sc = sort_parse_criteria (default_dict, 0, 0, 0, terminators);
+  sc = sort_parse_criteria (default_dict, 
+			    &src_vars, &n_src_vars, 0, terminators);
 
   if ( lex_match(T_BY)  )
     {
@@ -170,57 +825,6 @@
 }
 
 
-/* Return a name for a new variable which ranks the variable VAR_NAME,
-   according to the ranking function F.
-   If IDX is non zero, then IDX is used as a disambiguating number.
-   FIXME: This is not very robust.
-*/
-static char *
-new_variable_name(const char *ranked_var_name, enum RANK_FUNC f, int idx)
-{
-  static char new_name[SHORT_NAME_LEN + 1];
-  char temp[SHORT_NAME_LEN + 1];
- 
-  if ( idx == 0 ) 
-    {
-      switch (f) 
-	{
-	case RANK:
-	case RFRACTION:
-	  strcpy(new_name,"R");
-	  break;
-
-	case NORMAL:
-	case N:
-	case NTILES:
-	  strcpy(new_name,"N");
-	  break;
-      
-	case PERCENT:
-	case PROPORTION:
-	  strcpy(new_name,"P");
-	  break;
-
-	case SAVAGE:
-	  strcpy(new_name,"S");
-	  break;
-
-	default:
-	  assert(false);
-	  break;
-	}
-  
-      strncat(new_name, ranked_var_name, 7);
-    }
-  else
-    {
-      strncpy(temp, ranked_var_name, 3);
-      snprintf(new_name, SHORT_NAME_LEN, "%s%03d", temp, idx);
-    }
-
-  return new_name;
-}
-
 /* Parse the [/rank INTO var1 var2 ... varN ] clause */
 static int
 parse_rank_function(struct cmd_rank *cmd UNUSED, enum RANK_FUNC f)
@@ -231,6 +835,7 @@
   n_rank_specs++;
   rank_specs = xnrealloc(rank_specs, n_rank_specs, sizeof *rank_specs);
   rank_specs[n_rank_specs - 1].rfunc = f;
+  rank_specs[n_rank_specs - 1].destvars = NULL;
 
   rank_specs[n_rank_specs - 1].destvars = 
 	    xcalloc (sc->crit_cnt, sizeof (struct variable *));
@@ -262,37 +867,9 @@
 	  rank_specs[n_rank_specs - 1].destvars[var_count - 1] = destvar ;
 
 	  lex_get();
-	  
 	}
     }
 
-  /* Allocate rank  variable names to all those which haven't had INTO 
-     variables assigned */
-  while (var_count < sc->crit_cnt)
-    {
-      static int idx=0;
-      struct variable *destvar ; 
-      const struct variable *v = dict_get_var(default_dict,
-					      sc->crits[var_count].fv);
-
-      char *new_name;
-      
-      do {
-	new_name = new_variable_name(v->name, f, idx);
-
-	destvar = dict_create_var (default_dict, new_name, 0);
-	if (!destvar ) 
-	  ++idx;
-
-      } while( !destvar ) ;
-
-      destvar->print = destvar->write = f8_2;
-
-      rank_specs[n_rank_specs - 1].destvars[var_count] = destvar ;
-      
-      ++var_count;
-    }
-
   return 1;
 }
 
@@ -312,7 +889,7 @@
 static int
 rank_custom_percent(struct cmd_rank *cmd, void *aux UNUSED )
 {
-  return parse_rank_function(cmd, NORMAL);
+  return parse_rank_function (cmd, PERCENT);
 }
 
 static int
@@ -347,6 +924,7 @@
     {
       if ( lex_force_int() ) 
 	{
+	  k_ntiles = lex_integer ();
 	  lex_get();
 	  lex_force_match(')');
 	}
@@ -359,4 +937,3 @@
   return parse_rank_function(cmd, NTILES);
 }
 
-
