2 * atom_match.c - match atoms and process
4 * author: frank.zirkelbach@physik.uni-augsburg.de
19 #define ME "[atom match]"
27 #define S_COL_NO_OVERRIDE 0
36 typedef int t_element;
38 typedef struct s_rule {
50 int parse_rule(t_am *am,char *line) {
61 wptr=strtok(NULL," ");
63 wptr=strtok(line," ");
66 strncpy(word[wcnt],wptr,64);
72 am->rule[am->count].params=malloc(sizeof(t_element));
73 element=am->rule[am->count].params;
75 printf("%s malloc (element).\n",ME);
78 *element=atoi(word[1]);
93 int parse_argv(int argc,char **argv,t_am *am) {
98 memset(am,0,sizeof(t_am));
101 for(i=1;i<argc;i++) {
102 if(argv[i][0]=='-') {
106 strncpy(am->infile,argv[++i],128);
110 am->rule[am->count].logic_op=LAND;
111 ret=parse_rule(am,argv[++i]);
116 am->rule[am->count].logic_op=LOR;
117 ret=parse_rule(am,argv[++i]);
121 // how to process data
124 printf("%s unknown switch: %s\n",
131 printf("%s unknown argument: %s\n",ME,argv[i]);
139 int main(int argc,char **argv) {
150 memset(&moldyn,0,sizeof(t_moldyn));
152 if(parse_argv(argc,argv,&am)<0) {
153 printf("%s aborted (bad args).\n",ME);
157 if(moldyn_read_save_file(&moldyn,am.infile)<0) {
158 printf("%s aborted (bad infile).\n",ME);
165 link_cell_init(&moldyn,VERBOSE);
167 /* alloc select status and color memory */
168 sel_atom=malloc(acnt*sizeof(u8));
170 printf("%s aborted (malloc failed).\n",ME);
173 sel_color=malloc(acnt*sizeof(u8));
174 if(sel_color==NULL) {
175 printf("%s aborted (malloc failed).\n",ME);
180 for(i=0;i<am.count;i++) {
182 /* initialize status and color in first run */
184 if(am.rule[0].logic_op==LAND)
185 memset(sel_atom,SELECT,acnt*sizeof(u8));
187 memset(sel_atom,UNSELECT,acnt*sizeof(u8));
191 switch(am.rule[i].type) {
194 if(am.rule[i].type==LAND)
196 if(atom[j].element==*e)
199 sel_atom[j]&=UNSELECT;
202 if(atom[j].element==*e)
206 printf("%s unknown rule %c -> skipped.\n",
214 if(sel_atom[i]==SELECT)
215 printf("%s %f %f %f %s %f\n",
216 pse_name[atom[i].element],
217 atom[i].r.x,atom[i].r.y,atom[i].r.z,
218 pse_col[atom[i].element],
221 /* exit and cleanup */
224 link_cell_shutdown(&moldyn);
225 moldyn_free_save_file(&moldyn);