const char *get_estr(int *ninp, t_inpfile **inp, const char *name, const char *def) { char buf[32]; int ii; ii = get_einp(ninp, inp, name); if (ii == -1) { if (def) { sprintf(buf, "%s", def); (*inp)[(*ninp)-1].value = strdup(buf); } else { (*inp)[(*ninp)-1].value = NULL; } return def; } else { return (*inp)[ii].value; } }
gmx_large_int_t get_egmx_large_int(int *ninp, t_inpfile **inp, const char *name, gmx_large_int_t def, warninp_t wi) { char buf[32], *ptr, warn_buf[STRLEN]; int ii; gmx_large_int_t ret; ii = get_einp(ninp, inp, name); if (ii == -1) { sprintf(buf, gmx_large_int_pfmt, def); (*inp)[(*ninp)-1].value = strdup(buf); return def; } else { ret = str_to_large_int_t((*inp)[ii].value, &ptr); if (ptr == (*inp)[ii].value) { sprintf(warn_buf, "Right hand side '%s' for parameter '%s' in parameter file is not an integer value\n", (*inp)[ii].value, (*inp)[ii].name); warning_error(wi, warn_buf); } return ret; } }
double get_ereal(int *ninp, t_inpfile **inp, const char *name, double def, warninp_t wi) { char buf[32], *ptr, warn_buf[STRLEN]; int ii; double ret; ii = get_einp(ninp, inp, name); if (ii == -1) { sprintf(buf, "%g", def); (*inp)[(*ninp)-1].value = strdup(buf); return def; } else { ret = strtod((*inp)[ii].value, &ptr); if (ptr == (*inp)[ii].value) { sprintf(warn_buf, "Right hand side '%s' for parameter '%s' in parameter file is not a real value\n", (*inp)[ii].value, (*inp)[ii].name); warning_error(wi, warn_buf); } return ret; } }
/* Note that sanitizing the trailing part of (*inp)[ii].value was the responsibility of read_inpfile() */ int get_eint(int *ninp, t_inpfile **inp, const char *name, int def, warninp_t wi) { char buf[32], *ptr, warn_buf[STRLEN]; int ii; int ret; ii = get_einp(ninp, inp, name); if (ii == -1) { sprintf(buf, "%d", def); (*inp)[(*ninp)-1].value = gmx_strdup(buf); return def; } else { ret = strtol((*inp)[ii].value, &ptr, 10); if (*ptr != '\0') { sprintf(warn_buf, "Right hand side '%s' for parameter '%s' in parameter file is not an integer value\n", (*inp)[ii].value, (*inp)[ii].name); warning_error(wi, warn_buf); } return ret; } }
int get_eeenum(int *ninp, t_inpfile **inp, const char *name, const char **defs, warninp_t wi) { int ii, i, j; int n = 0; char buf[STRLEN]; ii = get_einp(ninp, inp, name); if (ii == -1) { (*inp)[(*ninp)-1].value = strdup(defs[0]); return 0; } for (i = 0; (defs[i] != NULL); i++) { if (gmx_strcasecmp_min(defs[i], (*inp)[ii].value) == 0) { break; } } if (defs[i] == NULL) { n += sprintf(buf, "Invalid enum '%s' for variable %s, using '%s'\n", (*inp)[ii].value, name, defs[0]); n += sprintf(buf+n, "Next time use one of:"); j = 0; while (defs[j]) { n += sprintf(buf+n, " '%s'", defs[j]); j++; } if (wi != NULL) { warning_error(wi, buf); } else { fprintf(stderr, "%s\n", buf); } (*inp)[ii].value = strdup(defs[0]); return 0; } return i; }