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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
// Copyright 2004, 2007 Nanorex, Inc. See LICENSE file for details.
//====================================================================//
/* Program to compare two mmp files.
Program Arguments: two mmp files.
Details:
Small differences in the atom positions in the mmp file are neglected
The Tolerence value for the atom positions in |5|
main() is in this file itself. This is an independent program
-Ninad Sathaye,
Nanorex Inc.
Date: August 12, 2004
*/
//===================================================================//
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
FILE *file1;
FILE *file2;
FILE *pOutFile;
# define PART 1
# define ATOM 2
# define BOND 3
# define GRND 4
# define MOTOR 5
# define LINMOT 6
# define SHAFT 7
# define BEARING 8
# define SHOW 9
# define END 10
# define OTHERS 11
int gSpaceAtom[]= { 2,3,2,2,0}; // This array is defining the 'empty spaces' between the two
// entries , in a line starting with 'atom' :-)
char * gStringArray[]= {"def", "nil", "lin", "cpk", "tub", "mix", "vdw"};//These are the valid codes
//after 'show' word in mmp file
int parse(char * psCnt)
{
if (0==strncmp(psCnt,"part",4))
return PART ;
else if (0==strncmp(psCnt,"atom",4))
return ATOM;
else if (0==strncmp(psCnt,"bond",4))
return BOND;
else if (0==strncmp(psCnt,"ground",6))
return GRND;
else if (0==strncmp(psCnt,"motor",5))
return MOTOR;
else if (0==strncmp(psCnt,"linmotor",8))
return LINMOT;
else if (0==strncmp(psCnt,"shaft",5))
return SHAFT;
else if (0==strncmp(psCnt,"bearing",7))
return BEARING;
else if (0==strncmp(psCnt,"show",4))
return SHOW;
else if (0==strncmp(psCnt,"end",3))
return END;
else return OTHERS;
}
void main (int argc, char *argv[])
{
int i;
int check1,check2; //required in case SHOW
// int nExit;
int ntemp=0; //this is temp.
char filename1[100],filename2[100];
char buf1[128],buf2[128];
char *pBuf1= buf1;
char *pBuf2=buf2;
char *psTok1;//used as StiringTokens
char *psTok2;
long l1, l2;
char *pFile1;
char *pFile2;
pOutFile=fopen ("mmpsCompared.txt","w");
fprintf(pOutFile,"***\tProgram for comparing two mmp files\t***\n\n");
fprintf(pOutFile,"Small differences in atom positions are ignored (Tolerence=5)\n");
fprintf(pOutFile,"Differences in theh 'show' mode are ignored but still check for valid codes such as lin, vdw etc.:\n\n");
fprintf(pOutFile,"Input mmp files are as follows:\n");
fprintf(pOutFile,"File1: %s\t File2: %s\n\n\n",argv[1],argv[2]);
if(argc==3)
{
strcpy(filename1, argv[1]);
strcpy(filename2, argv[2]);
}
else
{
printf("***Program for comparing two mmp files***");
printf("This program needs exactly two arguments and you are seeing this message because \n either those were not provided or more than 2 args were given .\n");
printf("Please provide the two file names to compare and run the program again");
exit(1);
}
file1=fopen(filename1,"r");
file2=fopen(filename2,"r");
i=0;
printf("BEFORE the while loop /n");
pFile1 = fgets(buf1,127,file1);
pFile2 = fgets(buf2,127,file2);
while(pFile1 || pFile2)
{
pBuf1 = buf1;
pBuf2 = buf2;
switch (parse(pBuf1))
{
case PART :
{
break;
}
case BOND :
{
if(0 != strcmp(pBuf1,pBuf2))
{
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
}
case ATOM :
{
pBuf1+=5;
pBuf2+=5;
for (i=0;i<5;i++)
{
l1= strtol(pBuf1,&pBuf1,10);
l2 = strtol(pBuf2,&pBuf2,10);
if (l1 !=l2 && i<2)
{
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
else if (i>=2 && labs(l1-l2) >5)
{
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
pBuf1+=gSpaceAtom[i];
pBuf2+=gSpaceAtom[i];
}
break ;
}
case GRND :
{
if(0 != strcmp(pBuf1,pBuf2))
{
printf("IN the GRND case \n");
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
break;
}
case MOTOR :
{
if(0 != strcmp(pBuf1,pBuf2))
{
printf("IN the MOTOR case \n");
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
break;
}
case LINMOT :
{
if(0 != strcmp(pBuf1,pBuf2))
{
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
break;
}
case SHAFT :
{
if(0 != strcmp(pBuf1,pBuf2))
{
printf("IN the SHAFT case \n");
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
break;
}
case BEARING :
{
if(0 != strcmp(pBuf1,pBuf2))
{
printf("IN the BEARING case \n");
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
break;
}
case SHOW :
{
ntemp++; //this is for debug
pBuf1+=5;
pBuf2+=5;
psTok1=strtok(pBuf1," ");
psTok2=strtok(pBuf2," ");
check1=check2=0;
for (i=0;i<7;i++)
{
if (0==strncmp(psTok1,gStringArray[i], strlen(gStringArray[i]))) check1=1;
if (0==strncmp(psTok2,gStringArray[i], strlen(gStringArray[i]))) check2=1;
}
if(check1!=1 || check2!=1)
{
printf("In the SHOW case\t ntemp=%d\n",ntemp);
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
break;
}
case END :
{
break;
}
case OTHERS : //These are the ones that are not a standard part of mmp files So print those buffers
{
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
}
pFile1 = fgets(buf1,127,file1);
pFile2 = fgets(buf2,127,file2);
}
fclose(file1);
fclose(file2);
fclose(pOutFile);
}
/* case BOND :
{
nExit=0; //To get out of while loop in case a mismatch is found
//so that no further checking is required. (nExit =1)
pBuf1+=4;
pBuf2+=4;
psTok1=strtok(pBuf1," ");
psTok2=strtok(pBuf2," ");
while(psTok1!=NULL && psTok2!=NULL && nExit==0)
{
if(0!= strcmp(psTok1,psTok2))
{
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
nExit=1;
}
//Get the next tokens
psTok1=strtok(psTok1+strlen(psTok1)+1," ");
psTok2=strtok(psTok2+strlen(psTok2)+1," ");
}
break;
}*/
/* case BOND :
{
nExit=0; //To get out of while loop in case a mismatch is found
//so that no further checking is required. (nExit =1)
pBuf1+=4;
pBuf2+=4;
while(pBuf1!=NULL || pBuf2 !=NULL)
{
if(*pBuf1++!=*pBuf2))
{
fprintf(pOutFile,"==\n");
fprintf(pOutFile,"file 1 : %sfile 2 : %s",buf1,buf2);
break;
}
while(pBuf1 ==" " && *pBuf1 != '\0') pBuf1+=1;
while(pBuf2==" " && *pBuf2 != '\0') pBuf2+=1;
}
break;
}*/
|