<commit_before>#include <limits.h>
#include <iostream>
#include <fstream>
#include "pt.h"
#include "species.h"
#include "stratum.h"
#include "forest.h"
#include "location.h"
#include "ffm_io.h"
#include "layer.h"
#include "ffm_settings.h"
#include "ffm_util.h"

using namespace ffm_settings;
using std::vector;
using std::cout;
using std::endl;

void process(std::string inPath, std::ostream &outputStream) {

  std::pair<Results::OutputLevelType, int> waddaYaWant = prelimParseInputTextFile(inPath);
  Results::OutputLevelType outputLevel = waddaYaWant.first;
  int numIter = waddaYaWant.second;
  
  bool monteCarlo = (outputLevel == Results::MONTE_CARLO);
  
  if (!monteCarlo) {
    Location loc = parseInputTextFile(inPath, monteCarlo);
    outputStream << loc.printToString() << endl;
    Results res = loc.results();

    outputStream << res.printToString(outputLevel) << endl;
  }
  else {
    int counter = 0;
    bool firstTime = true;
    while (counter < numIter) {
      Location loc = parseInputTextFile(inPath, monteCarlo);
      if (loc.empty()) {
	cout << "continuing" << endl;
	continue;
      }
      Results res = loc.results();
      if (firstTime) {
	outputStream << printMonteCarloHeader(loc);
	firstTime = false;
      }
      outputStream << printMonteCarloInputs(loc);
      outputStream << printMonteCarloResults(res) << endl;
      ++counter;
    }
  }


}

int main(int argc, char *argv[]) {
  if (argc < 2) {
    cout << "usage: ffm input_file [output_file]" << endl;
    return 0;
  }

  std::string inPath = std::string(argv[1]);

  // optional output path - if not provided output is sent to console
  bool isFileOutput = false;
  std::ostream* fp = &cout;
  std::ofstream fout;
  std::string outPath = argc >= 3 ? std::string(argv[2]) : "";
  if( !outPath.empty()) {
    fout.open(outPath); 
    fp = &fout;
    isFileOutput = true;
  }

  process(inPath, *fp);
  if (!outPath.empty()) fout.close();
}

<commit_msg>Added -p command line flag to turn on echo of input parameters in the output (default is off)<commit_after>#include <limits.h>
#include <iostream>
#include <fstream>
#include "pt.h"
#include "species.h"
#include "stratum.h"
#include "forest.h"
#include "location.h"
#include "ffm_io.h"
#include "layer.h"
#include "ffm_settings.h"
#include "ffm_util.h"

using namespace ffm_settings;
using std::vector;
using std::cout;
using std::endl;

void process(std::string inPath, std::ostream &outputStream, bool paramsFlag) {

  std::pair<Results::OutputLevelType, int> waddaYaWant = prelimParseInputTextFile(inPath);
  Results::OutputLevelType outputLevel = waddaYaWant.first;
  int numIter = waddaYaWant.second;
  
  bool monteCarlo = (outputLevel == Results::MONTE_CARLO);
  
  if (!monteCarlo) {
    Location loc = parseInputTextFile(inPath, monteCarlo);

    if (paramsFlag) 
      outputStream << loc.printToString() << endl;
    
    Results res = loc.results();

    outputStream << res.printToString(outputLevel) << endl;
  }
  else {
    int counter = 0;
    bool firstTime = true;
    while (counter < numIter) {
      Location loc = parseInputTextFile(inPath, monteCarlo);
      if (loc.empty()) {
	cout << "continuing" << endl;
	continue;
      }
      Results res = loc.results();
      if (firstTime) {
	outputStream << printMonteCarloHeader(loc);
	firstTime = false;
      }
      outputStream << printMonteCarloInputs(loc);
      outputStream << printMonteCarloResults(res) << endl;
      ++counter;
    }
  }


}

int main(int argc, char *argv[]) {
  std::string usage("usage: ffm input_file [output_file] [-p]"); 

  if (argc < 2) {
    cout << usage << endl;
    return 0;
  }

  // collect the inPath and the optional outPath and flag arguments
  bool paramsFlag;
  std::string flag_str("-p");
  std::string inPath;
  std::string outPath;

  for (int i = 1; i < argc; i++) {
    std::string arg( argv[i] );

    if (arg.compare(0, flag_str.size(), flag_str) == 0)
      paramsFlag = true;
    else if (inPath.empty())
      inPath = arg;
    else if (outPath.empty())
      outPath = arg;
  }

  if (inPath.empty()) {
    cout << usage << endl;
    return 0;
  }

  std::ostream* fp = &cout;
  std::ofstream fout;
  if( !outPath.empty()) {
    fout.open(outPath); 
    fp = &fout;
  }

  process(inPath, *fp, paramsFlag);
  if (!outPath.empty()) fout.close();

  return 0;
}


{'fraction_non_alphanumeric': 0.14476717381281698, 'fraction_numerical': 0.003227293683725219, 'mean_word_length': 3.577004219409283, 'pattern_counts': {'":': 0, '<': 68, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2431085', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1496, 'n_words': 369}