6 #include "gmx_qhop_parm.h"
8 typedef struct gmx_qhop
{
11 char **value
,**unit
,**name
;
14 #define assign_str(dst,src) if (NULL != src) { if (NULL != dst) *dst = strdup(src); } else { *dst = NULL; }
15 #define assign_scal(dst,src) if (NULL != dst) *dst = src
17 /* Return a new gmx_qhop structure */
18 gmx_qhop_t
gmx_qhop_init()
27 void gmx_qhop_set_donor(gmx_qhop_t gqh
,char *donor
)
29 gqh
->donor
= strdup(donor
);
32 void gmx_qhop_set_acceptor(gmx_qhop_t gqh
,char *acceptor
)
34 gqh
->acceptor
= strdup(acceptor
);
37 char *gmx_qhop_get_donor(gmx_qhop_t gqh
)
42 char *gmx_qhop_get_acceptor(gmx_qhop_t gqh
)
47 /* Add parameter to gqh, return 1 if OK, 0 if not OK */
48 int gmx_qhop_add_param(gmx_qhop_t gqh
,char *name
,char *value
,char *unit
)
50 srenew(gqh
->name
,gqh
->nparam
+1);
51 srenew(gqh
->value
,gqh
->nparam
+1);
52 srenew(gqh
->unit
,gqh
->nparam
+1);
53 gqh
->name
[gqh
->nparam
] = strdup(name
);
54 gqh
->value
[gqh
->nparam
] = strdup(value
);
55 gqh
->unit
[gqh
->nparam
] = strdup(unit
);
61 /* Lists the parameters, one by one on repeatedly calling the
62 function. Returns 1 if OK, 0 if not OK */
63 int gmx_qhop_get_param(gmx_qhop_t gqh
,char **name
,char **value
,char **unit
)
65 if (gqh
->nparam_c
< gqh
->nparam
) {
66 assign_str(name
,gqh
->name
[gqh
->nparam_c
]);
67 assign_str(value
,gqh
->value
[gqh
->nparam_c
]);
68 assign_str(unit
,gqh
->unit
[gqh
->nparam_c
]);
79 /* Return a value corresponding to name */
80 int gmx_qhop_get_value(gmx_qhop_t gqh
,char *name
,double *x
)
84 for(i
=0; (i
<gqh
->nparam
); i
++)
85 if (gmx_strcasecmp(gqh
->name
[i
],name
) == 0) {
86 *x
= strtod(gqh
->value
[i
],NULL
);
94 void gmx_qhop_done(gmx_qhop_t gqh
)
98 for(i
=0; (i
<gqh
->nparam
); i
++) {
100 sfree(gqh
->value
[i
]);
103 if (gqh
->nparam
> 0) {
111 sfree(gqh
->acceptor
);