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