示例#1
0
void	get_flag(char *format, int *i, int *chars_written, va_list *list)
{
  if (is_good_flag(format[*i]))
    {
      while (is_good_flag(format[*i]))
	{
	  *chars_written += arg_handler(format, i, list);
	  *i += 1;
	}
    }
  else
    {
      if (format[*i] != '%')
	*chars_written += my_putchar('%');
      *chars_written += my_putchar(format[*i]);
    }
}
示例#2
0
int main(int argc, char **argv) {

  ArgumentHandler arg_handler(argc, argv);
  Forest* forest = 0;
  try {

    // Handle command line arguments
    if (arg_handler.processArguments() != 0) {
      return 0;
    }
    arg_handler.checkArguments();

    // Create forest object
    switch (arg_handler.treetype) {
    case TREE_CLASSIFICATION:
      if (arg_handler.probability) {
        forest = new ForestProbability;
      } else {
        forest = new ForestClassification;
      }
      break;
    case TREE_REGRESSION:
      forest = new ForestRegression;
      break;
    case TREE_SURVIVAL:
      forest = new ForestSurvival;
      break;
    case TREE_PROBABILITY:
      forest = new ForestProbability;
      break;
    }

    // Verbose output to logfile if non-verbose mode
    std::ostream* verbose_out;
    if (arg_handler.verbose) {
      verbose_out = &std::cout;
    } else {
      std::ofstream* logfile = new std::ofstream();
      logfile->open(arg_handler.outprefix + ".log");
      if (!logfile->good()) {
        throw std::runtime_error("Could not write to logfile.");
      }
      verbose_out = logfile;
    }

    // Call Ranger
    *verbose_out << "Starting Ranger." << std::endl;
    forest->initCpp(arg_handler.depvarname, arg_handler.memmode, arg_handler.file, arg_handler.mtry,
        arg_handler.outprefix, arg_handler.ntree, verbose_out, arg_handler.seed, arg_handler.nthreads,
        arg_handler.predict, arg_handler.impmeasure, arg_handler.targetpartitionsize, arg_handler.splitweights,
        arg_handler.alwayssplitvars, arg_handler.statusvarname, arg_handler.replace, arg_handler.catvars,
        arg_handler.savemem, arg_handler.splitrule);
    forest->run(true);
    if (arg_handler.write) {
      forest->saveToFile();
    }
    forest->writeOutput();
    *verbose_out << "Finished Ranger." << std::endl;

    delete forest;
  } catch (std::exception& e) {
    std::cerr << "Error: " << e.what() << " Ranger will EXIT now." << std::endl;
    delete forest;
    return -1;
  }

  return 0;
}