1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
10 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
11 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
12 * Copyright (c) 2001-2008, The GROMACS development team,
13 * check out http://www.gromacs.org for more information.
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * If you want to redistribute modifications, please consider that
21 * scientific software is very special. Version control is crucial -
22 * bugs must be traceable. We will be happy to consider code for
23 * inclusion in the official distribution, but derived work must not
24 * be called official GROMACS. Details are found in the README & COPYING
25 * files - if they are missing, get the official version at www.gromacs.org.
27 * To help us fund GROMACS development, we humbly ask that you cite
28 * the papers on the package - you can find them in the top README file.
30 * For more info, check our website at http://www.gromacs.org
33 * Groningen Machine for Chemical Simulation
44 #include "gmx_qhop_parm.h"
46 typedef struct gmx_qhop {
47 char *donor,*acceptor;
49 char **value,**unit,**name;
52 #define assign_str(dst,src) if (NULL != src) { if (NULL != dst) *dst = strdup(src); } else { *dst = NULL; }
53 #define assign_scal(dst,src) if (NULL != dst) *dst = src
55 /* Return a new gmx_qhop structure */
56 gmx_qhop_t gmx_qhop_init()
65 void gmx_qhop_set_donor(gmx_qhop_t gqh,char *donor)
67 gqh->donor = strdup(donor);
70 void gmx_qhop_set_acceptor(gmx_qhop_t gqh,char *acceptor)
72 gqh->acceptor = strdup(acceptor);
75 char *gmx_qhop_get_donor(gmx_qhop_t gqh)
80 char *gmx_qhop_get_acceptor(gmx_qhop_t gqh)
85 /* Add parameter to gqh, return 1 if OK, 0 if not OK */
86 int gmx_qhop_add_param(gmx_qhop_t gqh,char *name,char *value,char *unit)
88 srenew(gqh->name,gqh->nparam+1);
89 srenew(gqh->value,gqh->nparam+1);
90 srenew(gqh->unit,gqh->nparam+1);
91 gqh->name[gqh->nparam] = strdup(name);
92 gqh->value[gqh->nparam] = strdup(value);
93 gqh->unit[gqh->nparam] = strdup(unit);
99 /* Lists the parameters, one by one on repeatedly calling the
100 function. Returns 1 if OK, 0 if not OK */
101 int gmx_qhop_get_param(gmx_qhop_t gqh,char **name,char **value,char **unit)
103 if (gqh->nparam_c < gqh->nparam) {
104 assign_str(name,gqh->name[gqh->nparam_c]);
105 assign_str(value,gqh->value[gqh->nparam_c]);
106 assign_str(unit,gqh->unit[gqh->nparam_c]);
117 /* Return a value corresponding to name */
118 int gmx_qhop_get_value(gmx_qhop_t gqh,char *name,double *x)
122 for(i=0; (i<gqh->nparam); i++)
123 if (gmx_strcasecmp(gqh->name[i],name) == 0) {
124 *x = strtod(gqh->value[i],NULL);
131 /* Liberate memory */
132 void gmx_qhop_done(gmx_qhop_t gqh)
136 for(i=0; (i<gqh->nparam); i++) {
138 sfree(gqh->value[i]);
141 if (gqh->nparam > 0) {
149 sfree(gqh->acceptor);