-
Notifications
You must be signed in to change notification settings - Fork 2
/
namelist.c
122 lines (113 loc) · 2.82 KB
/
namelist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "headdefs.h"
NameList nameList[] = {
NameI (NumAtomType),
NameR (Temperature),
NameR (Alpha),
NameR (Stop),
NameR (Rcut),
NameR (Size),
NameI (Pts),
NameI (AtomType),
NameI (HS_size_approximation),
NameI (Approx_excess_free_energy),
};
#define NP_I ((int *) (nameList[k].vPtr) + j)
#define NP_R ((double *) (nameList[k].vPtr) + j)
int GetNameList (int argc, char **argv)
{
int j, k, match, ok;
char buff[80], *token;
FILE *fp;
strcpy (buff, argv[0]);
strcat (buff, ".in");
if ((fp = fopen (buff, "r")) == 0) return (0);
for (k = 0; k < sizeof (nameList) / sizeof (NameList); k ++)
nameList[k].vStatus = 0;
ok = 1;
while (1) {
fgets (buff, 80, fp);
if (feof (fp)) break;
token = strtok (buff, " \t\n");
if (! token) break;
match = 0;
for (k = 0; k < sizeof (nameList) / sizeof (NameList); k ++) {
if (strcmp (token, nameList[k].vName) == 0) {
match = 1;
if (nameList[k].vStatus == 0) {
nameList[k].vStatus = 1;
for (j = 0; j < nameList[k].vLen; j ++) {
token = strtok (NULL, ", \t\n");
if (token) {
switch (nameList[k].vType) {
case N_I:
*NP_I = atol (token);
break;
case N_R:
*NP_R = atof (token);
break;
}
} else {
nameList[k].vStatus = 2;
ok = 0;
}
}
token = strtok (NULL, ", \t\n");
if (token) {
nameList[k].vStatus = 3;
ok = 0;
}
break;
} else {
nameList[k].vStatus = 4;
ok = 0;
}
}
}
if (! match) ok = 0;
}
fclose (fp);
for (k = 0; k < sizeof (nameList) / sizeof (NameList); k ++) {
if (nameList[k].vStatus != 1) ok = 0;
}
return (ok);
}
void PrintNameList (FILE *fp)
{
int j, k;
fprintf (fp, "NameList -- data\n");
for (k = 0; k < sizeof (nameList) / sizeof (NameList); k ++) {
fprintf (fp, "%s\t", nameList[k].vName);
if (strlen (nameList[k].vName) < 8) fprintf (fp, "\t");
if (nameList[k].vStatus > 0) {
for (j = 0; j < nameList[k].vLen; j ++) {
switch (nameList[k].vType) {
case N_I:
fprintf (fp, "%d ", *NP_I);
break;
case N_R:
fprintf (fp, "%#g ", *NP_R);
break;
}
}
}
switch (nameList[k].vStatus) {
case 0:
fprintf (fp, "** no data");
break;
case 1:
break;
case 2:
fprintf (fp, "** missing data");
break;
case 3:
fprintf (fp, "** extra data");
break;
case 4:
fprintf (fp, "** multiply defined");
break;
}
fprintf (fp, "\n");
}
fprintf (fp, "----\n");
fflush (fp);
}