示例#1
0
/* ------------------------------------------------------------------ */
static int parse_commandline(int argc, char **argv) {
  int  nargc , nargsused;
  char **pargv, *option ;
  DVT *dvttmp;
  float ftmp[2000];

  if (argc < 1) usage_exit();

  nargc   = argc;
  pargv = argv;
  while (nargc > 0) {

    option = pargv[0];
    if (debug) printf("%d %s\n",nargc,option);
    nargc -= 1;
    pargv += 1;

    nargsused = 0;

    if (!strcasecmp(option, "--help"))  print_help() ;
    else if (!strcasecmp(option, "--version")) print_version() ;
    else if (!strcasecmp(option, "--debug"))   debug = 1;
    else if (!strcasecmp(option, "--keepid"))  KeepSubjId = 1;

    else if (!strcmp(option, "--gdf")) {
      if (nargc < 1) argnerr(option,1);
      GDFile = pargv[0];
      fsgd0 = gdfRead(GDFile,0);
      if (fsgd0 == NULL) exit(1);
      nargsused = 1;
    } else if (!strcmp(option, "--dvt")) {
      if (nargc < 1) argnerr(option,1);
      DVTFile = pargv[0];
      dvttmp = DVTread(DVTFile);
      dvt0 = DVTtranspose(dvttmp);
      DVTfree(&dvttmp);
      nargsused = 1;
    } else if (!strcmp(option, "--classes")) {
      if (nargc < 1) argnerr(option,1);
      while (nth_is_arg(nargc, pargv,  nargsused)) {
        ClassList[nClassList] = pargv[nargsused];
        nClassList++;
        nargsused++;
      }
    } else if (!strcmp(option, "--covar")) {
      if (nargc < 1) argnerr(option,1);
      while (nth_is_arg(nargc, pargv, nargsused)) {
        CovarList[nCovarList] = pargv[nargsused];
        nCovarList++;
        nargsused++;
      }
    } else if (!strcmp(option, "--covarprune")) {
      if (nargc < 3) argnerr(option,3);
      CovarPrune[nCovarPrune].Covar = pargv[0];
      sscanf(pargv[1],"%f",&CovarPrune[nCovarPrune].Min);
      sscanf(pargv[2],"%f",&CovarPrune[nCovarPrune].Max);
      if (CovarPrune[nCovarPrune].Min > CovarPrune[nCovarPrune].Max) {
        printf("ERROR: covarprune min > max\n");
        exit(1);
      }
      nCovarPrune++;
      nargsused = 3;
    } else if (!strcmp(option, "--depvar")) {
      if (nargc < 1) argnerr(option,1);
      while (nth_is_arg(nargc, pargv, nargsused)) {
        DepVarList[nDepVarList] = pargv[nargsused];
        nDepVarList++;
        nargsused++;
      }
    } else if (!strcmp(option, "--wdepvar")) {
      if (nargc < 1) argnerr(option,1);
      while (nth_is_arg(nargc, pargv, nargsused)) {
        sscanf(pargv[nargsused],"%f",&ftmp[nwDepVar]);
        nwDepVar++;
        nargsused++;
      }
      wDepVar = (float *)calloc(sizeof(float),nwDepVar);
      memmove(wDepVar,ftmp,sizeof(float)*nwDepVar);
    } else if (!strcmp(option, "--wlms")) {
      if (nargc < 1) argnerr(option,1);
      WLMSDepVar = pargv[0];
      nargsused = 1;
    } else if (!strcmp(option, "--wclass")) {
      if (nargc < 1) argnerr(option,1);
      while (nth_is_arg(nargc, pargv, nargsused)) {
        sscanf(pargv[nargsused],"%f",&ftmp[nwClass]);
        nwClass++;
        nargsused++;
      }
      wClass = (float *)calloc(sizeof(float),nwClass);
      memmove(wClass,ftmp,sizeof(float)*nwClass);
    } else if (!strcmp(option, "--wcovar")) {
      if (nargc < 1) argnerr(option,1);
      while (nth_is_arg(nargc, pargv, nargsused)) {
        sscanf(pargv[nargsused],"%f",&ftmp[nwCovar]);
        nwCovar++;
        nargsused++;
      }
      wCovar = (float *)calloc(sizeof(float),nwCovar+1);
      memmove(&wCovar[1],ftmp,sizeof(float)*nwCovar);
      wCovar[0] = 0.0;
      //Note: the first weight is for offset
    } else if (!strcmp(option, "--testoffset")) TestOffset = 1;

    else if (!strcmp(option, "--o")) {
      if (nargc < 1) argnerr(option,1);
      OutBase = pargv[0];
      nargsused = 1;
    } else {
      fprintf(stderr,"ERROR: Option %s unknown\n",option);
      if (singledash(option))
        fprintf(stderr,"       Did you really mean -%s ?\n",option);
      exit(-1);
    }
    nargc -= nargsused;
    pargv += nargsused;
  }
  return(0);
}
示例#2
0
/* ------------------------------------------------------------------ */
static int parse_commandline(int argc, char **argv) {
  int  i, nargc , nargsused;
  char **pargv, *option ;
  char tmpstr[1000];

  if (argc < 1) usage_exit();

  nargc   = argc;
  pargv = argv;
  while (nargc > 0) {

    option = pargv[0];
    if (debug) printf("%d %s\n",nargc,option);
    nargc -= 1;
    pargv += 1;

    nargsused = 0;

    if (!strcasecmp(option, "--help"))           print_help() ;
    else if (!strcasecmp(option, "--version"))   print_version() ;
    else if (!strcasecmp(option, "--debug"))     debug = 1;
    else if (!strcasecmp(option, "--abs"))       DoAbs = 1;
    else if (!strcasecmp(option, "--nogmnnorm")) gmnnorm = 0;
    else if (!strcasecmp(option, "--rescale"))   rescale=1;
    else if (!strcasecmp(option, "--norescale")) rescale=0;
    else if (!strcasecmp(option, "--no-output")) NoOutput = 1;
    else if (!strcasecmp(option, "--fft"))       UseFFT = 1;
    else if (!strcasecmp(option, "--offset"))    AddOffset=1;
    else if (!strcasecmp(option, "--offset-mid")){
      AddOffset = 1;
      OffsetFrame = -1;
    }
    else if (!strcmp(option, "--hsc")) {
      if (nargc < 2) argnerr(option,2);
      sscanf(pargv[0],"%lf",&HSCMin);
      sscanf(pargv[1],"%lf",&HSCMax);
      DoHSC = 1;
      nargsused = 2;
    }
    else if (!strcmp(option, "--sum2")) {
      if (nargc < 1) argnerr(option,1);
      sum2file = pargv[0];
      pdfname  = "delta";
      //NoOutput = 1;
      nframes  = 1;
      nargsused = 1;
    }
    else if (!strcmp(option, "--hsynth")) {
      // eres mask DoTnorm out
      if (nargc < 3) argnerr(option,3);
      mri = MRIread(pargv[0]);
      mask = MRIread(pargv[1]);
      sscanf(pargv[2],"%d",&DoTNorm);
      mri2 = fMRIhsynth(mri, mask, DoTNorm);
      MRIwrite(mri2,pargv[3]);
      exit(0);
      nargsused = 2;
    }
    else if (!strcmp(option, "--vol") || !strcmp(option, "--o")) {
      if (nargc < 1) argnerr(option,1);
      volid = pargv[0];
      nargsused = 1;
      if (nth_is_arg(nargc, pargv, 1)) {
        volfmt = pargv[1];
        nargsused ++;
        volfmtid = checkfmt(volfmt);
      } 
    }
    else if (!strcmp(option, "--temp") || !strcmp(option, "--template")) {
      if(DoCurv){
	printf("ERROR: cannot use --temp and --curv\n");
	exit(1);
      }
      if(nargc < 1) argnerr(option,1);
      tempid = pargv[0];
      nargsused = 1;
      if (nth_is_arg(nargc, pargv, 1)) {
        tempfmt = pargv[1];
        nargsused ++;
        tempfmtid = checkfmt(tempfmt);
      } else tempfmtid = getfmtid(tempid);
    } else if (!strcmp(option, "--curv")) {
      if(tempid != NULL){
	printf("ERROR: cannot use --temp and --curv\n");
	exit(1);
      }
      if(nargc < 2) argnerr(option,2);
      subject = pargv[0];
      hemi = pargv[1];
      DoCurv = 1;
      nargsused = 2;
      sprintf(tmpstr,"%s/%s/surf/%s.thickness",getenv("SUBJECTS_DIR"),subject,hemi);
      tempid = strcpyalloc(tmpstr);
    } else if ( !strcmp(option, "--dim") ) {
      if (nargc < 4) argnerr(option,4);
      for (i=0;i<4;i++) sscanf(pargv[i],"%d",&dim[i]);
      nargsused = 4;
      dimSpeced = 1;
    } 
    else if ( !strcmp(option, "--nframes") ) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%d",&nframes);
      nargsused = 1;
    } 
    else if ( !strcmp(option, "--TR") || !strcmp(option, "--tr") ) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&TR);
      nargsused = 1;
    } 
    else if ( !strcmp(option, "--res") ) {
      if (nargc < 4) argnerr(option,4);
      for (i=0;i<4;i++) sscanf(pargv[i],"%f",&res[i]);
      nargsused = 4;
      resSpeced = 1;
    } 
    else if ( !strcmp(option, "--vox-size") ) {
      if (nargc < 3) argnerr(option,3);
      for (i=0;i<3;i++) sscanf(pargv[i],"%f",&res[i]);
      nargsused = 4;
      resSpeced = 1;
      NewVoxSizeSpeced = 1;
    } 
    else if ( !strcmp(option, "--c_ras") ) {
      if (nargc < 3) argnerr(option,3);
      for (i=0;i<3;i++) sscanf(pargv[i],"%f",&cras[i]);
      nargsused = 3;
    } 
    else if ( !strcmp(option, "--p0") ) {
      if (nargc < 3) argnerr(option,3);
      for (i=0;i<3;i++) sscanf(pargv[i],"%f",&p0[i]);
      usep0 = 1;
      nargsused = 3;
    } 
    else if ( !strcmp(option, "--cdircos") ) {
      if (nargc < 3) argnerr(option,3);
      for (i=0;i<3;i++) sscanf(pargv[i],"%f",&cdircos[i]);
      nargsused = 3;
    } else if ( !strcmp(option, "--rdircos") ) {
      if (nargc < 3) argnerr(option,3);
      for (i=0;i<3;i++) sscanf(pargv[i],"%f",&rdircos[i]);
      nargsused = 3;
    } else if ( !strcmp(option, "--sdircos") ) {
      if (nargc < 3) argnerr(option,3);
      for (i=0;i<3;i++) sscanf(pargv[i],"%f",&sdircos[i]);
      nargsused = 3;
    } else if ( !strcmp(option, "--fwhm") ) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%f",&fwhm);
      gstd = fwhm/sqrt(log(256.0));
      nargsused = 1;
    } else if (!strcmp(option, "--precision")) {
      if (nargc < 1) argnerr(option,1);
      precision = pargv[0];
      nargsused = 1;
    } else if (!strcmp(option, "--seed")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%ld",&seed);
      nargsused = 1;
    } else if (!strcmp(option, "--seedfile")) {
      if (nargc < 1) argnerr(option,1);
      seedfile = pargv[0];
      nargsused = 1;
    } else if (!strcmp(option, "--pdf")) {
      if (nargc < 1) argnerr(option,1);
      pdfname = pargv[0];
      nargsused = 1;
    } else if (!strcmp(option, "--bb")) {
      if (nargc < 6) argnerr(option,6);
      sscanf(pargv[0],"%d",&boundingbox.x);
      sscanf(pargv[1],"%d",&boundingbox.y);
      sscanf(pargv[2],"%d",&boundingbox.z);
      sscanf(pargv[3],"%d",&boundingbox.dx);
      sscanf(pargv[4],"%d",&boundingbox.dy);
      sscanf(pargv[5],"%d",&boundingbox.dz);
      pdfname = "boundingbox";
      nargsused = 6;
    }
    else if (!strcasecmp(option, "--checker"))
      pdfname = "checker";
    else if (!strcmp(option, "--dof-num")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%d",&numdof);
      nargsused = 1;
    } else if (!strcmp(option, "--val-a")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&ValueA);
      nargsused = 1;
    } else if (!strcmp(option, "--val-b")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&ValueB);
      nargsused = 1;
    } else if (!strcmp(option, "--radius")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&voxradius);
      nargsused = 1;
    } else if (!strcmp(option, "--dof-den") || !strcmp(option, "--dof")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%d",&dendof);
      nargsused = 1;
    } else if (!strcmp(option, "--gmean")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&gausmean);
      nargsused = 1;
    } else if (!strcmp(option, "--gstd")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&gausstd);
      nargsused = 1;
    } else if (!strcmp(option, "--delta-crsf")) {
      if (nargc < 4) argnerr(option,4);
      sscanf(pargv[0],"%d",&delta_crsf[0]);
      sscanf(pargv[1],"%d",&delta_crsf[1]);
      sscanf(pargv[2],"%d",&delta_crsf[2]);
      sscanf(pargv[3],"%d",&delta_crsf[3]);
      delta_crsf_speced = 1;
      nargsused = 4;
    } else if (!strcmp(option, "--delta-val")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&delta_value);
      nargsused = 1;
    } else if (!strcmp(option, "--delta-val-off")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%lf",&delta_off_value);
      nargsused = 1;
    } else if (!strcmp(option, "--spike")) {
      if (nargc < 1) argnerr(option,1);
      sscanf(pargv[0],"%d",&SpikeTP);
      nargsused = 1;
    } else {
      fprintf(stderr,"ERROR: Option %s unknown\n",option);
      if (singledash(option))
        fprintf(stderr,"       Did you really mean -%s ?\n",option);
      exit(-1);
    }
    nargc -= nargsused;
    pargv += nargsused;
  }
  return(0);
}