Skip to content
Snippets Groups Projects
FilmGlsOptions.cc 4.96 KiB
Newer Older
Stephen Smith's avatar
Stephen Smith committed
/*  FilmGlsOptions.cc

    Mark Woolrich, FMRIB Image Analysis Group

    Copyright (C) 1999-2000 University of Oxford  */

Stephen Smith's avatar
Stephen Smith committed
/*  CCOPYRIGHT  */
Stephen Smith's avatar
Stephen Smith committed

#define WANT_STREAM
#define WANT_MATH

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
Stephen Smith's avatar
Stephen Smith committed
#include "FilmGlsOptions.h"
#include "utils/log.h"
Stephen Smith's avatar
Stephen Smith committed

Mark Woolrich's avatar
Mark Woolrich committed
using namespace Utilities;

namespace FILM {
Stephen Smith's avatar
Stephen Smith committed

FilmGlsOptions* FilmGlsOptions::gopt = NULL;

Mark Woolrich's avatar
Mark Woolrich committed
void FilmGlsOptions::parse_command_line(int argc, char** argv, Log& logger)
Stephen Smith's avatar
Stephen Smith committed
{
  if(argc<2){
    print_usage(argc,argv);
    exit(1);
  }
  
  int inp = 1;
  int n=1;
  string arg;
  char first;
  
  while (n<argc) {
    arg=argv[n];
Stephen Smith's avatar
Stephen Smith committed
    if (arg.size()<1) { n++; continue; }
    first = arg[0];
Mark Woolrich's avatar
Mark Woolrich committed
    if (first!='-' || inp==3) {
Stephen Smith's avatar
Stephen Smith committed
      if(inp == 1)
	gopt->inputfname = arg;
      else if(inp == 2)
Mark Woolrich's avatar
Mark Woolrich committed
	{
	  if(ac_only)
	    gopt->thresh = atof(argv[n]);
	  else
	    gopt->paradigmfname = arg;
	}
      else if(inp == 3 && !ac_only)
	gopt->thresh = atof(argv[n]);
Stephen Smith's avatar
Stephen Smith committed
      else
	{
	  cerr << "Mismatched argument " << arg << endl;
	  break;
	}
      n++;
      inp++;
      continue;
    }
    
    // put options without arguments here
    if ( arg == "-help" ) {
      print_usage(argc,argv);
      exit(0);
    } else if ( arg == "-v" ) {
      gopt->verbose = true;
      n++;
      continue;
    } else if ( arg == "-ar" ) {
      gopt->fitAutoRegressiveModel = true;
Mark Woolrich's avatar
Mark Woolrich committed
      gopt->tukey = false;
      n++;
      continue;
Mark Woolrich's avatar
Mark Woolrich committed
    } else if ( arg == "-ac" ) {
      gopt->ac_only = true;
      n++;
      continue;
Mark Woolrich's avatar
Mark Woolrich committed
    } else if ( arg == "-pava" ) {
      gopt->pava = true;
      gopt->tukey = false;
Stephen Smith's avatar
Stephen Smith committed
      n++;
      continue;
    } else if ( arg == "-sa" ) {
      gopt->smoothACEst = true;
      n++;
Mark Woolrich's avatar
Mark Woolrich committed
      continue;    
    } else if ( arg == "-noest" ) {
      gopt->noest = true;
Stephen Smith's avatar
Stephen Smith committed
      n++;
      continue;
Mark Woolrich's avatar
Mark Woolrich committed
    } else if ( arg == "-output_pwdata" ) {
      gopt->output_pwdata = true;
      n++;
      continue;
Stephen Smith's avatar
Stephen Smith committed

    if (n+1>=argc) 
      { 
	cerr << "Lacking argument to option " << arg << endl;
	break; 
      }

    // put options with 1 argument here
    if ( arg == "-ms") {
      gopt->ms = atoi(argv[n+1]);
      n+=2;
    } else if ( arg == "-sp" ) {
      gopt->susanpath = argv[n+1];      
      n+=2;
    } else if ( arg == "-rn" ) {
      gopt->datadir = argv[n+1];      
      n+=2;
Mark Woolrich's avatar
Mark Woolrich committed
    } else if ( arg == "-tukey" ) {
      gopt->tukeysize = atoi(argv[n+1]);
      gopt->tukey = true;
      n+=2;
    } else if ( arg == "-mt" ) {
      gopt->multitapersize = atoi(argv[n+1]);
      gopt->tukey = false;
      gopt->multitaper = true;
      n+=2;
    }
    else if ( arg == "-epith" ) {
      gopt->epith = atoi(argv[n+1]);      
      n+=2;
Stephen Smith's avatar
Stephen Smith committed
    } else { 
      cerr << "Unrecognised option " << arg << endl;
      n++;
    } 
  }  // while (n<argc)

Mark Woolrich's avatar
Mark Woolrich committed
  logger.makeDir(gopt->datadir);
  cout << "Log directory is: " << logger.getDir() << endl;
  for(int a = 0; a < argc; a++)
    logger.str() << argv[a] << " ";
  logger.str() << endl << "---------------------------------------------" << endl << endl;
Stephen Smith's avatar
Stephen Smith committed

  if (gopt->inputfname.size()<1) {
    print_usage(argc,argv);
    throw Exception("Input filename not found");
  }
Mark Woolrich's avatar
Mark Woolrich committed
  if (gopt->paradigmfname.size()<1 && !ac_only) {
Stephen Smith's avatar
Stephen Smith committed
    print_usage(argc,argv);
Mark Woolrich's avatar
Mark Woolrich committed
    throw Exception("Paradigm filenam needs to be specified");
Stephen Smith's avatar
Stephen Smith committed
  }
Stephen Smith's avatar
Stephen Smith committed
}

void FilmGlsOptions::print_usage(int argc, char *argv[])
{
Mark Woolrich's avatar
Mark Woolrich committed
  cout << "Usage: " << argv[0] << " [options] <groupfile> [optional:<paradigmfile>] <thresh>\n\n"
Stephen Smith's avatar
Stephen Smith committed
       << "  Available options are:\n"
       << "        -sa                                (smooths auto corr estimates)\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -sp <path>                         (susan path)\n"
Stephen Smith's avatar
Stephen Smith committed
       << "        -ms <num>                          (susan mask size)\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -epith <num>                       (set susan brightness threshold - otherwise it is estimated)\n"
Stephen Smith's avatar
Stephen Smith committed
       << "        -v                                 (outputs full data)\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -ac                                (perform autocorrelation estimation only)" 
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -ar                                (fits autoregressive model - default " 
Mark Woolrich's avatar
Mark Woolrich committed
       << "is to use tukey with M=sqrt(numvols))\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -tukey <num>                       (uses tukey window to estimate autocorr with window size num - default "
Mark Woolrich's avatar
Mark Woolrich committed
       << "is to use tukey with M=sqrt(numvols))\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -mt <num>                          (uses multitapering with slepian tapers and num is the time-bandwidth product - default " 
Mark Woolrich's avatar
Mark Woolrich committed
       << "is to use tukey with M=sqrt(numvols))\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -pava                              (estimates autocorr using PAVA - default " 
Mark Woolrich's avatar
Mark Woolrich committed
       << "is to use tukey with M=sqrt(numvols))\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -noest                             (do not estimate auto corrs)\n"
Mark Woolrich's avatar
Mark Woolrich committed
       << "        -output_pwdata                     (output prewhitened data and average design matrix)\n" 
Stephen Smith's avatar
Stephen Smith committed
       << "        -rn <dir>                          (directory name to store results in, default is "
       << gopt->datadir << ")\n"
       << "        -help\n\n";
}

#ifndef NO_NAMESPACE
}
#endif