Merge release-4-5-patches into release-4-6
[alexxy/gromacs.git] / src / gmxlib / selection / selmethod.c
1 /*
2  *
3  *                This source code is part of
4  *
5  *                 G   R   O   M   A   C   S
6  *
7  *          GROningen MAchine for Chemical Simulations
8  *
9  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11  * Copyright (c) 2001-2009, The GROMACS development team,
12  * check out http://www.gromacs.org for more information.
13
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * If you want to redistribute modifications, please consider that
20  * scientific software is very special. Version control is crucial -
21  * bugs must be traceable. We will be happy to consider code for
22  * inclusion in the official distribution, but derived work must not
23  * be called official GROMACS. Details are found in the README & COPYING
24  * files - if they are missing, get the official version at www.gromacs.org.
25  *
26  * To help us fund GROMACS development, we humbly ask that you cite
27  * the papers on the package - you can find them in the top README file.
28  *
29  * For more info, check our website at http://www.gromacs.org
30  */
31 /*! \internal \file
32  * \brief Implementation of functions in selmethod.h.
33  */
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #include <ctype.h>
39 #include <stdarg.h>
40
41 #include <macros.h>
42 #include <string2.h>
43
44 #include <selmethod.h>
45
46 #include "selcollection.h"
47 #include "symrec.h"
48
49 /*
50  * These global variables cannot be const because gmx_ana_selmethod_register()
51  * modifies them to set some defaults. This is a small price to pay for the
52  * convenience of not having to remember exactly how the selection compiler
53  * expects the structures to be filled, and even more so if the expectations
54  * change. Also, even if the gmx_ana_selmethod_t structures were made const,
55  * the parameters could not be without typecasts somewhere, because the param
56  * field in gmx_ana_selmethod_t cannot be declared const.
57  *
58  * Even though the variables may be modified, this should be thread-safe as
59  * modifications are done only in gmx_ana_selmethod_register(), and it should
60  * work even if called more than once for the same structure, and even if
61  * called concurrently from multiple threads (as long as the selection
62  * collection is not the same).
63  *
64  * All of these problems should go away if/when the selection methods are
65  * implemented as C++ classes.
66  */
67
68 /* From sm_com.c */
69 extern gmx_ana_selmethod_t sm_cog;
70 extern gmx_ana_selmethod_t sm_com;
71 /* From sm_simple.c */
72 extern gmx_ana_selmethod_t sm_all;
73 extern gmx_ana_selmethod_t sm_none;
74 extern gmx_ana_selmethod_t sm_atomnr;
75 extern gmx_ana_selmethod_t sm_resnr;
76 extern gmx_ana_selmethod_t sm_resindex;
77 extern gmx_ana_selmethod_t sm_molindex;
78 extern gmx_ana_selmethod_t sm_atomname;
79 extern gmx_ana_selmethod_t sm_pdbatomname;
80 extern gmx_ana_selmethod_t sm_atomtype;
81 extern gmx_ana_selmethod_t sm_resname;
82 extern gmx_ana_selmethod_t sm_insertcode;
83 extern gmx_ana_selmethod_t sm_chain;
84 extern gmx_ana_selmethod_t sm_mass;
85 extern gmx_ana_selmethod_t sm_charge;
86 extern gmx_ana_selmethod_t sm_altloc;
87 extern gmx_ana_selmethod_t sm_occupancy;
88 extern gmx_ana_selmethod_t sm_betafactor;
89 extern gmx_ana_selmethod_t sm_x;
90 extern gmx_ana_selmethod_t sm_y;
91 extern gmx_ana_selmethod_t sm_z;
92 /* From sm_distance.c */
93 extern gmx_ana_selmethod_t sm_distance;
94 extern gmx_ana_selmethod_t sm_mindistance;
95 extern gmx_ana_selmethod_t sm_within;
96 /* From sm_insolidangle.c */
97 extern gmx_ana_selmethod_t sm_insolidangle;
98 /* From sm_same.c */
99 extern gmx_ana_selmethod_t sm_same;
100
101 /* From sm_merge.c */
102 extern gmx_ana_selmethod_t sm_merge;
103 extern gmx_ana_selmethod_t sm_plus;
104 /* From sm_permute.c */
105 extern gmx_ana_selmethod_t sm_permute;
106
107 /*! \brief
108  * Helper structure for defining selection methods.
109  */
110 typedef struct {
111     /*! \brief
112      * Name to register the method under.
113      *
114      * If NULL, use the actual name of the method.
115      * This field is used for defining synonyms.
116      */
117     const char            *name;
118     /** Method data structure to register. */
119     gmx_ana_selmethod_t   *method;
120 } t_register_method;
121
122 /** Array of selection methods defined in the library. */
123 static const t_register_method smtable_def[] = {
124     {NULL,         &sm_cog},
125     {NULL,         &sm_com},
126
127     {NULL,         &sm_all},
128     {NULL,         &sm_none},
129     {NULL,         &sm_atomnr},
130     {NULL,         &sm_resnr},
131     {"resid",      &sm_resnr},
132     {NULL,         &sm_resindex},
133     {"residue",    &sm_resindex},
134     {NULL,         &sm_molindex},
135     {"mol",        &sm_molindex},
136     {"molecule",   &sm_molindex},
137     {NULL,         &sm_atomname},
138     {"name",       &sm_atomname},
139     {NULL,         &sm_pdbatomname},
140     {"pdbname",    &sm_pdbatomname},
141     {NULL,         &sm_atomtype},
142     {"type",       &sm_atomtype},
143     {NULL,         &sm_resname},
144     {NULL,         &sm_insertcode},
145     {NULL,         &sm_chain},
146     {NULL,         &sm_mass},
147     {NULL,         &sm_charge},
148     {NULL,         &sm_altloc},
149     {NULL,         &sm_occupancy},
150     {NULL,         &sm_betafactor},
151     {NULL,         &sm_x},
152     {NULL,         &sm_y},
153     {NULL,         &sm_z},
154
155     {NULL,         &sm_distance},
156     {NULL,         &sm_mindistance},
157     {NULL,         &sm_within},
158     {NULL,         &sm_insolidangle},
159     {NULL,         &sm_same},
160
161     {NULL,         &sm_merge},
162     {NULL,         &sm_plus},
163     {NULL,         &sm_permute},
164 };
165
166 /*! \brief
167  * Convenience function for reporting errors found in selection methods.
168  */
169 static void
170 report_error(FILE *fp, const char *name, const char *fmt, ...)
171 {
172     va_list ap;
173     va_start(ap, fmt);
174     if (fp)
175     {
176         fprintf(fp, "selection method '%s': ", name);
177         vfprintf(fp, fmt, ap);
178         fprintf(fp, "\n");
179     }
180     va_end(ap);
181 }
182
183 /*! \brief
184  * Convenience function for reporting errors found in selection method parameters.
185  */
186 static void
187 report_param_error(FILE *fp, const char *mname, const char *pname,
188                    const char *fmt, ...)
189 {
190     va_list ap;
191     va_start(ap, fmt);
192     if (fp)
193     {
194         fprintf(fp, "selection method '%s': parameter '%s': ", mname, pname);
195         vfprintf(fp, fmt, ap);
196         fprintf(fp, "\n");
197     }
198     va_end(ap);
199 }
200
201 /*! \brief
202  * Checks the validity of parameters.
203  *
204  * \param[in]     fp      File handle to use for diagnostic messages
205  *   (can be NULL).
206  * \param[in]     name    Name of the method (used for error messages).
207  * \param[in]     nparams Number of parameters in \p param.
208  * \param[in,out] param   Parameter array
209  *   (only the \c flags field of gmx_boolean parameters may be modified).
210  * \param[in]     symtab  Symbol table (used for checking overlaps).
211  * \returns       TRUE if there are no problems with the parameters,
212  *   FALSE otherwise.
213  *
214  * This function performs some checks common to both check_method() and
215  * check_modifier().
216  * The purpose of these checks is to ensure that the selection parser does not
217  * need to check for the validity of the parameters at each turn, and to
218  * report programming errors as early as possible.
219  * If you remove a check, make sure that the parameter parser can handle the
220  * resulting parameters.
221  */
222 static gmx_bool
223 check_params(FILE *fp, const char *name, int nparams, gmx_ana_selparam_t param[],
224              gmx_sel_symtab_t *symtab)
225 {
226     gmx_bool              bOk = TRUE;
227     gmx_sel_symrec_t *sym;
228     int               i, j;
229
230     if (nparams > 0 && !param)
231     {
232         report_error(fp, name, "error: missing parameter data");
233         return FALSE;
234     }
235     if (nparams == 0 && param)
236     {
237         report_error(fp, name, "warning: parameter data unused because nparams=0");
238     }
239     /* Check each parameter */
240     for (i = 0; i < nparams; ++i)
241     {
242         /* Check that there is at most one NULL name, in the beginning */
243         if (param[i].name == NULL && i > 0)
244         {
245             report_error(fp, name, "error: NULL parameter should be the first one");
246             bOk = FALSE;
247             continue;
248         }
249         /* Check for duplicates */
250         for (j = 0; j < i; ++j)
251         {
252             if (param[j].name == NULL)
253             {
254                 continue;
255             }
256             if (!gmx_strcasecmp(param[i].name, param[j].name))
257             {
258                 report_error(fp, name, "error: duplicate parameter name '%s'", param[i].name);
259                 bOk = FALSE;
260                 break;
261             }
262         }
263         /* Check flags */
264         if (param[i].flags & SPAR_SET)
265         {
266             report_param_error(fp, name, param[i].name, "warning: flag SPAR_SET is set");
267             param[i].flags &= ~SPAR_SET;
268         }
269         if (param[i].flags & SPAR_RANGES)
270         {
271             if (param[i].val.type != INT_VALUE && param[i].val.type != REAL_VALUE)
272             {
273                 report_param_error(fp, name, param[i].name, "error: SPAR_RANGES cannot be set for a non-numeric parameter");
274                 bOk = FALSE;
275             }
276             if (param[i].flags & SPAR_DYNAMIC)
277             {
278                 report_param_error(fp, name, param[i].name, "warning: SPAR_DYNAMIC does not have effect with SPAR_RANGES");
279                 param[i].flags &= ~SPAR_DYNAMIC;
280             }
281             if (!(param[i].flags & SPAR_VARNUM) && param[i].val.nr != 1)
282             {
283                 report_param_error(fp, name, param[i].name, "error: range should take either one or an arbitrary number of values");
284                 bOk = FALSE;
285             }
286             if (param[i].flags & SPAR_ATOMVAL)
287             {
288                 report_param_error(fp, name, param[i].name, "error: SPAR_RANGES and SPAR_ATOMVAL both set");
289                 bOk = FALSE;
290             }
291         }
292         if ((param[i].flags & SPAR_VARNUM) && (param[i].flags & SPAR_ATOMVAL))
293         {
294             report_param_error(fp, name, param[i].name, "error: SPAR_VARNUM and SPAR_ATOMVAL both set");
295             bOk = FALSE;
296         }
297         if (param[i].flags & SPAR_ENUMVAL)
298         {
299             if (param[i].val.type != STR_VALUE)
300             {
301                 report_param_error(fp, name, param[i].name, "error: SPAR_ENUMVAL can only be set for string parameters");
302                 bOk = FALSE;
303             }
304             if (param[i].val.nr != 1)
305             {
306                 report_param_error(fp, name, param[i].name, "error: SPAR_ENUMVAL parameters should take exactly one value");
307                 bOk = FALSE;
308             }
309             if (param[i].flags & (SPAR_DYNAMIC | SPAR_VARNUM | SPAR_ATOMVAL))
310             {
311                 report_param_error(fp, name, param[i].name, "error: only SPAR_OPTIONAL supported with SPAR_ENUMVAL");
312                 bOk = FALSE;
313             }
314         }
315         /* Check gmx_boolean parameters */
316         if (param[i].val.type == NO_VALUE)
317         {
318             if (param[i].val.nr != 0)
319             {
320                 report_param_error(fp, name, param[i].name, "error: number of values should be zero for gmx_boolean parameters");
321                 bOk = FALSE;
322             }
323             /* The gmx_boolean parameters should always be optional, so set the
324              * flag for convenience. */
325             param[i].flags |= SPAR_OPTIONAL;
326             /* Any other flags should not be specified */
327             if (param[i].flags & ~SPAR_OPTIONAL)
328             {
329                 report_param_error(fp, name, param[i].name, "error: gmx_boolean parameter should not have any flags set");
330                 bOk = FALSE;
331             }
332         }
333         /* Check val.nr */
334         if (param[i].flags & (SPAR_VARNUM | SPAR_ATOMVAL))
335         {
336             if (param[i].val.nr != -1)
337             {
338                 report_param_error(fp, name, param[i].name, "warning: val.nr is not -1 although SPAR_VARNUM/SPAR_ATOMVAL is set");
339             }
340             param[i].val.nr = -1;
341         }
342         else if (param[i].val.type != NO_VALUE)
343         {
344             if (param[i].val.nr <= 0)
345             {
346                 report_param_error(fp, name, param[i].name, "error: val.nr <= 0");
347                 bOk = FALSE;
348             }
349         }
350         /* Check that the value pointer is NULL */
351         if (param[i].nvalptr != NULL)
352         {
353             report_param_error(fp, name, param[i].name, "warning: nvalptr is set");
354         }
355         if (param[i].val.u.ptr != NULL && !(param[i].flags & SPAR_ENUMVAL))
356         {
357             report_param_error(fp, name, param[i].name, "warning: value pointer is set");
358         }
359         /* Check that the name contains only valid characters */
360         if (param[i].name == NULL)
361         {
362             continue;
363         }
364         if (!isalpha(param[i].name[0]))
365         {
366             report_param_error(fp, name, param[i].name, "error: name does not begin with a letter");
367             bOk = FALSE;
368             continue;
369         }
370         for (j = 1; param[i].name[j] != 0; ++j)
371         {
372             if (param[i].name[j] != '_' && !isalnum(param[i].name[j]))
373             {
374                 report_param_error(fp, name, param[i].name, "error: name contains non-alphanumeric characters");
375                 bOk = FALSE;
376                 break;
377             }
378         }
379         if (param[i].name[j] != 0)
380         {
381             continue;
382         }
383         /* Check that the name does not conflict with a method */
384         if (_gmx_sel_find_symbol(symtab, param[i].name, TRUE))
385         {
386             report_param_error(fp, name, param[i].name, "error: name conflicts with another method or a keyword");
387             bOk = FALSE;
388         }
389     } /* End of parameter loop */
390     /* Check parameters of existing methods */
391     sym = _gmx_sel_first_symbol(symtab, SYMBOL_METHOD);
392     while (sym)
393     {
394         gmx_ana_selmethod_t *method = _gmx_sel_sym_value_method(sym);
395         gmx_ana_selparam_t  *param =
396             gmx_ana_selmethod_find_param(name, method);
397         if (param)
398         {
399             report_param_error(fp, method->name, param->name, "error: name conflicts with another method or a keyword");
400             bOk = FALSE;
401         }
402         sym = _gmx_sel_next_symbol(sym, SYMBOL_METHOD);
403     }
404     return bOk;
405 }
406
407 /*! \brief
408  * Checks the validity of selection method callback functions.
409  *
410  * \param[in] fp        File handle to use for diagnostic messages
411  *   (can be NULL).
412  * \param[in] method    The method to check.
413  * \returns   TRUE if there are no problems, FALSE otherwise.
414  *
415  * This function performs some checks common to both check_method() and
416  * check_modifier().
417  * This function checks that all the required callbacks are defined, i.e.,
418  * not NULL, to find programming errors.
419  */
420 static gmx_bool
421 check_callbacks(FILE *fp, gmx_ana_selmethod_t *method)
422 {
423     gmx_bool         bOk = TRUE;
424     gmx_bool         bNeedInit;
425     int          i;
426
427     /* Make some checks on init_data and free */
428     if (method->nparams > 0 && !method->init_data)
429     {
430         report_error(fp, method->name, "error: init_data should be provided because the method has parameters");
431         bOk = FALSE;
432     }
433     if (method->free && !method->init_data)
434     {
435         report_error(fp, method->name, "warning: free is not used because of missing init_data");
436     }
437     /* Check presence of outinit for position-valued methods */
438     if (method->type == POS_VALUE && !method->outinit)
439     {
440         report_error(fp, method->name, "error: outinit should be provided because the method has POS_VALUE");
441         bOk = FALSE;
442     }
443     /* Check presence of outinit for variable output count methods */
444     if ((method->flags & SMETH_VARNUMVAL) && !method->outinit)
445     {
446         report_error(fp, method->name, "error: outinit should be provided because the method has SMETH_VARNUMVAL");
447         bOk = FALSE;
448     }
449     /* Warn of dynamic callbacks in static methods */
450     if (!(method->flags & SMETH_MODIFIER))
451     {
452         if (method->pupdate && !(method->flags & SMETH_DYNAMIC))
453         {
454             report_error(fp, method->name, "warning: pupdate not used because the method is static");
455             method->pupdate = NULL;
456         }
457     }
458     /* Check that there is an evaluation function */
459     if (method->type != NO_VALUE && !method->update && !method->pupdate)
460     {
461         report_error(fp, method->name, "error: evaluation function missing");
462         bOk = FALSE;
463     }
464     /* Loop through the parameters to determine if initialization callbacks
465      * are needed. */
466     bNeedInit = FALSE;
467     for (i = 0; i < method->nparams; ++i)
468     {
469         if (method->param[i].val.type != POS_VALUE
470             && (method->param[i].flags & (SPAR_VARNUM | SPAR_ATOMVAL)))
471         {
472             bNeedInit = TRUE;
473         }
474     }
475     /* Check that the callbacks required by the parameters are present */
476     if (bNeedInit && !method->init)
477     {
478         report_error(fp, method->name, "error: init should be provided");
479         bOk = FALSE;
480     }
481     return bOk;
482 }
483
484 /*!
485  * Checks the validity of a selection method.
486  *
487  * \param[in]     fp     File handle to use for diagnostic messages
488  *   (can be NULL).
489  * \param[in,out] method Method to check.
490  * \param[in]     symtab Symbol table (used for checking overlaps).
491  *
492  * Checks the validity of the given selection method data structure
493  * that does not have \ref SMETH_MODIFIER set.
494  * If you remove a check, please make sure that the selection parser,
495  * compiler, and evaluation functions can deal with the method.
496  */
497 static gmx_bool
498 check_method(FILE *fp, gmx_ana_selmethod_t *method, gmx_sel_symtab_t *symtab)
499 {
500     gmx_bool         bOk = TRUE;
501
502     /* Check the type */
503     if (method->type == NO_VALUE)
504     {
505         report_error(fp, method->name, "error: no value type specified");
506         bOk = FALSE;
507     }
508     if (method->type == STR_VALUE && method->nparams > 0)
509     {
510         report_error(fp, method->name, "error: evaluates to a string but is not a keyword");
511         bOk = FALSE;
512     }
513     /* Check flags */
514     if (method->type == GROUP_VALUE)
515     {
516         /* Group methods should always have SMETH_SINGLEVAL,
517          * so set it for convenience. */
518         method->flags |= SMETH_SINGLEVAL;
519         /* Check that conflicting flags are not present. */
520         if (method->flags & SMETH_VARNUMVAL)
521         {
522             report_error(fp, method->name, "error: SMETH_VARNUMVAL cannot be set for group-valued methods");
523             bOk = FALSE;
524         }
525     }
526     else
527     {
528         if ((method->flags & SMETH_SINGLEVAL)
529             && (method->flags & SMETH_VARNUMVAL))
530         {
531             report_error(fp, method->name, "error: SMETH_SINGLEVAL and SMETH_VARNUMVAL both set");
532             bOk = FALSE;
533         }
534     }
535     if ((method->flags & SMETH_CHARVAL) && method->type != STR_VALUE)
536     {
537         report_error(fp, method->name, "error: SMETH_CHARVAL can only be specified for STR_VALUE methods");
538         bOk = FALSE;
539     }
540     /* Check the parameters */
541     if (!check_params(fp, method->name, method->nparams, method->param, symtab))
542     {
543         bOk = FALSE;
544     }
545     /* Check the callback pointers */
546     if (!check_callbacks(fp, method))
547     {
548         bOk = FALSE;
549     }
550
551     return bOk;
552 }
553
554 /*!
555  * Checks the validity of a selection modifier method.
556  *
557  * \param[in]     fp     File handle to use for diagnostic messages
558  *   (can be NULL).
559  * \param[in,out] method Method to check.
560  * \param[in]     symtab Symbol table (used for checking overlaps).
561  *
562  * Checks the validity of the given selection method data structure
563  * that has \ref SMETH_MODIFIER set.
564  * If you remove a check, please make sure that the selection parser,
565  * compiler, and evaluation functions can deal with the method.
566  */
567 static gmx_bool
568 check_modifier(FILE *fp, gmx_ana_selmethod_t *method, gmx_sel_symtab_t *symtab)
569 {
570     gmx_bool         bOk = TRUE;
571
572     /* Check the type */
573     if (method->type != NO_VALUE && method->type != POS_VALUE)
574     {
575         report_error(fp, method->name, "error: modifier should have type POS_VALUE or NO_VALUE");
576         bOk = FALSE;
577     }
578     /* Check flags */
579     if (method->flags & (SMETH_SINGLEVAL | SMETH_VARNUMVAL))
580     {
581         report_error(fp, method->name, "error: modifier should not have SMETH_SINGLEVAL or SMETH_VARNUMVAL set");
582         bOk = FALSE;
583     }
584     /* Check the parameters */
585     /* The first parameter is skipped */
586     if (!check_params(fp, method->name, method->nparams-1, method->param+1, symtab))
587     {
588         bOk = FALSE;
589     }
590     /* Check the callback pointers */
591     if (!check_callbacks(fp, method))
592     {
593         bOk = FALSE;
594     }
595     if (method->update)
596     {
597         report_error(fp, method->name, "error: modifier should not have update");
598         bOk = FALSE;
599     }
600     if (method->type == POS_VALUE && !method->pupdate)
601     {
602         report_error(fp, method->name, "error: evaluation function missing");
603         bOk = FALSE;
604     }
605
606     return bOk;
607 }
608
609 /*!
610  * \param[in,out] sc     Selection collection to registered the method to.
611  * \param[in]     name   Name under which the method should be registered.
612  * \param[in]     method Method to register.
613  * \returns       0 on success, EINVAL if there was something wrong with the
614  *   method.
615  *
616  * \p name does not need to match the name of the method, and the same
617  * method can be registered multiple times under different names.
618  * If \p name equals some previously registered name,
619  * an error message is printed and the method is not registered.
620  *
621  * The function also performs some sanity checking on the input method,
622  * and refuses to register it if there are problems.
623  * Some problems only generate warnings.
624  * All problems are described to \p stderr.
625  */
626 int
627 gmx_ana_selmethod_register(struct gmx_ana_selcollection_t *sc,
628                            const char *name, gmx_ana_selmethod_t *method)
629 {
630     gmx_bool bOk;
631
632     /* Check the method */
633     if (method->flags & SMETH_MODIFIER)
634     {
635         bOk = check_modifier(stderr, method, sc->symtab);
636     }
637     else
638     {
639         bOk = check_method(stderr, method, sc->symtab);
640     }
641     /* Try to register the method if everything is ok */
642     if (bOk) 
643     {
644         if (!_gmx_sel_add_method_symbol(sc->symtab, name, method))
645         {
646             bOk = FALSE;
647         }
648     }
649     if (!bOk)
650     {
651         report_error(stderr, name, "warning: not registered");
652         return EINVAL;
653     }
654     return 0;
655 }
656
657 /*!
658  * \param[in,out] sc     Selection collection to registered the methods to.
659  * \returns       0 on success, -1 if any of the default methods could not be
660  *   registered.
661  */
662 int
663 gmx_ana_selmethod_register_defaults(struct gmx_ana_selcollection_t *sc)
664 {
665     size_t i;
666     int  rc;
667     gmx_bool bOk;
668
669     bOk = TRUE;
670     for (i = 0; i < asize(smtable_def); ++i)
671     {
672         gmx_ana_selmethod_t *method = smtable_def[i].method;
673
674         if (smtable_def[i].name == NULL)
675         {
676             rc = gmx_ana_selmethod_register(sc, method->name, method);
677         }
678         else
679         {
680             rc = gmx_ana_selmethod_register(sc, smtable_def[i].name, method);
681         }
682         if (rc != 0)
683         {
684             bOk = FALSE;
685         }
686     }
687     return bOk ? 0 : -1;
688 }
689
690 /*!
691  * \param[in] name   Name of the parameter to search.
692  * \param[in] method Method to search for the parameter.
693  * \returns   Pointer to the parameter in the
694  *   \ref gmx_ana_selmethod_t::param "method->param" array,
695  *   or NULL if no parameter with name \p name was found.
696  *
697  * This is a simple wrapper for gmx_ana_selparam_find().
698  */
699 gmx_ana_selparam_t *
700 gmx_ana_selmethod_find_param(const char *name, gmx_ana_selmethod_t *method)
701 {
702     return gmx_ana_selparam_find(name, method->nparams, method->param);
703 }