regcntsSubs.c
/* parse command line arguments and figure out what src/bkg types we have */
parse command line arguments and figure out what src/bkg types we have
parse command line arguments and figure out what src / bkg types we have
void regcntsParseArgs(int argc, char **argv,
		      Opts opts, Data src, Data bkg, Res res){
  int c;
  int args;
  char *s;
  optind = 1;
  while ((c = getopt(argc, argv, "b:c:e:gGhjmo:prstz1")) != -1){
    switch(c){
    case 'b':
      opts->bin = atof(optarg);
      break;
    case 'c':
      opts->cube = optarg;
      opts->dodata = 1;
      if( strstr(opts->cube, "all") ){
	opts->docube = 1;
      }
      break;
    case 'e':
      opts->efd = fopen(optarg, "w");
      if( opts->efd ){
	setxerrorfd(opts->efd);
      } else {
	xerror(stderr, "could not open error file for writing: %s\n", optarg);
      }
      break;
    case 'g':
      opts->dog = 1;
      break;
    case 'G':
      opts->dog = 2;
      break;
    case 'h':
      regcntsUsage(argv[0]);
      break;
    case 'j':
      opts->otype = 1;
      break;
    case 'm':
      opts->domatch = 1;
      break;
    case 'o':
      opts->fd = fopen(optarg, "w");
      if( !opts->fd ){
	xerror(stderr, "could not open output file for writing: %s\n", optarg);
      }
      break;
    case 'p':
      opts->dopixels = 1;
      break;
    case 'r':
      opts->doradang = 1;
      break;
    case 's':
      opts->dosum = 1;
      break;
    case 'z':
      opts->dozero = 1;
      break;
    case 'T':
      opts->c = '\t';
      break;
    case '1':
      opts->dodata = 1;
      break;
    }
  }
  args = argc - optind;
  if( args < 1 ){
    regcntsUsage(argv[0]);
  }
  src->name = xstrdup(argv[optind+0]);
  if( (args == 1) || !*(src->regstr = argv[optind+1]) ){
    src->regstr = "field()";
  }
  if( args >= 3 ){
    if( args == 3 ){
      bkg->name = NULL;
      bkg->regstr = argv[optind+2];
    } else {
      bkg->name = xstrdup(argv[optind+2]);
      bkg->regstr = argv[optind+3];
    }
    res->bkgval = strtod(bkg->regstr, &s);
    if( bkg->regstr && *bkg->regstr && (s == bkg->regstr) ){
      opts->bktype = BKG_ALL;
      res->bkgval = 0.0;
    } else {
      if( args == 4 ){
	regcntsUsage(argv[0]);
      }
      opts->bktype = BKG_VAL;
      bkg->regstr = NULL;
    }
  }
}
void regcntsParseArgs ( int argc , char * * argv , Opts opts , Data src , Data bkg , Res res ) { int c ; int args ; char * s ; optind = 1 ; while ( ( c = getopt ( argc , argv , " " ) ) != -1 ) { switch ( c ) { case ' ' : opts -> bin = atof ( optarg ) ; break ; case ' ' : opts -> cube = optarg ; opts -> dodata = 1 ; if ( strstr ( opts -> cube , " " ) ) { opts -> docube = 1 ; } break ; case ' ' : opts -> efd = fopen ( optarg , " " ) ; if ( opts -> efd ) { setxerrorfd ( opts -> efd ) ; } else { xerror ( stderr , " \n " , optarg ) ; } break ; case ' ' : opts -> dog = 1 ; break ; case ' ' : opts -> dog = 2 ; break ; case ' ' : regcntsUsage ( argv [ 0 ] ) ; break ; case ' ' : opts -> otype = 1 ; break ; case ' ' : opts -> domatch = 1 ; break ; case ' ' : opts -> fd = fopen ( optarg , " " ) ; if ( ! opts -> fd ) { xerror ( stderr , " \n " , optarg ) ; } break ; case ' ' : opts -> dopixels = 1 ; break ; case ' ' : opts -> doradang = 1 ; break ; case ' ' : opts -> dosum = 1 ; break ; case ' ' : opts -> dozero = 1 ; break ; case ' ' : opts -> c = ' \t ' ; break ; case ' ' : opts -> dodata = 1 ; break ; } } args = argc - optind ; if ( args < 1 ) { regcntsUsage ( argv [ 0 ] ) ; } src -> name = xstrdup ( argv [ optind + 0 ] ) ; if ( ( args == 1 ) || ! * ( src -> regstr = argv [ optind + 1 ] ) ) { src -> regstr = " " ; } if ( args >= 3 ) { if ( args == 3 ) { bkg -> name = NULL ; bkg -> regstr = argv [ optind + 2 ] ; } else { bkg -> name = xstrdup ( argv [ optind + 2 ] ) ; bkg -> regstr = argv [ optind + 3 ] ; } res -> bkgval = strtod ( bkg -> regstr , & s ) ; if ( bkg -> regstr && * bkg -> regstr && ( s == bkg -> regstr ) ) { opts -> bktype = BKG_ALL ; res -> bkgval = 0.0 ; } else { if ( args == 4 ) { regcntsUsage ( argv [ 0 ] ) ; } opts -> bktype = BKG_VAL ; bkg -> regstr = NULL ; } } }
parse command line arguments and figure out what src/bkg types we have
parse command line arguments and figure out what src / bkg types we have
/* process switch arguments */ /* check for required arguments */ /* arg 1: source file name */ /* arg 2: source region */ /* arg 3: background region */ /* check for constant numeric value -- background counts */ /* if we did not get a valid numeric constant, its a region */ /* this might get changed to "each", once we know the number of regions */ /* can't have background file and background value */