+int SummaryCommand::process(SAbundVector*& sabund, ofstream& outputFileHandle, ofstream& outAve, ofstream& outStd) {
+ try {
+
+ //calculator -> data -> values
+ vector< vector< vector<double> > > results; results.resize(sumCalculators.size());
+
+ outputFileHandle << sabund->getLabel();
+
+ SubSample sample;
+ for (int thisIter = 0; thisIter < iters+1; thisIter++) {
+
+ SAbundVector* thisIterSabund = sabund;
+
+ //we want the summary results for the whole dataset, then the subsampling
+ if ((thisIter > 0) && subsample) { //subsample sabund and run it
+ //copy sabund since getSample destroys it
+ RAbundVector rabund = sabund->getRAbundVector();
+ SAbundVector* newSabund = new SAbundVector();
+ *newSabund = rabund.getSAbundVector();
+
+ sample.getSample(newSabund, subsampleSize);
+ thisIterSabund = newSabund;
+ }
+
+ for(int i=0;i<sumCalculators.size();i++){
+ vector<double> data = sumCalculators[i]->getValues(thisIterSabund);
+
+ if (m->control_pressed) { return 0; }
+
+ if (thisIter == 0) {
+ outputFileHandle << '\t';
+ sumCalculators[i]->print(outputFileHandle);
+ }else {
+ //some of the calc have hci and lci need to make room for that
+ if (results[i].size() == 0) { results[i].resize(data.size()); }
+ //save results for ave and std.
+ for (int j = 0; j < data.size(); j++) {
+ if (m->control_pressed) { return 0; }
+ results[i][j].push_back(data[j]);
+ }
+ }
+ }
+
+ //cleanup memory
+ if ((thisIter > 0) && subsample) { delete thisIterSabund; }
+ }
+ outputFileHandle << endl;
+
+ if (subsample) {
+ outAve << sabund->getLabel() << '\t'; outStd << sabund->getLabel() << '\t';
+ //find ave and std for this label and output
+ //will need to modify the createGroupSummary to combine results and not mess with the .summary file.
+
+ //calcs -> values
+ vector< vector<double> > calcAverages; calcAverages.resize(sumCalculators.size());
+ for (int i = 0; i < calcAverages.size(); i++) { calcAverages[i].resize(results[i].size(), 0); }
+
+ for (int thisIter = 0; thisIter < iters; thisIter++) { //sum all groups dists for each calculator
+ for (int i = 0; i < calcAverages.size(); i++) { //initialize sums to zero.
+ for (int j = 0; j < calcAverages[i].size(); j++) {
+ calcAverages[i][j] += results[i][j][thisIter];
+ }
+ }
+ }
+
+ for (int i = 0; i < calcAverages.size(); i++) { //finds average.
+ for (int j = 0; j < calcAverages[i].size(); j++) {
+ calcAverages[i][j] /= (float) iters;
+ outAve << calcAverages[i][j] << '\t';
+ }
+ }
+
+ //find standard deviation
+ vector< vector<double> > stdDev; stdDev.resize(sumCalculators.size());
+ for (int i = 0; i < stdDev.size(); i++) { stdDev[i].resize(results[i].size(), 0); }
+
+ for (int thisIter = 0; thisIter < iters; thisIter++) { //compute the difference of each dist from the mean, and square the result of each
+ for (int i = 0; i < stdDev.size(); i++) {
+ for (int j = 0; j < stdDev[i].size(); j++) {
+ stdDev[i][j] += ((results[i][j][thisIter] - calcAverages[i][j]) * (results[i][j][thisIter] - calcAverages[i][j]));
+ }
+ }
+ }
+
+ for (int i = 0; i < stdDev.size(); i++) { //finds average.
+ for (int j = 0; j < stdDev[i].size(); j++) {
+ stdDev[i][j] /= (float) iters;
+ stdDev[i][j] = sqrt(stdDev[i][j]);
+ outStd << stdDev[i][j] << '\t';
+ }
+ }
+ outAve << endl; outStd << endl;
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SummaryCommand", "process");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************