Exemplo n.º 1
0
// this function parses two strings "$a;$b" and "???_???l$ch$d" where $a-$d are (real) numbers
// it is used to parse in the parameters of continues variables from the input file
density_integral parse_density_integral_string(char *input, char *variablename) {
  density_integral result;
  int i;
  char garbage[64], s1[64],s2[64],s3[64],s4[64];

  if(sscanf(input, "%64[^;];%64[^;]", s1,s2) != 2) {
    fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
    fprintf(stderr, "The string should contain 2 fields seperated by ; characters.\n");
    exit(EXIT_FAILURE);
  }

  if (IsRealNumber(s1)) {
    result.mu=atof(s1);
  } else {
    fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
    fprintf(stderr, "%s is not a number\n",s1);
    exit(EXIT_FAILURE);
  }

  if (IsRealNumber(s2)) {
    result.sigma=atof(s2);
  } else {
    fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
    fprintf(stderr, "%s is not a number\n",s2);
    exit(EXIT_FAILURE);
  }

 if (result.sigma<=0) {
    fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string",input);
    fprintf(stderr, "The value for sigma has to be larger than 0.\n");

    exit(EXIT_FAILURE);
  }

  if (sscanf(variablename,"%64[^lh]l%64[^lh]h%64[^lh]",garbage,s3,s4) != 3) {
    fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",variablename);
    fprintf(stderr, "The string should contain 2 fields seperated by ; characters.\n");
    exit(EXIT_FAILURE);
  }

  //  replace the d by . in s1 and s2
  for(i=0; s3[i]!='\0' ; i++) {
    if (s3[i]=='d') {
      s3[i]='.';
    }
    if (s3[i]=='m') {
      s3[i]='-';
    }
  }
  for(i=0; s4[i]!='\0' ; i++) {
    if (s4[i]=='d') {
      s4[i]='.';
    }
    if (s4[i]=='m') {
      s4[i]='-';
    }
  }

  if (IsRealNumber(s3)) {
    result.low=atof(s3);
  } else {
    fprintf(stderr, "Error at parsing the string %s in the function parse_density_integral_string\n",input);
    fprintf(stderr, "%s is not a number\n",s1);
    exit(EXIT_FAILURE);
  }

 if (IsRealNumber(s4)) {
    result.high=atof(s4);
  } else {
    fprintf(stderr, "Error ar parsing the string %s in the function parse_density_integral_string\n",input);
    fprintf(stderr, "%s is not a number\n",s1);
    exit(EXIT_FAILURE);
  }

  
  if (result.low>result.high) {
    fprintf(stderr, "Error ar parsing the string %s in the function parse_density_integral_string\n",input);
    fprintf(stderr, "The value for low has to be larger than then value for high.\n");
    exit(EXIT_FAILURE);
  }


  return result;
}
Exemplo n.º 2
0
parameters loadparam(int argc, char **arg) {
  int i;
  parameters params;
  params.loadfile = -1;
  params.savedfile = -1;
  params.exportfile = -1;
  params.method = 0;
  params.inputfile = -1;
  params.debug = 0;
  params.errorcnt = 0;
  params.queryid = 0;
  params.timeout = 0;
  params.sigmoid_slope = 1.0;
  params.online = 0;
  params.maxbufsize = 0;
  params.ppid = NULL;
  params.error = (int *)malloc(argc * sizeof(int));
  for (i = 1; i < argc; i++) {
    switch (argtype(arg[i])) {
    case 0:
      if (argc > i + 1) {
        i++;
        params.loadfile = i;
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 2:
      if (argc > i + 1) {
        i++;
        params.exportfile = i;
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 3:
      if (argc > i + 1) {
        i++;
        params.method = i;
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 4:
      if (argc > i + 1) {
        i++;
        params.inputfile = i;
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 5:
      printhelp(argc, arg);
      break;
    case 6:
      params.debug = 1;
      break;
    case 7:
      if (argc > i + 1) {
        i++;
        params.queryid = i;
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 8:
      if ((argc > i + 1) && (IsPosNumber(arg[i + 1]))) {
        i++;
        params.timeout = atoi(arg[i]);
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 9:
      if (argc > i + 1) {
        i++;
        params.savedfile = i;
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 10:
      if ((argc > i + 1) && (IsRealNumber(arg[i + 1]))) {
        i++;
        params.sigmoid_slope = atof(arg[i]);
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 11:
      params.online = 1;
      break;
    case 12:
      if ((argc > i + 1) && (IsPosNumber(arg[i + 1]))) {
        i++;
        params.maxbufsize = atoi(arg[i]);
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    case 13:
      if ((argc > i + 1) && (IsPosNumber(arg[i + 1]))) {
        i++;
        params.ppid = (char *)malloc(sizeof(char) * (strlen(arg[i]) + 1));
        strcpy(params.ppid, arg[i]);
      } else {
        params.error[params.errorcnt] = i;
        params.errorcnt++;
      }
      break;
    default:
      params.error[params.errorcnt] = i;
      params.errorcnt++;
      break;
    }
  }
  return params;
}