minor fixes in ditribution files
[gromacs/qmmm-gamess-us.git] / src / mdlib / gmx_qhop_parm.c
blob4fb43ba812af957854f7b778c4f0fd424cc23823
1 #include <stdlib.h>
2 #include <string.h>
3 #include "smalloc.h"
4 #include "string2.h"
6 #include "gmx_qhop_parm.h"
8 typedef struct gmx_qhop {
9 char *donor,*acceptor;
10 int nparam,nparam_c;
11 char **value,**unit,**name;
12 } gmx_qhop;
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()
20 struct gmx_qhop *qht;
22 snew(qht,1);
24 return qht;
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)
39 return gqh->donor;
42 char *gmx_qhop_get_acceptor(gmx_qhop_t gqh)
44 return gqh->acceptor;
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);
56 gqh->nparam++;
58 return 1;
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]);
69 gqh->nparam_c++;
71 return 1;
73 else
74 gqh->nparam_c = 0;
76 return 0;
79 /* Return a value corresponding to name */
80 int gmx_qhop_get_value(gmx_qhop_t gqh,char *name,double *x)
82 int i;
84 for(i=0; (i<gqh->nparam); i++)
85 if (gmx_strcasecmp(gqh->name[i],name) == 0) {
86 *x = strtod(gqh->value[i],NULL);
87 return 1;
90 return 0;
93 /* Liberate memory */
94 void gmx_qhop_done(gmx_qhop_t gqh)
96 int i;
98 for(i=0; (i<gqh->nparam); i++) {
99 sfree(gqh->name[i]);
100 sfree(gqh->value[i]);
101 sfree(gqh->unit[i]);
103 if (gqh->nparam > 0) {
104 sfree(gqh->name);
105 sfree(gqh->value);
106 sfree(gqh->unit);
108 if (gqh->donor)
109 sfree(gqh->donor);
110 if (gqh->acceptor)
111 sfree(gqh->acceptor);