From 15902607af7e20a76acdc98623b9f5a99751065b Mon Sep 17 00:00:00 2001
From: John Darrington <john@darrington.wattle.id.au>
Date: Mon, 16 Jan 2012 09:49:50 +0100
Subject: [PATCH] MEANS: implemented the /CELLS={ALL,NONE,DEFAULT} options and
 added a test

---
 src/language/stats/means.c    | 52 ++++++++++++++++++++++++-----
 tests/language/stats/means.at | 62 +++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 9 deletions(-)

diff --git a/src/language/stats/means.c b/src/language/stats/means.c
index 0ddadf8009..874ddda8b2 100644
--- a/src/language/stats/means.c
+++ b/src/language/stats/means.c
@@ -395,6 +395,13 @@ first_get (const struct per_var_data *pvd UNUSED,  void *stat)
   return *f;
 }
 
+enum 
+  {
+    MEANS_MEAN = 0,
+    MEANS_N,
+    MEANS_STDDEV
+  };
+
 /* Table of cell_specs */
 static const struct cell_spec cell_spec[] = {
   {N_("Mean"), "MEAN", NULL, NULL, arithmean_get},
@@ -699,17 +706,44 @@ cmd_means (struct lexer *lexer, struct dataset *ds)
 	  while (lex_token (lexer) != T_ENDCMD
 		 && lex_token (lexer) != T_SLASH)
 	    {
-	      int k;
-	      for (k = 0; k < n_C; ++k)
+	      int k = 0;
+	      if (lex_match (lexer, T_ALL))
 		{
-		  if (lex_match_id (lexer, cell_spec[k].keyword))
-		    {
-		      means.cells =
-			xrealloc (means.cells,
-				  ++means.n_cells * sizeof (*means.cells));
+		  int x;
+		  means.cells =
+		    xrealloc (means.cells,
+			      (means.n_cells += n_C) * sizeof (*means.cells));
 
-		      means.cells[means.n_cells - 1] = k;
-		      break;
+		  for (x = 0; x < n_C; ++x)
+		    means.cells[means.n_cells - (n_C - 1 - x) - 1] = x;
+		}
+	      else if (lex_match_id (lexer, "NONE"))
+		{
+		  /* Do nothing */
+		}
+	      else if (lex_match_id (lexer, "DEFAULT"))
+		{
+		  means.cells =
+		    xrealloc (means.cells,
+			      (means.n_cells += 3) * sizeof (*means.cells));
+		  
+		  means.cells[means.n_cells - 2 - 1] = MEANS_MEAN;
+		  means.cells[means.n_cells - 1 - 1] = MEANS_N;
+		  means.cells[means.n_cells - 0 - 1] = MEANS_STDDEV;
+		}
+	      else
+		{
+		  for (; k < n_C; ++k)
+		    {
+		      if (lex_match_id (lexer, cell_spec[k].keyword))
+			{
+			  means.cells =
+			    xrealloc (means.cells,
+				      ++means.n_cells * sizeof (*means.cells));
+			
+			  means.cells[means.n_cells - 1] = k;
+			  break;
+			}
 		    }
 		}
 	      if (k >= n_C)
diff --git a/tests/language/stats/means.at b/tests/language/stats/means.at
index 51d74e2eb7..a69051b1ad 100644
--- a/tests/language/stats/means.at
+++ b/tests/language/stats/means.at
@@ -263,3 +263,65 @@ y,3.0000,3.0000,3.0000
 ])
 
 AT_CLEANUP
+
+
+
+
+
+
+AT_SETUP([MEANS all/none/default])
+
+dnl Make sure that /CELLS = {ALL,NONE,DEFAULT} work properly
+AT_DATA([means-stat-keywords.sps], [dnl
+SET FORMAT=F12.2.
+SET DECIMAL=DOT.
+
+DATA LIST NOTABLE LIST /score *.
+BEGIN DATA.
+22
+22
+29
+16
+23
+END DATA.
+
+MEANS score /CELLS = ALL.
+MEANS score /CELLS = DEFAULT.
+MEANS score /CELLS = NONE.
+])
+
+
+AT_CHECK([pspp -O format=csv means-stat-keywords.sps], [0],
+  [dnl
+Table: Case Processing Summary
+,Cases,,,,,
+,Included,,Excluded,,Total,
+,N,Percent,N,Percent,N,Percent
+score: ,5,100%,0,0%,5,100%
+
+Table: Report
+,Mean,N,Std. Deviation,S.E. Mean,Sum,Min,Max,Range,Variance,Kurtosis,S.E. Kurt,Skewness,S.E. Skew,First,Last,Harmonic Mean,Geom. Mean
+score,22.40,5.00,4.62,2.06,112.00,16.00,29.00,13.00,21.30,1.85,2.00,.11,.91,22.00,23.00,21.61,22.01
+
+Table: Case Processing Summary
+,Cases,,,,,
+,Included,,Excluded,,Total,
+,N,Percent,N,Percent,N,Percent
+score: ,5,100%,0,0%,5,100%
+
+Table: Report
+,Mean,N,Std. Deviation
+score,22.40,5.00,4.62
+
+Table: Case Processing Summary
+,Cases,,,,,
+,Included,,Excluded,,Total,
+,N,Percent,N,Percent,N,Percent
+score: ,5,100%,0,0%,5,100%
+
+Table: Report
+
+score
+])
+
+AT_CLEANUP
-- 
2.30.2