ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/xyz2pov/src/atom_parser.c
Revision: 61
Committed: Thu Aug 1 21:12:33 2002 UTC (21 years, 11 months ago) by mmeineke
Content type: text/plain
File size: 4001 byte(s)
Log Message:
This commit was generated by cvs2svn to compensate for changes in r60, which
included commits to RCS files with non-trunk default branches.

File Contents

# Content
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "atom_parser.h"
6
7
8 struct linked_atom *head_main;
9 struct linked_atom *head_inUse;
10 int n_inUse;
11
12 int findAtomType_internal(char *, struct atom *);
13
14 void initializeParser(){
15 char *token;
16 char *delim = "\t ,;";
17 struct linked_atom *temp_linked;
18 const int buffer_size = 300;
19 char lineBuffer[buffer_size];
20
21 char *in_filename;
22 char *in_file_env = "_xyz2pov_AtomTypes_";
23 FILE *in_file;
24
25 head_main = (struct linked_atom *)malloc(sizeof(struct linked_atom));
26 head_main->next = NULL;
27
28 head_inUse = (struct linked_atom *)malloc(sizeof(struct linked_atom));
29 head_inUse->next = NULL;
30
31 n_inUse = 0;
32
33 in_filename = getenv(in_file_env);
34
35 in_file = fopen(in_filename, "r");
36
37 if(in_file == NULL){
38
39 printf("Error reading AtomTypes file, is the _xyz2pov_AtomTypes_\n"
40 "enviorment variable set?\n");
41 exit(8);
42 }
43
44 while(fgets(lineBuffer, sizeof(lineBuffer), in_file) != NULL){
45
46 if(lineBuffer[0] == '#' || lineBuffer[0] == '\n'){
47 continue;
48 }
49
50 token = strtok(lineBuffer, delim);
51 sscanf(token, "%s", head_main->myAtom.name);
52 strtok(NULL, delim);
53 strtok(NULL, delim);
54 strtok(NULL, delim);
55 token = strtok(NULL, delim);
56 sscanf(token, "%lf", &head_main->myAtom.vanDerWallRadii);
57 token = strtok(NULL, delim);
58 sscanf(token, "%lf", &head_main->myAtom.covalentRadii);
59 token = strtok(NULL, delim);
60 sscanf(token, "%d", &head_main->myAtom.red);
61 token = strtok(NULL, delim);
62 sscanf(token, "%d", &head_main->myAtom.green);
63 token = strtok(NULL, delim);
64 sscanf(token, "%d", &head_main->myAtom.blue);
65
66 temp_linked = (struct linked_atom *)malloc(sizeof(struct linked_atom));
67 temp_linked->next = head_main;
68 head_main = temp_linked;
69 }
70
71 fclose(in_file);
72 return;
73 }
74
75
76 int findAtomType_internal(char *typeKey, struct atom *dummy_plug){
77
78 struct linked_atom *link;
79
80 link = head_main->next;
81
82 while(link != NULL){
83
84 if(!strcmp(link->myAtom.name, typeKey)){
85 strcpy(dummy_plug->name, link->myAtom.name);
86 dummy_plug->vanDerWallRadii = link->myAtom.vanDerWallRadii;
87 dummy_plug->covalentRadii = link->myAtom.covalentRadii;
88 dummy_plug->red = link->myAtom.red;
89 dummy_plug->green = link->myAtom.green;
90 dummy_plug->blue = link->myAtom.blue;
91
92 return 1;
93 }
94 link = link->next;
95 }
96 return 0;
97 }
98
99
100 void update_types(char *new_key){
101
102 int found = 0;
103
104 struct linked_atom *link;
105
106 link = head_inUse->next;
107
108 while(link != NULL){
109
110 if(!strcmp(link->myAtom.name, new_key)){
111 found = 1;
112 }
113
114 link = link->next;
115 }
116
117 if(!found){
118 found = findAtomType_internal(new_key, &head_inUse->myAtom);
119 if(!found){
120 fprintf(stderr, "Atom Type %s, not found!\n",
121 new_key);
122 exit(8);
123 }
124
125 link = (struct linked_atom *)malloc(sizeof(struct linked_atom));
126
127 link->next = head_inUse;
128 head_inUse = link;
129
130 n_inUse++;
131 }
132
133
134 }
135
136 int get_n_inUse(void){
137 return n_inUse;
138 }
139
140
141 int findAtomType(char *typeKey, struct atom *dummy_plug){
142
143 struct linked_atom *link;
144
145 link = head_inUse->next;
146
147 while(link != NULL){
148
149 if(!strcmp(link->myAtom.name, typeKey)){
150 strcpy(dummy_plug->name, link->myAtom.name);
151 dummy_plug->vanDerWallRadii = link->myAtom.vanDerWallRadii;
152 dummy_plug->covalentRadii = link->myAtom.covalentRadii;
153 dummy_plug->red = link->myAtom.red;
154 dummy_plug->green = link->myAtom.green;
155 dummy_plug->blue = link->myAtom.blue;
156
157 return 1;
158 }
159 link = link->next;
160 }
161 return 0;
162 }
163
164
165 struct linked_atom *get_type_list(){
166
167 return head_inUse;
168 }
169
170 void clean_type_list(){
171
172 struct linked_atom *current_atom;
173 struct linked_atom *next_atom; /* place holders */
174
175
176 current_atom = head_inUse->next;
177
178 while(current_atom != NULL){
179
180 next_atom = current_atom->next;
181 free(current_atom);
182 current_atom = next_atom;
183 }
184
185 head_inUse->next = NULL;
186 }