2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2009, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
40 * Implementation of functions in selparam.h.
51 #include <selmethod.h>
54 #include "parsetree.h"
59 * \param[in] name Name of the parameter to search.
60 * \param[in] nparam Number of parameters in the \p param array.
61 * \param[in] param Parameter array to search.
62 * \returns Pointer to the parameter in the \p param
63 * or NULL if no parameter with name \p name was found.
65 * The comparison is case-sensitive.
68 gmx_ana_selparam_find(const char *name, int nparam, gmx_ana_selparam_t *param)
76 /* Find the first non-null parameter */
78 while (i < nparam && param[i].name == NULL)
82 /* Process the special case of a NULL parameter */
85 return (i == 0) ? NULL : ¶m[i-1];
87 for ( ; i < nparam; ++i)
89 if (!strcmp(param[i].name, name))
93 /* Check for 'no' prefix on gmx_boolean parameters */
94 if (param[i].val.type == NO_VALUE
95 && strlen(name) > 2 && name[0] == 'n' && name[1] == 'o'
96 && !strcmp(param[i].name, name+2))
105 * Does a type conversion on a \c t_selexpr_value.
107 * \param[in,out] value Value to convert.
108 * \param[in] type Type to convert to.
109 * \param[in] scanner Scanner data structure.
110 * \returns 0 on success, a non-zero value on error.
113 convert_value(t_selexpr_value *value, e_selvalue_t type, void *scanner)
115 if (value->type == type || type == NO_VALUE)
121 /* Conversion from atom selection to position using default
122 * reference positions. */
123 if (value->type == GROUP_VALUE && type == POS_VALUE)
126 _gmx_sel_init_position(value->u.expr, NULL, scanner);
127 if (value->u.expr == NULL)
138 /* Integers to floating point are easy */
139 if (value->type == INT_VALUE && type == REAL_VALUE)
141 real r1 = (real)value->u.i.i1;
142 real r2 = (real)value->u.i.i2;
148 /* Reals that are integer-valued can also be converted */
149 if (value->type == REAL_VALUE && type == INT_VALUE
150 && gmx_within_tol(value->u.r.r1, (int)value->u.r.r1, GMX_REAL_EPS)
151 && gmx_within_tol(value->u.r.r2, (int)value->u.r.r2, GMX_REAL_EPS))
153 int i1 = (int)value->u.r.r1;
154 int i2 = (int)value->u.r.r2;
165 * Does a type conversion on a list of values.
167 * \param[in,out] values Values to convert.
168 * \param[in] type Type to convert to.
169 * \param[in] scanner Scanner data structure.
170 * \returns 0 on success, a non-zero value on error.
173 convert_values(t_selexpr_value *values, e_selvalue_t type, void *scanner)
175 t_selexpr_value *value;
182 rc1 = convert_value(value, type, scanner);
183 if (rc1 != 0 && rc == 0)
189 /* FIXME: More informative error messages */
194 * Adds a child element for a parameter, keeping the parameter order.
196 * \param[in,out] root Root element to which the child is added.
197 * \param[in] child Child to add.
198 * \param[in] param Parameter for which this child is a value.
200 * Puts \p child in the child list of \p root such that the list remains
201 * in the same order as the corresponding parameters.
204 place_child(t_selelem *root, t_selelem *child, gmx_ana_selparam_t *param)
206 gmx_ana_selparam_t *ps;
209 ps = root->u.expr.method->param;
211 /* Put the child element in the correct place */
212 if (!root->child || n < root->child->u.param - ps)
214 child->next = root->child;
222 while (prev->next && prev->next->u.param - ps >= n)
226 child->next = prev->next;
232 * Comparison function for sorting integer ranges.
234 * \param[in] a Pointer to the first range.
235 * \param[in] b Pointer to the second range.
236 * \returns -1, 0, or 1 depending on the relative order of \p a and \p b.
238 * The ranges are primarily sorted based on their starting point, and
239 * secondarily based on length (longer ranges come first).
242 cmp_int_range(const void *a, const void *b)
244 if (((int *)a)[0] < ((int *)b)[0])
248 if (((int *)a)[0] > ((int *)b)[0])
252 if (((int *)a)[1] > ((int *)b)[1])
260 * Comparison function for sorting real ranges.
262 * \param[in] a Pointer to the first range.
263 * \param[in] b Pointer to the second range.
264 * \returns -1, 0, or 1 depending on the relative order of \p a and \p b.
266 * The ranges are primarily sorted based on their starting point, and
267 * secondarily based on length (longer ranges come first).
270 cmp_real_range(const void *a, const void *b)
272 if (((real *)a)[0] < ((real *)b)[0])
276 if (((real *)a)[0] > ((real *)b)[0])
280 if (((real *)a)[1] > ((real *)b)[1])
288 * Parses the values for a parameter that takes integer or real ranges.
290 * \param[in] nval Number of values in \p values.
291 * \param[in] values Pointer to the list of values.
292 * \param param Parameter to parse.
293 * \returns TRUE if the values were parsed successfully, FALSE otherwise.
296 parse_values_range(int nval, t_selexpr_value *values, gmx_ana_selparam_t *param)
298 t_selexpr_value *value;
303 param->flags &= ~SPAR_DYNAMIC;
304 if (param->val.type != INT_VALUE && param->val.type != REAL_VALUE)
306 gmx_bug("internal error");
311 if (param->val.type == INT_VALUE)
325 _gmx_selparser_error("expressions not supported within range parameters");
328 if (value->type != param->val.type)
330 gmx_bug("internal error");
333 if (param->val.type == INT_VALUE)
335 /* Make sure the input range is in increasing order */
336 if (value->u.i.i1 > value->u.i.i2)
338 int tmp = value->u.i.i1;
339 value->u.i.i1 = value->u.i.i2;
342 /* Check if the new range overlaps or extends the previous one */
343 if (i > 0 && value->u.i.i1 <= idata[i-1]+1 && value->u.i.i2 >= idata[i-2]-1)
345 idata[i-2] = min(idata[i-2], value->u.i.i1);
346 idata[i-1] = max(idata[i-1], value->u.i.i2);
350 idata[i++] = value->u.i.i1;
351 idata[i++] = value->u.i.i2;
356 /* Make sure the input range is in increasing order */
357 if (value->u.r.r1 > value->u.r.r2)
359 real tmp = value->u.r.r1;
360 value->u.r.r1 = value->u.r.r2;
363 /* Check if the new range overlaps or extends the previous one */
364 if (i > 0 && value->u.r.r1 <= rdata[i-1] && value->u.r.r2 >= rdata[i-2])
366 rdata[i-2] = min(rdata[i-2], value->u.r.r1);
367 rdata[i-1] = max(rdata[i-1], value->u.r.r2);
371 rdata[i++] = value->u.r.r1;
372 rdata[i++] = value->u.r.r2;
378 /* Sort the ranges and merge consequent ones */
379 if (param->val.type == INT_VALUE)
381 qsort(idata, n, 2*sizeof(int), &cmp_int_range);
382 for (i = j = 2; i < 2*n; i += 2)
384 if (idata[j-1]+1 >= idata[i])
386 if (idata[i+1] > idata[j-1])
388 idata[j-1] = idata[i+1];
394 idata[j+1] = idata[i+1];
401 qsort(rdata, n, 2*sizeof(real), &cmp_real_range);
402 for (i = j = 2; i < 2*n; i += 2)
404 if (rdata[j-1]+1 >= rdata[i])
406 if (rdata[i+1] > rdata[j-1])
408 rdata[j-1] = rdata[i+1];
414 rdata[j+1] = rdata[i+1];
420 /* Store the values */
421 if (param->flags & SPAR_VARNUM)
424 if (param->val.type == INT_VALUE)
427 _gmx_selvalue_setstore_alloc(¶m->val, idata, j);
432 _gmx_selvalue_setstore_alloc(¶m->val, rdata, j);
437 if (n != param->val.nr)
439 _gmx_selparser_error("the value of parameter '%s' should consist of exactly one range",
445 if (param->val.type == INT_VALUE)
447 memcpy(param->val.u.i, idata, 2*n*sizeof(int));
452 memcpy(param->val.u.r, rdata, 2*n*sizeof(real));
458 *param->nvalptr = param->val.nr;
460 param->nvalptr = NULL;
466 * Parses the values for a parameter that takes a variable number of values.
468 * \param[in] nval Number of values in \p values.
469 * \param[in] values Pointer to the list of values.
470 * \param param Parameter to parse.
471 * \param root Selection element to which child expressions are added.
472 * \returns TRUE if the values were parsed successfully, FALSE otherwise.
474 * For integer ranges, the sequence of numbers from the first to second value
475 * is stored, each as a separate value.
478 parse_values_varnum(int nval, t_selexpr_value *values,
479 gmx_ana_selparam_t *param, t_selelem *root)
481 t_selexpr_value *value;
484 param->flags &= ~SPAR_DYNAMIC;
485 /* Update nval if there are integer ranges. */
486 if (param->val.type == INT_VALUE)
491 if (value->type == INT_VALUE && !value->bExpr)
493 nval += abs(value->u.i.i2 - value->u.i.i1);
499 /* Check that the value type is actually implemented */
500 if (param->val.type != INT_VALUE && param->val.type != REAL_VALUE
501 && param->val.type != STR_VALUE && param->val.type != POS_VALUE)
503 gmx_bug("internal error");
507 /* Reserve appropriate amount of memory */
508 if (param->val.type == POS_VALUE)
510 gmx_ana_pos_reserve(param->val.u.p, nval, 0);
511 gmx_ana_pos_set_nr(param->val.u.p, nval);
512 gmx_ana_indexmap_init(¶m->val.u.p->m, NULL, NULL, INDEX_UNKNOWN);
516 _gmx_selvalue_reserve(¶m->val, nval);
525 _gmx_selparser_error("expressions not supported within value lists");
528 if (value->type != param->val.type)
530 gmx_bug("internal error");
533 switch (param->val.type)
536 if (value->u.i.i1 <= value->u.i.i2)
538 for (j = value->u.i.i1; j <= value->u.i.i2; ++j)
540 param->val.u.i[i++] = j;
545 for (j = value->u.i.i1; j >= value->u.i.i2; --j)
547 param->val.u.i[i++] = j;
552 if (value->u.r.r1 != value->u.r.r2)
554 _gmx_selparser_error("real ranges not supported for parameter '%s'", param->name);
557 param->val.u.r[i++] = value->u.r.r1;
559 case STR_VALUE: param->val.u.s[i++] = strdup(value->u.s); break;
560 case POS_VALUE: copy_rvec(value->u.x, param->val.u.p->x[i++]); break;
561 default: /* Should not be reached */
562 gmx_bug("internal error");
570 *param->nvalptr = param->val.nr;
572 param->nvalptr = NULL;
573 /* Create a dummy child element to store the string values.
574 * This element is responsible for freeing the values, but carries no
576 if (param->val.type == STR_VALUE)
580 child = _gmx_selelem_create(SEL_CONST);
581 _gmx_selelem_set_vtype(child, STR_VALUE);
582 child->name = param->name;
583 child->flags &= ~SEL_ALLOCVAL;
584 child->flags |= SEL_FLAGSSET | SEL_VARNUMVAL | SEL_ALLOCDATA;
585 child->v.nr = param->val.nr;
586 _gmx_selvalue_setstore(&child->v, param->val.u.s);
587 /* Because the child is not group-valued, the u union is not used
588 * for anything, so we can abuse it by storing the parameter value
589 * as place_child() expects, but this is really ugly... */
590 child->u.param = param;
591 place_child(root, child, param);
598 * Adds a new subexpression reference to a selection element.
600 * \param[in,out] root Root element to which the subexpression is added.
601 * \param[in] param Parameter for which this expression is a value.
602 * \param[in] expr Expression to add.
603 * \returns The created child element.
605 * Creates a new \ref SEL_SUBEXPRREF element and adds it into the child
607 * If \p expr is already a \ref SEL_SUBEXPRREF, it is used as it is.
608 * \ref SEL_ALLOCVAL is cleared for the returned element.
611 add_child(t_selelem *root, gmx_ana_selparam_t *param, t_selelem *expr)
616 if (root->type != SEL_EXPRESSION && root->type != SEL_MODIFIER)
618 gmx_bug("unsupported root element for selection parameter parser");
621 /* Create a subexpression reference element if necessary */
622 if (expr->type == SEL_SUBEXPRREF)
628 child = _gmx_selelem_create(SEL_SUBEXPRREF);
633 _gmx_selelem_set_vtype(child, expr->v.type);
636 /* Setup the child element */
637 child->flags &= ~SEL_ALLOCVAL;
638 child->u.param = param;
639 if (child->v.type != param->val.type)
641 _gmx_selparser_error("invalid expression value for parameter '%s'",
645 rc = _gmx_selelem_update_flags(child);
650 if ((child->flags & SEL_DYNAMIC) && !(param->flags & SPAR_DYNAMIC))
652 _gmx_selparser_error("parameter '%s' does not support dynamic values",
656 if (!(child->flags & SEL_DYNAMIC))
658 param->flags &= ~SPAR_DYNAMIC;
660 /* Put the child element in the correct place */
661 place_child(root, child, param);
667 _gmx_selelem_free(child);
673 * Parses an expression value for a parameter that takes a variable number of values.
675 * \param[in] nval Number of values in \p values.
676 * \param[in] values Pointer to the list of values.
677 * \param param Parameter to parse.
678 * \param root Selection element to which child expressions are added.
679 * \returns TRUE if the values were parsed successfully, FALSE otherwise.
682 parse_values_varnum_expr(int nval, t_selexpr_value *values,
683 gmx_ana_selparam_t *param, t_selelem *root)
685 t_selexpr_value *value;
689 if (nval != 1 || !values->bExpr)
691 gmx_bug("internal error");
696 child = add_child(root, param, value->u.expr);
697 value->u.expr = NULL;
703 /* Process single-valued expressions */
704 /* TODO: We should also handle SEL_SINGLEVAL expressions here */
705 if (child->v.type == POS_VALUE || child->v.type == GROUP_VALUE)
707 /* Set the value storage */
708 _gmx_selvalue_setstore(&child->v, param->val.u.ptr);
712 *param->nvalptr = param->val.nr;
714 param->nvalptr = NULL;
718 if (!(child->flags & SEL_VARNUMVAL))
720 _gmx_selparser_error("invalid expression value for parameter '%s'",
725 child->flags |= SEL_ALLOCVAL;
727 *param->nvalptr = param->val.nr;
728 /* Rest of the initialization is done during compilation in
735 * Initializes the storage of an expression value.
737 * \param[in,out] sel Selection element that evaluates the value.
738 * \param[in] param Parameter to receive the value.
739 * \param[in] i The value of \p sel evaluates the value \p i for
742 * Initializes the data pointer of \p sel such that the result is stored
743 * as the value \p i of \p param.
744 * This function is used internally by parse_values_std().
747 set_expr_value_store(t_selelem *sel, gmx_ana_selparam_t *param, int i)
749 if (sel->v.type != GROUP_VALUE && !(sel->flags & SEL_SINGLEVAL))
751 _gmx_selparser_error("invalid expression value for parameter '%s'",
757 case INT_VALUE: sel->v.u.i = ¶m->val.u.i[i]; break;
758 case REAL_VALUE: sel->v.u.r = ¶m->val.u.r[i]; break;
759 case STR_VALUE: sel->v.u.s = ¶m->val.u.s[i]; break;
760 case POS_VALUE: sel->v.u.p = ¶m->val.u.p[i]; break;
761 case GROUP_VALUE: sel->v.u.g = ¶m->val.u.g[i]; break;
763 gmx_bug("internal error");
772 * Parses the values for a parameter that takes a constant number of values.
774 * \param[in] nval Number of values in \p values.
775 * \param[in] values Pointer to the list of values.
776 * \param param Parameter to parse.
777 * \param root Selection element to which child expressions are added.
778 * \returns TRUE if the values were parsed successfully, FALSE otherwise.
780 * For integer ranges, the sequence of numbers from the first to second value
781 * is stored, each as a separate value.
784 parse_values_std(int nval, t_selexpr_value *values, gmx_ana_selparam_t *param,
787 t_selexpr_value *value;
792 /* Handle atom-valued parameters */
793 if (param->flags & SPAR_ATOMVAL)
797 _gmx_selparser_error("extra values for parameter '%s'", param->name);
803 child = add_child(root, param, value->u.expr);
804 value->u.expr = NULL;
809 child->flags |= SEL_ALLOCVAL;
810 if (child->v.type != GROUP_VALUE && (child->flags & SEL_ATOMVAL))
812 /* Rest of the initialization is done during compilation in
814 /* TODO: Positions are not correctly handled */
818 *param->nvalptr = -1;
822 param->flags &= ~SPAR_ATOMVAL;
828 param->nvalptr = NULL;
829 if (param->val.type == INT_VALUE || param->val.type == REAL_VALUE
830 || param->val.type == STR_VALUE)
832 _gmx_selvalue_reserve(¶m->val, 1);
834 return set_expr_value_store(child, param, 0);
836 /* If we reach here, proceed with normal parameter handling */
838 if (param->val.type == INT_VALUE || param->val.type == REAL_VALUE
839 || param->val.type == STR_VALUE)
841 _gmx_selvalue_reserve(¶m->val, 1);
843 param->flags &= ~SPAR_ATOMVAL;
844 param->flags &= ~SPAR_DYNAMIC;
850 while (value && i < param->val.nr)
852 if (value->type != param->val.type)
854 _gmx_selparser_error("incorrect value for parameter '%s' skipped", param->name);
860 child = add_child(root, param, value->u.expr);
861 /* Clear the expression from the value once it is stored */
862 value->u.expr = NULL;
863 /* Check that the expression is valid */
868 if (!set_expr_value_store(child, param, i))
872 if (child->flags & SEL_DYNAMIC)
879 /* Value is not an expression */
883 if (value->u.i.i1 <= value->u.i.i2)
885 for (j = value->u.i.i1; j <= value->u.i.i2 && i < param->val.nr; ++j)
887 param->val.u.i[i++] = j;
889 if (j != value->u.i.i2 + 1)
891 _gmx_selparser_error("extra values for parameter '%s' skipped", param->name);
896 for (j = value->u.i.i1; j >= value->u.i.i2 && i < param->val.nr; --j)
898 param->val.u.i[i++] = j;
900 if (j != value->u.i.i2 - 1)
902 _gmx_selparser_error("extra values for parameter '%s' skipped", param->name);
908 if (value->u.r.r1 != value->u.r.r2)
910 _gmx_selparser_error("real ranges not supported for parameter '%s'", param->name);
913 param->val.u.r[i] = value->u.r.r1;
916 param->val.u.s[i] = strdup(value->u.s);
919 gmx_ana_pos_init_const(¶m->val.u.p[i], value->u.x);
923 gmx_bug("internal error");
932 _gmx_selparser_error("extra values for parameter '%s'", param->name);
935 if (i < param->val.nr)
937 _gmx_selparser_error("not enough values for parameter '%s'", param->name);
942 param->flags &= ~SPAR_DYNAMIC;
946 *param->nvalptr = param->val.nr;
948 param->nvalptr = NULL;
954 * Parses the values for a gmx_boolean parameter.
956 * \param[in] name Name by which the parameter was given.
957 * \param[in] nval Number of values in \p values.
958 * \param[in] values Pointer to the list of values.
959 * \param param Parameter to parse.
960 * \returns TRUE if the values were parsed successfully, FALSE otherwise.
963 parse_values_gmx_bool(const char *name, int nval, t_selexpr_value *values, gmx_ana_selparam_t *param)
968 if (param->val.type != NO_VALUE)
970 gmx_bug("internal error");
973 if (nval > 1 || (values && values->type != INT_VALUE))
975 _gmx_selparser_error("gmx_boolean parameter '%s' takes only a yes/no/on/off/0/1 value", param->name);
980 /* Check if the parameter name is given with a 'no' prefix */
982 if (len > 2 && name[0] == 'n' && name[1] == 'o'
983 && strncmp(name+2, param->name, len-2) == 0)
987 if (bSetNo && nval > 0)
989 _gmx_selparser_error("gmx_boolean parameter 'no%s' should not have a value", param->name);
992 if (values && values->u.i.i1 == 0)
997 *param->val.u.b = bSetNo ? FALSE : TRUE;
1002 * Parses the values for an enumeration parameter.
1004 * \param[in] nval Number of values in \p values.
1005 * \param[in] values Pointer to the list of values.
1006 * \param param Parameter to parse.
1007 * \returns TRUE if the values were parsed successfully, FALSE otherwise.
1010 parse_values_enum(int nval, t_selexpr_value *values, gmx_ana_selparam_t *param)
1016 _gmx_selparser_error("a single value is required for parameter '%s'", param->name);
1019 if (values->type != STR_VALUE || param->val.type != STR_VALUE)
1021 gmx_bug("internal error");
1026 _gmx_selparser_error("expression value for enumerated parameter '%s' not supported", param->name);
1030 len = strlen(values->u.s);
1033 while (param->val.u.s[i] != NULL)
1035 if (strncmp(values->u.s, param->val.u.s[i], len) == 0)
1037 /* Check if there is a duplicate match */
1040 _gmx_selparser_error("ambiguous value for parameter '%s'", param->name);
1049 _gmx_selparser_error("invalid value for parameter '%s'", param->name);
1052 param->val.u.s[0] = param->val.u.s[match];
1057 * Replaces constant expressions with their values.
1059 * \param[in,out] values First element in the value list to process.
1062 convert_const_values(t_selexpr_value *values)
1064 t_selexpr_value *val;
1069 if (val->bExpr && val->u.expr->v.type != GROUP_VALUE &&
1070 val->u.expr->type == SEL_CONST)
1072 t_selelem *expr = val->u.expr;
1074 switch (expr->v.type)
1077 val->u.i.i1 = val->u.i.i2 = expr->v.u.i[0];
1080 val->u.r.r1 = val->u.r.r2 = expr->v.u.r[0];
1083 val->u.s = expr->v.u.s[0];
1086 copy_rvec(expr->v.u.p->x[0], val->u.x);
1089 gmx_bug("internal error");
1092 _gmx_selelem_free(expr);
1099 * \param pparams List of parameters from the selection parser.
1100 * \param[in] nparam Number of parameters in \p params.
1101 * \param params Array of parameters to parse.
1102 * \param root Selection element to which child expressions are added.
1103 * \param[in] scanner Scanner data structure.
1104 * \returns TRUE if the parameters were parsed successfully, FALSE otherwise.
1106 * Initializes the \p params array based on the parameters in \p pparams.
1107 * See the documentation of \c gmx_ana_selparam_t for different options
1108 * available for parsing.
1110 * The list \p pparams and any associated values are freed after the parameters
1111 * have been processed, no matter is there was an error or not.
1114 _gmx_sel_parse_params(t_selexpr_param *pparams, int nparam, gmx_ana_selparam_t *params,
1115 t_selelem *root, void *scanner)
1117 t_selexpr_param *pparam;
1118 gmx_ana_selparam_t *oparam;
1122 /* Check that the value pointers of SPAR_VARNUM parameters are NULL and
1123 * that they are not NULL for other parameters */
1125 for (i = 0; i < nparam; ++i)
1127 if (params[i].val.type != POS_VALUE && (params[i].flags & (SPAR_VARNUM | SPAR_ATOMVAL)))
1129 if (params[i].val.u.ptr != NULL)
1131 _gmx_selparser_error("warning: value pointer of parameter '%s' is not NULL\n"
1132 " although it should be for SPAR_VARNUM and SPAR_ATOMVAL parameters\n",
1135 if ((params[i].flags & SPAR_VARNUM)
1136 && (params[i].flags & SPAR_DYNAMIC) && !params[i].nvalptr)
1138 _gmx_selparser_error("error: nvalptr of parameter '%s' is NULL\n"
1139 " but both SPAR_VARNUM and SPAR_DYNAMIC are specified\n",
1146 if (params[i].val.u.ptr == NULL)
1148 _gmx_selparser_error("error: value pointer of parameter '%s' is NULL\n",
1156 _gmx_selexpr_free_params(pparams);
1159 /* Parse the parameters */
1164 /* Find the parameter and make some checks */
1165 if (pparam->name != NULL)
1168 oparam = gmx_ana_selparam_find(pparam->name, nparam, params);
1172 oparam = ¶ms[i];
1173 if (oparam->name != NULL)
1176 _gmx_selparser_error("too many NULL parameters provided");
1184 _gmx_selparser_error("all NULL parameters should appear in the beginning of the list");
1186 pparam = pparam->next;
1191 _gmx_selparser_error("unknown parameter '%s' skipped", pparam->name);
1195 if (oparam->flags & SPAR_SET)
1197 _gmx_selparser_error("parameter '%s' set multiple times, extra values skipped", pparam->name);
1201 oparam->flags |= SPAR_SET;
1202 /* Process the values for the parameter */
1203 convert_const_values(pparam->value);
1204 if (convert_values(pparam->value, oparam->val.type, scanner) != 0)
1206 _gmx_selparser_error("invalid value for parameter '%s'", pparam->name);
1210 if (oparam->val.type == NO_VALUE)
1212 rc = parse_values_gmx_bool(pparam->name, pparam->nval, pparam->value, oparam);
1214 else if (oparam->flags & SPAR_RANGES)
1216 rc = parse_values_range(pparam->nval, pparam->value, oparam);
1218 else if (oparam->flags & SPAR_VARNUM)
1220 if (pparam->nval == 1 && pparam->value->bExpr)
1222 rc = parse_values_varnum_expr(pparam->nval, pparam->value, oparam, root);
1226 rc = parse_values_varnum(pparam->nval, pparam->value, oparam, root);
1229 else if (oparam->flags & SPAR_ENUMVAL)
1231 rc = parse_values_enum(pparam->nval, pparam->value, oparam);
1235 rc = parse_values_std(pparam->nval, pparam->value, oparam, root);
1241 /* Advance to the next parameter */
1243 pparam = pparam->next;
1245 /* Check that all required parameters are present */
1246 for (i = 0; i < nparam; ++i)
1248 if (!(params[i].flags & SPAR_OPTIONAL) && !(params[i].flags & SPAR_SET))
1250 _gmx_selparser_error("required parameter '%s' not specified", params[i].name);
1255 _gmx_selexpr_free_params(pparams);