Index: /trunk/psLib/test/math/.cvsignore
===================================================================
--- /trunk/psLib/test/math/.cvsignore	(revision 10383)
+++ /trunk/psLib/test/math/.cvsignore	(revision 10384)
@@ -52,2 +52,3 @@
 tap_psStatsTiming
 tap_psMD5
+tap_psStats_Sample_01
Index: /trunk/psLib/test/math/Makefile.am
===================================================================
--- /trunk/psLib/test/math/Makefile.am	(revision 10383)
+++ /trunk/psLib/test/math/Makefile.am	(revision 10384)
@@ -15,5 +15,6 @@
 	tap_psMD5 \
 	tap_psSparse \
-	tap_psStatsTiming
+	tap_psStatsTiming \
+	tap_psStats_Sample_01
 
 if BUILD_TESTS
Index: /trunk/psLib/test/math/tap_psStats_Sample_01.c
===================================================================
--- /trunk/psLib/test/math/tap_psStats_Sample_01.c	(revision 10384)
+++ /trunk/psLib/test/math/tap_psStats_Sample_01.c	(revision 10384)
@@ -0,0 +1,285 @@
+#include <stdio.h>
+#include <string.h>
+#include <pslib.h>
+
+#include "tap.h"
+#include "pstap.h"
+
+// example tap lines:
+// ok(condition, "condition succeeded");
+// skip_start(condition, Nskip, "Skipping tests because of failure");
+
+static float yraw_01[] = {
+                             11, 16, 13, 17, 17, 17, 23, 14, 18, 15,
+                             16, 13, 12, 17, 19, 15, 21, 18, 18, 17,
+                             15, 20, 26, 14, 12, 13, 19, 16, 14, 21,
+                             16, 12, 18, 14, 18, 25, 20, 16, 19, 16,
+                             14, 12, 20, 13, 12, 21, 16, 18, 11, 22,
+                             16, 23, 20, 21, 54, 12, 12, 16, 17, 14,
+                             18, 21, 19, 18, 16, 19, 18, 23, 21, 20,
+                             20, 22, 15, 13, 14, 15, 19, 16, 15, 23,
+                             14, 25, 18, 16, 20, 20, 19, 16, 22, 11,
+                             19, 12, 14, 21, 19, 15, 16, 35, 20, 18,
+                             14, 13, 18, 18, 19, 23, 19, 19, 13, 288,
+                             19, 17, 17, 19, 12, 18, 15, 14, 13, 16,
+                             10, 12, 22, 15, 13, 14, 15, 22, 16, 18,
+                             13, 19, 17, 17, 17, 16, 16, 15, 15, 24,
+                             25, 45, 23, 19, 18, 23, 12, 18, 20, 11,
+                             25, 16, 15, 15, 200, 16, 13, 19, 11, 16,
+                             19, 16, 13, 14, 12, 10, 17, 20, 25, 17,
+                             14, 13, 20, 9, 17, 13, 19, 16, 27, 19,
+                             20, 16, 15, 17, 15, 18, 20, 17, 19, 13,
+                             21, 11, 20, 19, 12, 17, 23, 8, 17, 13,
+                             11, 16, 29, 16, 16, 20, 13, 19, 20, 19,
+                             18, 22, 21, 20, 15, 11, 17, 17, 15, 17,
+                             13, 16, 19, 20, 21, 20, 18, 17, 99, 14,
+                             13, 20, 16, 18, 12, 15, 21, 17, 18, 20,
+                             19, 12, 9, 24, 10, 13, 18, 16, 15, 19,
+                             13, 19, 12, 22, 22, 20, 17, 13, 14, 14,
+                             20, 10, 19, 19, 18, 20, 15, 14, 13, 20,
+                             13, 14, 17, 19, 16, 25, 17, 15, 11, 19,
+                             19, 14, 15, 15, 12, 14, 16, 13, 20, 16,
+                             10, 15, 20, 21, 19, 17, 12, 18, 17, 17,
+                             20, 14, 19, 17, 19, 7, 12, 17, 24, 18,
+                             17, 13, 14, 16, 20, 15, 10, 18, 13, 18,
+                             17, 16, 13, 13, 21, 13, 15, 11, 15, 16,
+                             18, 13, 11, 18, 13, 12, 15, 17, 16, 19,
+                             12, 14, 20, 13, 26, 16, 20, 14, 12, 18,
+                             15, 24, 14, 12, 19, 19, 12, 15, 18, 20,
+                             16, 17625, 17, 17, 14, 22, 15, 17, 19, 17,
+                             15, 16, 13, 14, 18, 16, 11, 20, 20, 14,
+                             19, 16, 11, 12, 18, 13, 8, 20, 10, 17,
+                             18, 17, 21, 16, 18, 16, 16, 22, 19, 12,
+                             15, 14, 21, 13, 16, 11, 17, 12, 19, 18,
+                             18, 15, 18, 12, 17, 24, 12, 20, 21, 14,
+                             21, 14, 21, 11, 19, 13, 22, 15, 17, 21,
+                             21, 22, 16, 14, 21, 26, 17, 21, 20, 11,
+                             12, 15, 21, 19, 19, 17, 22, 16, 17, 18,
+                             13, 12, 13, 88, 14, 14, 9, 19, 18, 12,
+                             20, 16, 16, 14, 17, 19, 19, 6, 16, 15,
+                             20, 17, 10, 19, 15, 21, 20, 9, 14, 17,
+                             10, 27, 22, 18, 11, 19, 15, 15, 19, 13,
+                             15, 24, 22, 20, 19, 14, 16, 17, 12, 15,
+                             22, 12, 18, 19, 22, 18, 23, 19, 15, 15,
+                             8, 13, 24, 15, 12, 30, 16, 18, 15, 21,
+                             18, 14, 18, 20, 17, 12, 20, 19, 12, 17,
+                             13, 18, 20, 16, 23, 12, 17, 9, 18, 13,
+                             11, 15, 14, 20, 19, 16, 12, 19, 19, 18,
+                             22, 23, 18, 23, 18, 17, 19, 22, 15, 11,
+                             17, 20, 13, 19, 18, 17, 18, 20, 13, 14,
+                             14, 10, 22, 21, 13, 19, 14, 16, 14, 17,
+                             19, 14, 14, 26, 21, 18, 20, 11, 18, 19,
+                             20, 18, 15, 15, 19, 18, 15, 17, 12, 15,
+                             20, 18, 14, 22, 12, 13, 23, 22, 17, 10,
+                             15, 19, 18, 18, 17, 16, 19, 13, 19, 23,
+                             15, 13, 10, 14, 16, 14, 17, 15, 16, 20,
+                             17, 12, 20, 11, 19, 11, 20, 9, 27, 23,
+                             17, 18, 18, 19, 20, 15, 15, 18, 13, 13,
+                             21, 15, 18, 13, 19, 23, 19, 8, 21, 19,
+                             9, 22, 15, 14, 24, 17, 19, 15, 22, 19,
+                             18, 13, 11, 18, 13, 21, 17, 12, 13, 18,
+                             11, 16, 19, 16, 19, 24, 15, 16, 17, 18,
+                             19, 17, 19, 20, 18, 14, 16, 15, 20, 13,
+                             13, 16, 10, 15, 29, 13, 22, 18, 11, 13,
+                             18, 23, 13, 11, 19, 25, 18, 17, 17, 20,
+                             16, 16, 22, 12, 20, 39, 14, 21, 19, 10,
+                             61, 18, 24, 16, 14, 20, 20, 19, 16, 18,
+                             11, 16, 16, 20, 16, 7, 16, 14, 12, 24,
+                             20, 16, 17, 15, 11, 20, 13, 12, 25, 15,
+                             13, 15, 18, 12, 6, 18, 15, 24, 11, 15,
+                             14, 12, 14, 15, 15, 17, 20, 14, 21, 17,
+                             14, 19, 22, 13, 15, 12, 17, 19, 23, 15,
+                             17, 25, 15, 14, 23, 6, 17, 9, 10, 16,
+                             17, 17, 16, 18, 26, 15, 17, 23, 14, 11,
+                             22, 19, 21, 16, 15, 21, 15, 10, 22, 14,
+                             23, 12, 16, 20, 13, 16, 11, 19, 12, 19,
+                             16, 15, 43, 18, 16, 13, 27, 12, 13, 14,
+                             18, 15, 14, 18, 19, 14, 15, 21, 15, 20,
+                             13, 21, 19, 21, 18, 21, 13, 24, 22, 14,
+                             22, 14, 17, 21, 15, 17, 14, 16, 21, 11,
+                             17, 21, 26, 9, 12, 17, 15, 13, 13, 16,
+                             25, 23, 17, 13, 20, 16, 19, 17, 18, 19,
+                             17, 17, 20, 17, 17, 15, 20, 15, 10, 13,
+                             11, 18, 9, 19, 18, 28, 18, 19, 18, 15,
+                             22, 16, 16, 17, 15, 24, 19, 16, 10, 18,
+                             16, 15, 32, 17, 15, 17, 18, 11, 25, 15,
+                             19, 11, 20, 17, 17, 20, 18, 18, 16, 22,
+                             19, 15, 22, 16, 14, 21, 14, 14, 13, 14,
+                             14, 19, 21, 18, 18, 19, 12, 13, 19, 19,
+                             19, 16, 18, 16, 13, 17, 25, 17, 18, 16,
+                             25, 25, 19, 20, 13, 23, 13, 14, 18, 18,
+                             20, 27, 15, 23, 23, 17, 25, 13, 12, 19,
+                             17, 13, 25, 18, 13, 12, 15, 18, 16, 12,
+                         };
+
+static float yraw_02[] = {
+                             428, 405, 820, 581, 629, 396, 383, 400, 631, 413,
+                             614, 379, 646, 1629, 353, 2748, 400, 654, 1242, 556,
+                             1423, 524, 7261, 1997, 697, 1389, 818, 26580, 495, 26915,
+                             320, 1242, 592, 490, 580, 651, 421, 487, 1644, 1909,
+                             2791, 551, 386, 426, 504, 995, 598, 1235, 481, 589,
+                             619, 1608, 385, 687, 1119, 463, 1803, 338, 427, 2509,
+                             503, 426, 1305, 425, 394, 1173, 772, 672, 2239, 1171,
+                             1117, 583, 1028, 1837, 2287, 413, 762, 2109, 955, 959,
+                             1682, 1682, 1555, 481, 663, 987, 415, 668, 417, 1045,
+                             2094, 464, 3437, 1566, 487, 1067, 975, 1217, 6089, 383,
+                             394, 415, 1117, 522, 673, 1567, 559, 15690, 325, 591,
+                             607, 634, 966, 293, 1178, 334, 526, 552, 994, 1852,
+                             2689, 1175, 1221, 410, 933, 1106, 1094, 7888, 461, 2142,
+                             600, 395, 1963, 663, 882, 582, 456, 715, 459, 1527,
+                             1948, 1074, 1035, 556, 519, 624, 728, 415, 735, 414,
+                             392, 586, 745, 624, 588, 912, 1550, 2030, 451, 25635,
+                             774, 395, 452, 593, 644, 1807, 442, 33256, 1916, 1804,
+                             13222, 538, 1054, 433, 2055, 832, 545, 924, 2808, 597,
+                             456, 833, 812, 780, 422, 1189, 617, 1613, 1349, 30099,
+                             561, 2128, 1225, 1100, 415, 950, 403, 34824, 496, 388,
+                             670, 372, 503, 363, 604, 405, 1239, 612, 300, 17802,
+                             1560, 1123, 380, 2398, 1156, 1007, 1795, 311, 370, 1905,
+                             845, 1298, 1711, 1962, 408, 1421, 638, 657, 2339, 2242,
+                             3202, 2687, 1478, 618, 19826, 1263, 359, 888, 346, 673,
+                             487, 500, 2167, 1441, 382, 574, 360, 859, 2557, 441,
+                             1870, 361, 524, 864, 1910, 1993, 831, 542, 815, 677,
+                             321, 1018, 655, 1076, 680, 779, 518, 19929, 429, 514,
+                             972, 946, 388, 508, 1019, 316, 17112, 640, 2896, 1328,
+                             805, 432, 345, 858, 596, 488, 2105, 427, 1761, 711,
+                             689, 1003, 454, 427, 499, 468, 922, 394, 400, 2056,
+                             431, 433, 327, 1635, 438, 462, 602, 973, 761, 363,
+                             2206, 2335, 2451, 332, 1927, 1495, 649, 1112, 1036, 1360,
+                             539, 931, 1396, 408, 332, 871, 449, 508, 368, 1213,
+                             400, 479, 402, 1787, 426, 720, 846, 869, 650, 414,
+                             413, 19125, 385, 967, 1109, 22290, 918, 1752, 567, 1766,
+                             386, 1170, 619, 1963, 743, 605, 740, 517, 623, 631,
+                             430, 776, 750, 649, 778, 922, 1194, 868, 489, 770,
+                             387, 406, 545, 563, 1633, 469, 3058, 1600, 918, 1546,
+                             1969, 1611, 806, 699, 583, 581, 803, 657, 394, 1205,
+                             388, 709, 1174, 1849, 1571, 1051, 487, 1301, 1189, 1626,
+                             578, 398, 1514, 350, 501, 535, 1079, 1743, 1426, 1074,
+                             669, 3664, 757, 517, 1027, 1097, 1264, 2322, 359, 527,
+                             664, 560, 558, 22642, 331, 896, 1470, 934, 467, 1019,
+                             727, 424, 353, 601, 1097, 832, 510, 520, 1185, 1420,
+                             363, 965, 619, 2322, 4277, 20030, 2087, 2823, 560, 19312,
+                             1973, 770, 356, 832, 2467, 342, 660, 18751, 1706, 313,
+                             1069, 2490, 1238, 1013, 1471, 3348, 760, 871, 723, 397,
+                             1104, 371, 2382, 27958, 621, 339, 465, 616, 2282, 524,
+                             601, 379, 587, 534, 1408, 1260, 717, 1709, 965, 434,
+                             611, 1344, 387, 1660, 539, 831, 401, 842, 864, 1453,
+                             1746, 468, 391, 398, 376, 932, 342, 483, 824, 384,
+                             991, 591, 443, 419, 1112, 598, 379, 549, 511, 1626,
+                             1221, 14651, 2117, 1570, 899, 1063, 994, 2198, 424, 380,
+                             2611, 3374, 533, 565, 1098, 300, 857, 1517, 720, 1785,
+                             659, 9076, 1145, 476, 1588, 729, 551, 667, 1041, 364,
+                             447, 406, 1271, 1515, 345, 343, 577, 449, 571, 1066,
+                             1161, 1251, 332, 1669, 393, 5503, 466, 481, 18535, 420,
+                             1910, 1093, 4162, 448, 660, 395, 485, 450, 520, 461,
+                             406, 2414, 1150, 714, 411, 18470, 1054, 401, 582, 318,
+                             404, 434, 517, 3252, 1714, 997, 481, 833, 504, 407,
+                             490, 1942, 439, 3112, 910, 605, 727, 1347, 954, 565,
+                             493, 551, 535, 416, 393, 629, 4489, 395, 18156, 487,
+                             504, 618, 438, 1001, 21729, 644, 1340, 390, 355, 716,
+                             911, 575, 541, 2158, 8211, 959, 1004, 1370, 335, 611,
+                             385, 1382, 788, 1135, 929, 2275, 653, 549, 549, 1980,
+                             390, 556, 765, 1185, 1038, 493, 476, 387, 1980, 3695,
+                             808, 297, 1124, 829, 378, 835, 3024, 1273, 613, 1330,
+                             473, 15685, 3112, 628, 358, 1317, 607, 2270, 538, 808,
+                             1083, 287, 1598, 617, 438, 398, 435, 464, 476, 554,
+                             519, 507, 1171, 886, 717, 545, 1698, 1063, 533, 903,
+                             464, 2416, 1608, 18915, 337, 1222, 323, 981, 408, 1482,
+                             1268, 1413, 967, 392, 1373, 19138, 1133, 867, 1661, 2124,
+                             508, 304, 503, 406, 14095, 1091, 370, 435, 1231, 764,
+                             499, 2387, 3092, 361, 530, 945, 878, 1965, 5488, 1967,
+                             1148, 484, 565, 490, 995, 1807, 733, 331, 1273, 1231,
+                             459, 14455, 1510, 555, 7084, 841, 1024, 3561, 792, 440,
+                             1821, 574, 429, 1085, 691, 791, 667, 1684, 622, 1019,
+                             1704, 1105, 899, 307, 1987, 352, 639, 416, 428, 2525,
+                             312, 888, 444, 542, 364, 327, 400, 1629, 28582, 628,
+                             332, 513, 452, 361, 967, 21400, 544, 1103, 1134, 29599,
+                             638, 16500, 1148, 572, 364, 776, 794, 1967, 447, 1015,
+                             433, 619, 417, 897, 3099, 1957, 809, 401, 442, 529,
+                             433, 350, 895, 18687, 390, 553, 565, 1259, 21421, 1340,
+                             306, 2057, 473, 338, 889, 320, 974, 620, 1074, 1048,
+                             325, 300, 1867, 415, 358, 1721, 362, 436, 435, 484,
+                             1478, 1907, 590, 2146, 7816, 583, 381, 1610, 544, 376,
+                             2144, 589, 952, 389, 1145, 483, 958, 854, 814, 588,
+                             25947, 659, 830, 1045, 408, 880, 2352, 1651, 1288, 1022,
+                             1976, 1292, 838, 411, 796, 375, 879, 2339, 1047, 945,
+                             1922, 1322, 455, 358, 677, 25142, 977, 344, 1305, 421,
+                             1119, 682, 823, 1054, 554, 485, 1732, 1980, 326, 444,
+                             1762, 738, 15028, 413, 349, 2474, 2837, 1074, 763, 1400,
+                             686, 1184, 491, 6502, 399, 2194, 384, 968, 403, 462,
+                             499, 555, 1361, 568, 1315, 3912, 514, 514, 1066, 519,
+                             1024, 1307, 1056, 402, 914, 513, 444, 347, 406, 506,
+                             442, 614, 356, 1222, 597, 1162, 515, 22060, 2408, 2930,
+                             5935, 1057, 747, 1396, 400, 1576, 1212, 8900, 318, 688,
+                             2122, 1771, 316, 758, 445, 381, 1115, 394, 2284, 1515,
+                             1877, 637, 1279, 2291,
+                         };
+
+int main (void)
+{
+    plan_tests(26);
+
+    diag("psStats Tests with sample SDSS data from RHL");
+    diag("this file does not yet define a specific test");
+    diag ("the fitted mean is currently wrong for these two data sets");
+
+    {
+        psMemId id = psMemGetId();
+
+        diag("sample 1");
+        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
+                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
+                                       PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV |
+                                       PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN |
+                                       PS_STAT_SAMPLE_STDEV);
+
+        // copy data in static array
+        int nPts = sizeof(yraw_01) / sizeof (float);
+        psVector *y = psVectorAlloc (nPts, PS_TYPE_F32);
+        for (int i = 0; i < y->n; i++) {
+            y->data.F32[i] = yraw_01[i];
+        }
+
+        psVectorStats (stats, y, NULL, NULL, 1);
+        ok (1, "fitted  mean   %f, stdev %f", stats->fittedMean,   stats->fittedStdev);
+        ok (1, "robust  median %f, stdev %f", stats->robustMedian, stats->robustStdev);
+        ok (1, "clipped mean   %f, stdev %f", stats->clippedMean,  stats->clippedStdev);
+        ok (1, "sample  mean   %f, stdev %f", stats->sampleMean,   stats->sampleStdev);
+        ok (1, "sample  median %f, stdev %f", stats->sampleMedian, stats->sampleStdev);
+
+        psFree (y);
+        psFree (stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    {
+        psMemId id = psMemGetId();
+
+        diag("sample 2");
+        psStats *stats = psStatsAlloc (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV |
+                                       PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV |
+                                       PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV |
+                                       PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_MEDIAN |
+                                       PS_STAT_SAMPLE_STDEV);
+
+        // copy data in static array
+        int nPts = sizeof(yraw_02) / sizeof (float);
+        psVector *y = psVectorAlloc (nPts, PS_TYPE_F32);
+        for (int i = 0; i < y->n; i++) {
+            y->data.F32[i] = yraw_02[i];
+        }
+
+        psVectorStats (stats, y, NULL, NULL, 1);
+        ok (1, "fitted  mean   %f, stdev %f", stats->fittedMean,   stats->fittedStdev);
+        ok (1, "robust  median %f, stdev %f", stats->robustMedian, stats->robustStdev);
+        ok (1, "clipped mean   %f, stdev %f", stats->clippedMean,  stats->clippedStdev);
+        ok (1, "sample  mean   %f, stdev %f", stats->sampleMean,   stats->sampleStdev);
+        ok (1, "sample  median %f, stdev %f", stats->sampleMedian, stats->sampleStdev);
+
+        psFree (y);
+        psFree (stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+    return exit_status();
+}
