1 
2 #if defined(DARWIN) || defined(FREEBSD) || defined(__DragonFly__)
3 #else
4 #include <malloc.h>
5 #endif
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <signal.h>
10 #include <math.h>
11 
12 #if defined(VMS) || defined(UNDERSC)
13 void wrtesc();
14 void wrdesc();
15 #else
16 #ifdef CRAY
17 void WRTESC();
18 void WRDESC();
19 #else
20 void wrtesc_();
21 void wrdesc_();
22 #endif
23 #endif
24 
25 static int ctrlCset = 0;
26 void catch22(int sig);
27 static int *iwesc;
28 static int *nproc;
29 static int *taskid;
30 static int *lammps;
31 
32 #define NUMAT 2000
33 #define MAXBND  2*NUMAT
34 #define MAXANG  3*NUMAT
35 #define MAXTORS 4*NUMAT
36 #define MXCON 10
37 #define MAX13 MXCON*3
38 #define MAX14 MXCON*9
39 #define NUMADD 50000
40 #define NUMRES 10000
41 static int addat = NUMADD;
42 #define MSAVE 7
43 #define MXGFF 72
44 #define MXGTOR 638
45 #define MXGITR 42
46 
47 #define ABS(a) (((a) > 0) ? (a) : (-(a)))
48 
49 static float *gffvdw;
50 
51 static float *gffmas;
52 
53 typedef struct { float gftor1[MXGTOR][2];
54 		 float gftor2[MXGTOR][2];
55 		 float gftor3[MXGTOR][2];
56 		 float gftor4[MXGTOR][2];
57                } TORSTRU;
58 
59 static TORSTRU *torptr;
60 
61 typedef struct { float gftri1[MXGITR][2];
62 		 float gftri2[MXGITR][2];
63                } ITORSTRU;
64 
65 static ITORSTRU *itorptr;
66 
67 typedef struct { float coo[NUMAT][3];
68 		 float ctmp[NUMAT][3];
69 		 float q[NUMAT];
70 		 float fr[NUMAT][3];
71 		 float ftmp[NUMAT];
72 		 int iaton[NUMAT];
73 		 int iopt[NUMAT];
74 		 int n13[NUMAT];
75 		 int i13[NUMAT][MAX13];
76 		 int n14[NUMAT];
77 		 int i14[NUMAT][MAX14];
78 		 int iresid[NUMAT];
79 		 int iconn[NUMAT][MXCON+1];
80 		 short int ityp[NUMAT];
81 
82                } ATOMSTRU;
83 
84 static ATOMSTRU *atomptr;
85 
86 typedef struct {
87 		  float bl[MAXBND];
88 		  float bk[MAXBND];
89 		  float ango[MAXANG];
90 		  float ak[MAXANG];
91 		  float trs1[MAXTORS][4];
92 		  float trs2[MAXTORS][4];
93 		  float trs3[MAXTORS][4];
94 		  float trs4[MAXTORS][4];
95 		  int itor[MAXTORS];
96 		  float trsi1[MAXTORS][4];
97 		  float trsi2[MAXTORS][4];
98 		  int imptor[MAXTORS];
99 		  int maxbnd;
100 		  int maxang;
101 		  int maxtors;
102 		  int nbnd;
103 		  int ibnd[MAXBND][2];
104 		  int nang;
105 		  int iang[MAXANG][3];
106 		  int nt;
107 		  int it[MAXTORS][4];
108 		  int nti;
109 		  int iti[MAXTORS][4];
110                } FORSTRU;
111 
112 static FORSTRU *forvarptr;
113 
114 typedef struct { float coot[NUMAT][3];
115 		 float fort[NUMAT][3];
116 		 float zr[NUMAT][3];
117 		 float y[NUMAT][3];
118 		 float yt[NUMAT][3];
119 		 float pt[NUMAT][3];
120 		 float s[NUMAT][3];
121                } OPTSCRSTRU;
122 
123 static OPTSCRSTRU *optscr;
124 
125 typedef struct { float *coo;
126 		 float *ctmp;
127 		 float *q;
128 		 float *fr;
129 		 float *ftmp;
130 		 float *coot;
131 		 float *frt;
132 		 float *zr;
133 		 float *y;
134 		 float *yt;
135 		 float *pt;
136 		 float *s;
137 		 int *iaton;
138 		 int *iopt;
139 		 int *n13;
140 		 int *i13;
141 		 int *n14;
142 		 int *i14;
143 		 int *iconn;
144 		 int *iresid;
145 		 short int *ityp;
146 		 int *nbnd;
147 		 int *nang;
148 		 int *nt;
149 		 int *nti;
150 		 int *ibnd;
151 		 int *iang;
152 		 int *it;
153 		 int *iti;
154 		 int *watprot;
155 		 float *bl;
156 		 float *bk;
157 		 float *ango;
158 		 float *ak;
159 		 float *trs1;
160 		 float *trs2;
161 		 float *trs3;
162 		 float *trs4;
163 		 int *itor;
164 		 float *trsi1;
165 		 float *trsi2;
166 		 int *imptor;
167 		 float *work;
168 		 int *mxnat;
169 		 int *iatoms;
170 		 int mxorg;
171 		 int *maxbnd;
172 		 int *maxang;
173 		 int *maxtors;
174                } COOSTRU;
175 
176 static COOSTRU xyz;
177 static COOSTRU TMPxyz;
178 
179 typedef struct { float *v;
180 		 float *a;
181 		 float *m;
182                } MDSTRU;
183 
184 static MDSTRU md;
185 
186 #define MXNEIB 200
187 static int *nlst = NULL;
188 static int *lst = NULL;
189 
190 static float water[648][3] = {
191       3.009,    6.289,    1.536,
192       2.346,    5.879,    2.126,
193       2.541,    6.968,    1.000,
194       2.147,    3.888,   -7.775,
195       2.450,    3.249,   -7.100,
196       1.818,    3.297,   -8.479,
197      -0.200,    3.894,    7.128,
198      -0.006,    3.280,    7.875,
199      -0.614,    3.297,    6.466,
200       5.038,   -5.416,   -6.189,
201       4.421,   -5.875,   -6.806,
202       5.509,   -4.776,   -6.766,
203      -2.797,   -3.106,    7.212,
204      -3.242,   -3.604,    7.924,
205      -3.295,   -3.471,    6.443,
206      -1.191,    6.280,    8.994,
207      -0.626,    6.780,    8.379,
208      -0.577,    5.706,    9.484,
209      -7.041,    6.418,    7.260,
210      -6.964,    6.968,    6.458,
211      -7.539,    6.996,    7.871,
212      -1.185,    6.280,    1.920,
213      -1.048,    6.013,    0.967,
214      -1.614,    5.510,    2.316,
215       7.841,   -7.248,   -7.751,
216       7.528,   -6.641,   -7.072,
217       7.873,   -6.639,   -8.549,
218       8.126,    8.499,   -0.316,
219       8.639,    9.076,    0.293,
220       8.789,    8.211,   -0.977,
221       6.718,   -8.969,    7.092,
222       7.277,   -8.669,    7.851,
223       6.069,   -8.242,    6.961,
224       6.637,   -7.256,   -0.316,
225       7.087,   -6.641,    0.286,
226       6.138,   -6.678,   -0.932,
227       3.374,   -4.346,   -8.071,
228       2.557,   -4.509,   -8.589,
229       3.955,   -3.844,   -8.702,
230      -4.259,   -3.031,   -5.785,
231      -3.817,   -2.309,   -5.289,
232      -4.916,   -3.372,   -5.128,
233       4.833,    3.894,   -4.259,
234       5.485,    3.351,   -4.793,
235       4.429,    3.239,   -3.659,
236      -3.024,    4.023,    7.219,
237      -3.231,    4.544,    6.429,
238      -3.175,    4.678,    7.908,
239       1.969,   -0.811,    4.987,
240       2.544,   -0.513,    5.719,
241       2.542,   -1.352,    4.409,
242      -6.207,   -5.387,   -1.870,
243      -6.566,   -4.648,   -1.357,
244      -6.767,   -6.124,   -1.549,
245       2.034,   -4.164,    5.170,
246       2.544,   -3.631,    5.784,
247       1.456,   -4.609,    5.815,
248       3.103,   -7.256,    9.173,
249       2.745,   -8.058,    9.597,
250       2.629,   -6.554,    9.649,
251       6.513,   -0.807,   -4.193,
252       6.069,   -1.529,   -3.707,
253       6.069,   -0.028,   -3.792,
254       5.208,   -8.757,    1.476,
255       5.684,   -8.374,    0.696,
256       5.684,   -8.284,    2.204,
257      -2.684,    1.973,   -4.268,
258      -3.242,    2.479,   -4.894,
259      -3.292,    1.512,   -3.659,
260       0.641,    6.289,    5.157,
261       0.387,    5.519,    5.701,
262       0.455,    7.002,    5.787,
263      -0.219,   -0.811,    3.176,
264       0.318,   -0.964,    3.993,
265       0.277,   -0.123,    2.696,
266       0.944,   -3.022,    1.825,
267       0.397,   -3.805,    2.059,
268       0.466,   -2.326,    2.323,
269      -1.193,    9.784,    7.092,
270      -0.614,    9.289,    6.474,
271      -1.728,   10.288,    6.446,
272      -1.494,   -7.248,    5.042,
273      -1.612,   -6.678,    4.262,
274      -1.881,   -6.678,    5.743,
275       1.018,    7.300,   -2.181,
276       1.770,    7.611,   -2.708,
277       0.316,    7.411,   -2.844,
278       6.513,   -5.358,    7.239,
279       5.906,   -6.056,    7.581,
280       6.069,   -5.005,    6.443,
281      -5.868,   -5.591,   -4.383,
282      -5.336,   -6.135,   -4.985,
283      -5.588,   -5.940,   -3.504,
284       8.119,   -0.753,    5.056,
285       8.439,   -0.120,    4.389,
286       7.582,   -0.184,    5.651,
287       1.015,   -8.918,   -6.247,
288       1.828,   -9.338,   -6.614,
289       0.334,   -9.361,   -6.768,
290      -2.931,   -8.757,    1.666,
291      -3.242,   -9.488,    2.215,
292      -3.178,   -7.998,    2.215,
293      -6.310,   -0.786,   -2.263,
294      -6.575,   -0.054,   -2.855,
295      -6.575,   -1.533,   -2.843,
296       3.332,    2.063,   -0.316,
297       3.947,    2.756,   -0.683,
298       2.736,    2.601,    0.253,
299      -4.477,   -5.167,   -9.459,
300      -5.033,   -4.539,   -8.944,
301      -4.889,   -6.010,   -9.164,
302      -2.581,   -0.811,    5.051,
303      -2.214,   -1.362,    4.325,
304      -2.259,   -1.311,    5.830,
305       5.146,    7.419,    3.176,
306       5.672,    7.841,    2.483,
307       5.626,    7.654,    3.989,
308      -5.993,    3.894,   -8.722,
309      -6.767,    3.313,   -8.902,
310      -5.289,    3.223,   -8.655,
311      -2.566,   -2.739,    3.134,
312      -1.899,   -2.343,    2.544,
313      -3.324,   -2.824,    2.504,
314       6.717,    6.280,   -4.324,
315       6.974,    5.847,   -3.485,
316       7.050,    5.659,   -4.985,
317      -4.198,    5.067,   -2.051,
318      -3.626,    5.828,   -1.882,
319      -3.747,    4.452,   -1.460,
320      -8.592,    8.506,   -2.263,
321      -8.754,    7.762,   -2.865,
322      -8.923,    9.233,   -2.836,
323      -8.410,    3.946,   -6.152,
324      -8.994,    4.454,   -5.562,
325      -8.982,    3.300,   -6.612,
326      -8.366,    6.289,    4.987,
327      -8.933,    6.738,    5.651,
328      -8.998,    5.815,    4.408,
329       1.018,    8.499,    7.264,
330       1.666,    8.044,    7.851,
331       0.522,    9.084,    7.873,
332       1.018,   -0.580,   -2.447,
333       0.785,   -0.484,   -1.476,
334       0.334,   -0.051,   -2.870,
335       9.085,    3.894,    1.557,
336       9.548,    3.278,    0.957,
337       8.697,    3.280,    2.206,
338      -1.191,    6.280,   -0.553,
339      -1.659,    6.984,   -1.062,
340      -1.249,    5.534,   -1.182,
341      -4.347,   -7.302,    4.987,
342      -3.821,   -7.868,    4.389,
343      -4.916,   -6.752,    4.389,
344       5.146,    2.054,    8.732,
345       5.285,    2.399,    9.646,
346       5.548,    2.758,    8.200,
347      -8.295,   -4.318,    5.042,
348      -8.853,   -3.844,    4.371,
349      -8.913,   -4.499,    5.770,
350       3.443,   -0.811,    9.276,
351       4.051,   -1.457,    8.872,
352       4.029,   -0.126,    9.644,
353      -0.247,   -7.337,    8.994,
354      -0.608,   -7.890,    8.246,
355      -0.614,   -7.843,    9.747,
356      -6.301,   -3.031,   -4.259,
357      -6.287,   -3.649,   -3.511,
358      -6.767,   -3.582,   -4.921,
359       3.210,   -8.998,    3.089,
360       4.016,   -9.166,    2.543,
361       2.544,   -9.432,    2.543,
362      -4.272,    7.635,    7.218,
363      -4.916,    7.183,    7.805,
364      -3.555,    7.787,    7.857,
365       4.759,   -5.549,   -2.071,
366       4.269,   -5.794,   -2.885,
367       4.226,   -6.024,   -1.409,
368      -7.114,   -0.895,    1.536,
369      -6.860,   -1.431,    2.307,
370      -6.769,   -1.431,    0.797,
371       1.025,    2.061,   -3.850,
372       0.277,    2.633,   -3.591,
373       1.695,    2.451,   -3.252,
374      -2.797,   -5.416,    1.278,
375      -3.242,   -4.585,    1.051,
376      -3.230,   -6.033,    0.670,
377       5.078,   -0.811,    3.062,
378       5.504,   -0.478,    3.896,
379       5.716,   -1.431,    2.655,
380      -4.289,    1.759,    4.869,
381      -5.022,    1.340,    4.389,
382      -3.525,    1.359,    4.417,
383       2.036,   -0.811,   -6.158,
384       2.491,   -1.060,   -5.317,
385       2.478,   -1.431,   -6.768,
386       9.139,   -0.855,    8.994,
387       9.544,   -1.462,    9.649,
388       8.697,   -1.494,    8.392,
389       3.332,    6.289,    4.987,
390       3.869,    5.725,    4.389,
391       2.749,    6.800,    4.389,
392      -2.652,    2.054,   -0.646,
393      -2.740,    2.161,    0.345,
394      -3.242,    1.317,   -0.855,
395       6.697,    1.824,    1.239,
396       7.516,    1.314,    1.088,
397       6.069,    1.400,    0.633,
398       8.194,    2.054,   -2.004,
399       8.652,    1.414,   -1.422,
400       7.696,    2.624,   -1.395,
401       9.064,   -3.090,   -7.486,
402       8.308,   -3.582,   -7.106,
403       9.760,   -3.639,   -7.104,
404      -5.865,    6.280,   -4.268,
405      -5.281,    5.828,   -3.610,
406      -5.282,    6.972,   -4.673,
407       8.119,   -5.358,    9.159,
408       8.703,   -4.655,    9.483,
409       7.706,   -4.975,    8.341,
410       9.064,    5.265,    9.068,
411       8.777,    4.720,    8.288,
412       9.626,    4.664,    9.576,
413       4.970,    0.553,    5.157,
414       4.394,    0.840,    5.902,
415       4.600,    1.068,    4.389,
416      -4.304,   -7.256,   -0.152,
417      -3.809,   -7.919,    0.404,
418      -4.916,   -6.787,    0.455,
419       3.290,    0.341,    1.575,
420       3.799,    0.884,    0.933,
421       3.975,   -0.027,    2.204,
422      -9.584,    2.063,    4.891,
423     -10.319,    2.486,    4.417,
424      -8.845,    2.540,    4.486,
425      -8.401,    6.280,   -4.140,
426      -8.939,    5.690,   -3.589,
427      -7.492,    5.938,   -3.954,
428      -6.033,   -2.920,    7.239,
429      -6.566,   -2.343,    6.648,
430      -5.505,   -2.314,    7.805,
431       4.833,   -7.337,    7.205,
432       4.277,   -7.666,    7.954,
433       4.277,   -7.632,    6.443,
434      -6.016,   -0.558,    5.215,
435      -5.266,   -0.178,    5.719,
436      -6.767,   -0.182,    5.721,
437      -8.293,    5.344,   -0.243,
438      -8.992,    5.154,    0.408,
439      -7.577,    5.661,    0.336,
440       1.024,    6.094,   -4.390,
441       1.769,    5.828,   -4.957,
442       1.270,    5.727,   -3.523,
443       5.109,    2.054,   -7.383,
444       5.547,    1.362,   -6.856,
445       4.291,    2.248,   -6.856,
446       8.120,    3.940,    7.050,
447       7.571,    4.468,    6.446,
448       8.559,    3.280,    6.469,
449      -8.293,    0.312,    7.100,
450      -8.920,    0.113,    6.390,
451      -8.781,   -0.052,    7.889,
452      -4.272,   -7.567,    8.767,
453      -4.947,   -7.962,    8.166,
454      -3.858,   -6.839,    8.239,
455      -4.361,    6.200,   -9.292,
456      -5.079,    5.657,   -8.902,
457      -3.575,    5.766,   -8.906,
458      -0.226,    8.499,    3.219,
459       0.228,    7.879,    3.832,
460      -0.591,    7.879,    2.543,
461       4.950,   -5.295,    1.374,
462       4.400,   -5.193,    2.204,
463       4.364,   -4.885,    0.714,
464      -1.470,   -5.416,    7.014,
465      -0.719,   -5.791,    6.500,
466      -1.728,   -4.632,    6.489,
467      -4.321,    6.280,    1.476,
468      -4.882,    5.729,    2.079,
469      -3.679,    5.664,    1.084,
470       4.915,    2.061,    3.104,
471       5.688,    1.857,    2.523,
472       4.394,    2.669,    2.543,
473      -0.849,   -5.416,   -2.240,
474      -0.614,   -6.164,   -2.810,
475      -0.726,   -4.648,   -2.812,
476      -8.286,   -5.416,   -5.845,
477      -9.076,   -5.607,   -5.289,
478      -7.615,   -5.912,   -5.320,
479      -2.613,   -2.010,   -2.071,
480      -2.260,   -1.548,   -2.865,
481      -1.792,   -2.308,   -1.627,
482      -7.324,   -7.252,   -7.809,
483      -7.610,   -6.654,   -7.096,
484      -7.485,   -6.678,   -8.596,
485      -2.674,   -7.256,   -7.775,
486      -3.026,   -6.641,   -7.096,
487      -3.223,   -7.012,   -8.558,
488       9.092,    0.553,   -4.153,
489       9.626,    0.717,   -4.973,
490       9.543,    1.162,   -3.540,
491      -8.366,   -7.256,   -1.853,
492      -8.923,   -6.552,   -1.453,
493      -8.845,   -8.034,   -1.516,
494       6.658,   -7.615,    3.465,
495       5.937,   -7.910,    4.043,
496       7.419,   -7.985,    3.951,
497       3.424,    8.708,   -6.135,
498       3.902,    9.127,   -5.382,
499       3.701,    7.778,   -6.001,
500      -5.868,    3.946,   -6.019,
501      -5.454,    4.663,   -5.491,
502      -6.649,    4.394,   -6.445,
503       1.018,   -3.031,   -4.351,
504       0.619,   -2.338,   -4.922,
505       1.694,   -3.482,   -4.921,
506       3.317,   -7.256,    5.004,
507       3.750,   -6.643,    4.371,
508       2.888,   -7.910,    4.389,
509       5.192,    4.964,    8.998,
510       5.311,    5.495,    8.164,
511       5.745,    5.467,    9.644,
512      -5.993,   -5.287,    3.841,
513      -5.276,   -4.703,    4.167,
514      -6.767,   -4.858,    4.286,
515      -5.980,   -3.967,   -7.654,
516      -5.282,   -3.655,   -7.028,
517      -6.724,   -4.231,   -7.095,
518      -2.686,    6.359,    5.042,
519      -3.178,    6.968,    5.651,
520      -2.237,    6.968,    4.414,
521       3.443,   -3.032,   -5.950,
522       3.593,   -3.587,   -6.768,
523       3.857,   -3.620,   -5.281,
524       3.573,    6.289,   -2.475,
525       3.957,    7.109,   -2.844,
526       4.198,    5.653,   -2.852,
527      -2.652,    7.485,   -2.271,
528      -3.402,    7.825,   -2.810,
529      -1.917,    7.762,   -2.867,
530      -8.286,    0.553,   -0.724,
531      -7.755,    1.328,   -0.975,
532      -7.686,   -0.146,   -1.041,
533       4.896,    0.473,   -2.106,
534       4.277,    0.151,   -2.810,
535       4.290,    0.943,   -1.483,
536       6.513,    8.730,   -7.834,
537       6.118,    9.184,   -8.603,
538       6.079,    9.184,   -7.099,
539      -4.614,    8.539,   -8.033,
540      -4.889,    9.266,   -8.621,
541      -4.772,    7.762,   -8.593,
542      -6.020,    6.026,    3.465,
543      -5.295,    5.661,    4.006,
544      -6.769,    5.671,    3.989,
545       3.044,    2.054,   -5.845,
546       2.544,    2.669,   -5.281,
547       2.662,    1.208,   -5.535,
548       0.718,   -5.364,   -5.711,
549       0.525,   -6.145,   -5.134,
550       0.387,   -4.632,   -5.170,
551       6.839,    6.205,   -8.033,
552       7.487,    5.729,   -8.606,
553       6.988,    7.146,   -8.289,
554      -1.186,   -8.931,   -0.331,
555      -1.773,   -9.165,   -1.068,
556      -1.728,   -9.168,    0.444,
557       3.135,    0.553,    7.070,
558       2.450,    1.035,    6.578,
559       2.662,    0.144,    7.841,
560      -2.613,    3.946,    3.491,
561      -2.070,    3.311,    4.029,
562      -2.760,    4.678,    4.125,
563      -8.286,    8.212,   -9.462,
564      -7.541,    7.883,   -8.933,
565      -9.025,    7.762,   -9.024,
566      -8.293,   -3.030,   -2.208,
567      -8.920,   -2.573,   -2.836,
568      -7.896,   -3.653,   -2.836,
569      -0.178,   -3.030,   -2.071,
570       0.347,   -3.297,   -2.865,
571       0.157,   -3.649,   -1.400,
572       3.374,    8.503,   -0.316,
573       4.004,    8.964,    0.286,
574       3.947,    7.905,   -0.843,
575      -2.613,    2.054,    1.825,
576      -3.243,    1.342,    2.094,
577      -2.870,    2.800,    2.417,
578      -5.940,    8.499,   -0.217,
579      -5.363,    7.879,    0.286,
580      -5.339,    8.826,   -0.937,
581      -7.761,   -5.364,    8.895,
582      -7.855,   -6.083,    8.223,
583      -7.468,   -4.632,    8.329,
584       3.443,    8.499,   -9.654,
585       3.946,    8.038,  -10.363,
586       3.640,    7.879,   -8.906,
587       3.367,    6.250,   -8.448,
588       2.555,    5.726,   -8.626,
589       4.030,    5.671,   -8.902,
590       5.125,    3.952,   -0.463,
591       5.276,    4.426,    0.408,
592       5.510,    4.603,   -1.074,
593      -7.179,    3.952,   -2.071,
594      -7.755,    4.452,   -1.440,
595      -6.381,    4.465,   -1.890,
596      -7.107,    2.058,   -4.254,
597      -6.955,    2.669,   -3.507,
598      -6.861,    2.633,   -5.008,
599      -0.074,   -5.416,    1.536,
600      -0.614,   -5.973,    0.934,
601       0.236,   -6.063,    2.215,
602       0.944,   -0.779,    9.069,
603       0.337,   -1.548,    9.005,
604       1.750,   -1.174,    9.468,
605       5.082,   -3.030,    8.994,
606       5.722,   -2.337,    9.294,
607       5.626,   -3.585,    8.390,
608      -8.348,    8.482,   -6.135,
609      -7.856,    7.879,   -5.529,
610      -8.902,    7.879,   -6.661,
611       0.944,    6.280,   -7.485,
612       1.771,    5.925,   -7.106,
613       0.316,    5.703,   -7.046,
614       2.132,    3.952,   -2.182,
615       2.542,    4.607,   -2.778,
616       1.825,    4.535,   -1.460,
617      -4.566,   -9.021,   -2.071,
618      -5.020,   -8.283,   -1.612,
619      -5.084,   -9.225,   -2.867,
620       8.119,    6.221,    3.123,
621       8.581,    5.656,    2.483,
622       8.060,    7.076,    2.650,
623      -2.592,    6.195,   -6.129,
624      -2.289,    5.729,   -5.321,
625      -2.201,    5.661,   -6.827,
626       3.103,   -3.019,   -1.943,
627       2.583,   -2.316,   -1.506,
628       2.736,   -3.806,   -1.506,
629       6.697,    3.946,   -6.207,
630       6.136,    3.351,   -6.768,
631       6.988,    4.641,   -6.827,
632       9.064,   -2.261,   -4.259,
633       8.697,   -2.201,   -5.143,
634       8.752,   -1.431,   -3.860,
635       5.112,    4.993,    1.838,
636       5.695,    5.471,    2.454,
637       4.290,    5.552,    1.896,
638       1.024,   -7.340,   -4.238,
639       1.283,   -7.894,   -3.449,
640       1.223,   -7.982,   -4.975,
641      -5.937,   -8.757,   -6.135,
642      -5.356,   -9.251,   -6.768,
643      -6.652,   -8.426,   -6.740,
644      -5.978,    8.506,    3.176,
645      -6.498,    7.882,    3.732,
646      -5.451,    7.879,    2.631,
647      -0.842,   -1.078,   -6.281,
648      -0.008,   -1.268,   -6.766,
649      -1.516,   -1.457,   -6.885,
650      -6.171,   -0.810,   -7.737,
651      -5.531,   -1.227,   -8.378,
652      -6.535,   -1.548,   -7.224,
653       0.944,   -5.416,   -8.138,
654       0.695,   -5.639,   -7.187,
655       0.387,   -6.052,   -8.640,
656       6.697,   -2.010,   -1.968,
657       6.069,   -1.431,   -1.501,
658       7.109,   -1.457,   -2.664,
659       9.069,    0.379,    1.541,
660       9.588,    0.172,    0.721,
661       9.644,   -0.021,    2.214,
662      -1.191,    1.974,    5.042,
663      -0.730,    1.400,    4.391,
664      -1.614,    1.348,    5.662,
665      -4.361,   -3.022,    5.042,
666      -3.793,   -2.510,    4.408,
667      -4.909,   -2.343,    5.493,
668       1.018,   -0.786,   -0.034,
669       0.555,   -1.431,    0.529,
670       1.693,   -0.370,    0.539,
671      -5.868,    9.877,    6.945,
672      -5.365,    9.168,    6.500,
673      -5.497,   10.635,    6.443,
674       8.119,   -5.397,   -4.323,
675       7.651,   -4.915,   -3.589,
676       7.429,   -5.959,   -4.718,
677       6.697,   -3.022,    1.333,
678       7.056,   -2.481,    0.616,
679       6.080,   -3.649,    0.902,
680      -2.593,   -0.807,   -4.419,
681      -2.030,   -1.431,   -4.921,
682      -2.317,    0.004,   -4.894,
683      -0.054,    1.973,   -9.635,
684       0.316,    1.325,   -9.013,
685      -0.661,    1.416,  -10.159,
686       3.127,    3.849,    7.142,
687       2.542,    3.517,    6.446,
688       2.830,    3.326,    7.904,
689      -6.220,   -3.030,   -0.316,
690      -6.767,   -3.609,    0.263,
691      -6.833,   -2.628,   -0.970,
692       8.438,   -8.757,   -4.351,
693       8.710,   -9.471,   -4.939,
694       8.697,   -8.008,   -4.903,
695       9.078,    8.585,    3.176,
696       9.648,    9.123,    2.570,
697       9.673,    8.084,    3.761,
698      -4.232,   -3.030,    1.277,
699      -4.916,   -3.482,    0.717,
700      -3.877,   -2.341,    0.672,
701       3.289,   -5.461,   -4.323,
702       4.028,   -5.744,   -4.921,
703       2.544,   -5.959,   -4.731,
704      -2.652,   -5.364,   -5.885,
705      -2.224,   -5.996,   -5.277,
706      -3.193,   -4.775,   -5.317,
707      -8.293,   -7.337,    7.239,
708      -8.872,   -7.923,    7.786,
709      -7.852,   -7.950,    6.612,
710      -8.293,    2.008,   -9.546,
711      -7.927,    1.457,  -10.286,
712      -8.855,    1.387,   -9.053,
713       6.681,   -4.100,    4.959,
714       7.280,   -4.569,    4.325,
715       6.016,   -3.758,    4.344,
716      -0.862,    3.946,   -4.460,
717      -0.521,    4.722,   -4.921,
718      -0.701,    3.210,   -5.100,
719       3.136,   -5.194,    3.176,
720       2.544,   -4.764,    2.536,
721       2.715,   -4.842,    4.021,
722       1.018,   -8.721,   -2.047,
723       0.319,   -8.440,   -1.418,
724       1.554,   -9.306,   -1.460,
725       6.717,    1.990,   -4.194,
726       7.393,    1.302,   -4.028,
727       7.067,    2.669,   -3.591,
728       1.018,    3.894,    1.227,
729       0.387,    3.375,    0.684,
730       1.258,    4.655,    0.677,
731      -4.374,    8.524,   -4.430,
732      -5.033,    9.086,   -4.921,
733      -3.572,    8.689,   -4.985,
734       1.018,    1.973,    3.126,
735       0.628,    2.667,    2.543,
736       1.632,    1.491,    2.543,
737      -6.175,   -5.364,    1.278,
738      -6.819,   -6.033,    1.029,
739      -6.427,   -5.134,    2.214,
740       5.195,    8.524,   -4.323,
741       5.745,    9.258,   -4.638,
742       5.745,    7.762,   -4.610,
743      -4.165,   -0.811,   -9.464,
744      -3.684,   -0.003,   -9.215,
745      -3.613,   -1.485,   -9.024,
746       6.743,    6.280,   -1.743,
747       7.021,    7.158,   -1.406,
748       7.330,    5.690,   -1.252,
749      -2.690,   -7.249,   -2.218,
750      -3.193,   -7.035,   -1.402,
751      -3.173,   -6.707,   -2.852,
752       3.331,   -0.811,   -3.907,
753       2.475,   -1.004,   -3.450,
754       3.863,   -1.548,   -3.557,
755      -2.492,    8.752,   -6.212,
756      -2.336,    7.854,   -6.594,
757      -2.322,    9.324,   -6.976,
758      -5.870,    3.876,    4.876,
759      -5.306,    3.278,    4.352,
760      -5.660,    3.520,    5.787,
761       5.021,    6.571,    7.047,
762       5.681,    7.001,    6.474,
763       4.240,    6.537,    6.442,
764      -1.470,    3.894,   -2.008,
765      -1.584,    3.455,   -2.881,
766      -1.794,    3.180,   -1.406,
767      -1.064,    8.524,   -4.120,
768      -0.615,    9.259,   -3.659,
769      -1.479,    8.940,   -4.920,
770       9.069,   -5.358,   -0.316,
771       8.789,   -4.819,    0.441,
772       8.697,   -4.855,   -1.070,
773       6.513,   -0.725,   -9.626,
774       6.069,   -0.105,  -10.242,
775       7.096,   -0.144,   -9.100,
776      -4.291,   -0.807,   -0.515,
777      -5.020,   -0.622,   -1.152,
778      -3.667,   -1.355,   -1.079,
779       8.451,   -8.757,    8.994,
780       9.249,   -9.285,    9.240,
781       8.309,   -8.233,    9.822,
782      -8.286,   -8.837,    1.105,
783      -7.986,   -8.008,    0.717,
784      -7.615,   -9.438,    0.717,
785      -0.241,   -3.050,    8.994,
786      -0.582,   -3.639,    8.291,
787       0.234,   -3.658,    9.597,
788       2.182,   -5.358,   -0.206,
789       1.944,   -6.157,    0.286,
790       1.734,   -4.681,    0.334,
791       1.058,   -5.433,    7.220,
792       0.557,   -6.013,    7.851,
793       1.624,   -6.061,    6.713,
794       7.031,   -4.531,   -2.071,
795       6.069,   -4.746,   -1.936,
796       7.079,   -3.621,   -1.730,
797      -0.241,    1.973,   -6.143,
798       0.234,    1.416,   -5.482,
799      -0.608,    1.328,   -6.768,
800       4.942,    3.894,    5.051,
801       4.624,    3.278,    4.361,
802       4.394,    3.634,    5.825,
803      -2.480,   -3.031,   -7.834,
804      -2.201,   -3.582,   -8.593,
805      -2.322,   -3.646,   -7.095,
806       3.443,    6.112,   -5.887,
807       4.054,    5.661,   -5.279,
808       3.804,    5.828,   -6.768,
809       8.089,   -3.022,    7.047,
810       8.061,   -2.249,    6.458,
811       7.582,   -3.658,    6.491,
812      -4.477,    2.054,   -7.485,
813      -4.916,    1.268,   -7.116,
814      -4.962,    2.757,   -6.987,
815      -8.293,    0.392,   -6.345,
816      -8.993,   -0.051,   -6.828,
817      -7.490,    0.079,   -6.807,
818       8.126,   -5.416,    3.176,
819       7.582,   -6.033,    2.643,
820       8.616,   -6.015,    3.776,
821       6.658,   -2.921,   -6.135,
822       6.118,   -2.342,   -5.555,
823       7.050,   -2.291,   -6.768,
824      -4.477,    0.379,    1.718,
825      -4.661,   -0.029,    0.831,
826      -5.111,   -0.077,    2.282,
827      -5.993,    3.952,    7.282,
828      -6.649,    4.585,    6.893,
829      -5.506,    4.519,    7.904,
830      -2.797,    2.054,    8.980,
831      -3.242,    2.449,    9.752,
832      -3.101,    2.633,    8.237,
833       0.944,   -7.337,    3.176,
834       1.451,   -7.951,    2.613,
835       0.439,   -7.941,    3.774,
836       9.085,   -2.745,    3.291,
837       8.696,   -2.343,    2.504,
838       8.697,   -2.223,    4.021
839 };
840 
841 static int *listw = NULL;
842 static float *qpot = NULL;
843 static float *woo = NULL;
844 static float *whh = NULL;
845 static float *woh = NULL;
846 static float *dewoo = NULL;
847 static float *dewhh = NULL;
848 static float *dewoh = NULL;
849 static float *apprerf = NULL;
850 static float *appexp = NULL;
851 static float *ewoo = NULL;
852 static float *ewhh = NULL;
853 static float *ewoh = NULL;
854 static float *edwoo = NULL;
855 static float *edwhh = NULL;
856 static float *edwoh = NULL;
857 static float *drb = NULL;
858 static float *rsolv = NULL;
859 static float *rborn = NULL;
860 static float *shct = NULL;
861 
catch22(int sig)862 void catch22(int sig)
863 {
864 
865 	*iwesc = 1;
866 	(void) signal(SIGINT, catch22);
867 
868 }
869 
870 
871 #if defined(VMS) || defined(UNDERSC)
wexit()872 void wexit()
873 #else
874 #ifdef CRAY
875 void WEXIT()
876 #else
877 void wexit_()
878 #endif
879 #endif
880 {
881 #ifndef MD
882 
883 #if defined(VMS) || defined(UNDERSC)
884 	wrtesc();
885 #else
886 #ifdef CRAY
887 	WRTESC();
888 #else
889 	wrtesc_();
890 #endif
891 #endif
892 
893 #else
894 
895 #if defined(VMS) || defined(UNDERSC)
896 	wmdesc();
897 #else
898 #ifdef CRAY
899 	WMDESC();
900 #else
901 	wmdesc_();
902 #endif
903 #endif
904 
905 #endif
906 	exit(1);
907 }
908 
909 #if defined(VMS) || defined(UNDERSC)
parptr(nptr,fptr,ffptr,nitem)910 void parptr(nptr, fptr, ffptr, nitem)
911 #else
912 #ifdef CRAY
913 void PARPTR(nptr, fptr, ffptr, nitem)
914 #else
915 void parptr_(nptr, fptr, ffptr, nitem)
916 #endif
917 #endif
918 
919 int *nptr;
920 float *fptr;
921 float *ffptr;
922 int *nitem;
923 {
924 
925     switch(*nptr) {
926     case 0: atomptr   = (ATOMSTRU *) fptr;
927 	    xyz.coo   = (float *) atomptr->coo;
928 	    xyz.ctmp   = (float *) atomptr->ctmp;
929 	    xyz.q     = (float *) atomptr->q;
930 	    xyz.fr   = (float *) atomptr->fr;
931 	    xyz.ftmp  = (float *) atomptr->ftmp;
932 	    xyz.iaton = (int *) atomptr->iaton;
933 	    xyz.iopt  = (int *) atomptr->iopt;
934 	    xyz.n13   = (int *) atomptr->n13;
935 	    xyz.i13   = (int *) atomptr->i13;
936 	    xyz.n14   = (int *) atomptr->n14;
937 	    xyz.i14   = (int *) atomptr->i14;
938 	    xyz.iresid= (int *) atomptr->iresid;
939 	    xyz.iconn = (int *) atomptr->iconn;
940 	    xyz.ityp  = (short int *) atomptr->ityp;
941 	    break;
942     case 1: forvarptr = (FORSTRU *) fptr;
943 	    xyz.maxbnd =  (int *) &forvarptr->maxbnd;
944 	    xyz.maxang =  (int *) &forvarptr->maxang;
945 	    xyz.maxtors = (int *) &forvarptr->maxtors;
946 	    xyz.nbnd  = (int *) &forvarptr->nbnd;
947 	    xyz.nang  = (int *) &forvarptr->nang;
948 	    xyz.nt    = (int *) &forvarptr->nt;
949 	    xyz.nti   = (int *) &forvarptr->nti;
950 	    xyz.ibnd  = (int *) forvarptr->ibnd;
951 	    xyz.iang  = (int *) forvarptr->iang;
952 	    xyz.it    = (int *) forvarptr->it;
953 	    xyz.iti   = (int *) forvarptr->iti;
954 	    xyz.bl    = (float *) forvarptr->bl;
955 	    xyz.bk    = (float *) forvarptr->bk;
956 	    xyz.ango  = (float *) forvarptr->ango;
957 	    xyz.ak    = (float *) forvarptr->ak;
958 	    xyz.trs1  = (float *) forvarptr->trs1;
959 	    xyz.trs2  = (float *) forvarptr->trs2;
960 	    xyz.trs3  = (float *) forvarptr->trs3;
961 	    xyz.trs4  = (float *) forvarptr->trs4;
962 	    xyz.itor  = (int *) forvarptr->itor;
963 	    xyz.imptor = (int *) forvarptr->imptor;
964 	    xyz.trsi1 = (float *) forvarptr->trsi1;
965 	    xyz.trsi2 = (float *) forvarptr->trsi2;
966 	    break;
967     case 2:
968 	    xyz.iatoms = nitem;
969 	    xyz.mxorg = NUMAT;
970 	    break;
971     case 3: optscr = (OPTSCRSTRU *) fptr;
972 	    xyz.coot  = (float *) optscr->coot;
973 	    xyz.frt   = (float *) optscr->fort;
974 	    xyz.zr    = (float *) optscr->zr;
975 	    xyz.y     = (float *) optscr->y;
976 	    xyz.yt    = (float *) optscr->yt;
977 	    xyz.pt    = (float *) optscr->pt;
978 	    xyz.s     = (float *) optscr->s;
979 	    xyz.work  = NULL;
980 	    break;
981     case 4:
982 	    xyz.mxnat = nitem;
983 	    break;
984     case 5:
985 	    iwesc = nitem;
986 	    break;
987     case 6:
988 	    nproc = nitem;
989 	    break;
990     case 7:
991 	    taskid = nitem;
992 	    break;
993     case 8:
994 	    gffvdw = fptr;
995 	    break;
996     case 9:
997 	    gffmas = fptr;
998 	    break;
999     case 10:
1000 	    torptr = (TORSTRU *) fptr;
1001 	    break;
1002     case 11:
1003 	    lammps = nitem;
1004 	    break;
1005     case 12:
1006 	    itorptr = (ITORSTRU *) fptr;
1007 	    break;
1008     }
1009     if (!ctrlCset) {
1010 	(void) signal(SIGINT, catch22);
1011 	ctrlCset = 1;
1012         unlink("ambfor.wr");
1013     }
1014 }
1015 
1016 #if defined(VMS) || defined(UNDERSC)
allcoo(ZSizep)1017 void allcoo(ZSizep)
1018 #else
1019 #ifdef CRAY
1020 void ALLCOO(ZSizep)
1021 #else
1022 void allcoo_(ZSizep)
1023 #endif
1024 #endif
1025 int *ZSizep;
1026 {
1027    int memstat;
1028    float d;
1029    int i;
1030    short int j;
1031    int ZSize, wsize;
1032 
1033    ZSize = *xyz.mxnat + *ZSizep;
1034    memstat = 1;
1035 
1036    TMPxyz = xyz;
1037 
1038    if ((xyz.coo = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1039 	memstat = 0;
1040    }
1041 
1042    if ((xyz.ctmp = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1043 	memstat = 0;
1044    }
1045 
1046    if ((xyz.q = (float *) malloc((sizeof d)*ZSize)) == NULL) {
1047 	memstat = 0;
1048    }
1049 
1050    if ((xyz.fr = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1051 	memstat = 0;
1052    }
1053 
1054    if ((xyz.coot = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1055 	memstat = 0;
1056    }
1057 
1058    if ((xyz.frt = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1059 	memstat = 0;
1060    }
1061 
1062    if ((xyz.zr = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1063 	memstat = 0;
1064    }
1065 
1066    if ((xyz.y = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1067 	memstat = 0;
1068    }
1069 
1070    if ((xyz.yt = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1071 	memstat = 0;
1072    }
1073 
1074    if ((xyz.pt = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1075 	memstat = 0;
1076    }
1077 
1078    if ((xyz.s = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1079 	memstat = 0;
1080    }
1081 
1082    wsize = ZSize*3*(2*MSAVE+1)+2*MSAVE;
1083 
1084    if ((xyz.work = (float *) malloc((sizeof d)*wsize)) == NULL) {
1085 	memstat = 0;
1086    }
1087 
1088    if ((xyz.iaton = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1089 	memstat = 0;
1090    }
1091 
1092    if ((xyz.iopt = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1093 	memstat = 0;
1094    }
1095 
1096    if ((xyz.watprot = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1097 	memstat = 0;
1098    }
1099 
1100    if ((xyz.ftmp = (float *) malloc((sizeof d)*ZSize)) == NULL) {
1101 	memstat = 0;
1102    }
1103 
1104    if ((xyz.n13 = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1105 	memstat = 0;
1106    }
1107 
1108    if ((xyz.i13 = (int *) malloc((sizeof i)*ZSize*(MAX13))) == NULL) {
1109 	memstat = 0;
1110    }
1111 
1112    if ((xyz.n14 = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1113 	memstat = 0;
1114    }
1115 
1116    if ((xyz.i14 = (int *) malloc((sizeof i)*ZSize*(MAX14))) == NULL) {
1117 	memstat = 0;
1118    }
1119 
1120    if ((xyz.iresid = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1121 	memstat = 0;
1122    }
1123 
1124    if ((xyz.iconn = (int *) malloc((sizeof i)*ZSize*(MXCON+1))) == NULL) {
1125 	memstat = 0;
1126    }
1127 
1128    if ((xyz.ityp = (short int *) malloc((sizeof j)*ZSize)) == NULL) {
1129 	memstat = 0;
1130    }
1131 
1132    if ((xyz.ibnd = (int *) malloc((sizeof i)*ZSize*2*2)) == NULL) {
1133 	memstat = 0;
1134    }
1135 
1136    if ((xyz.iang = (int *) malloc((sizeof i)*ZSize*3*3)) == NULL) {
1137 	memstat = 0;
1138    }
1139 
1140    if ((xyz.it = (int *) malloc((sizeof i)*ZSize*4*4)) == NULL) {
1141 	memstat = 0;
1142    }
1143 
1144    if ((xyz.iti = (int *) malloc((sizeof i)*ZSize*4*4)) == NULL) {
1145 	memstat = 0;
1146    }
1147 
1148    if ((xyz.bl = (float *) malloc((sizeof d)*ZSize*2)) == NULL) {
1149 	memstat = 0;
1150    }
1151 
1152    if ((xyz.bk = (float *) malloc((sizeof d)*ZSize*2)) == NULL) {
1153 	memstat = 0;
1154    }
1155 
1156    if ((xyz.ango = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1157 	memstat = 0;
1158    }
1159 
1160    if ((xyz.ak = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
1161 	memstat = 0;
1162    }
1163 
1164    if ((xyz.trs1 = (float *) malloc((sizeof d)*ZSize*4*4)) == NULL) {
1165 	memstat = 0;
1166    }
1167 
1168    if ((xyz.trs2 = (float *) malloc((sizeof d)*ZSize*4*4)) == NULL) {
1169 	memstat = 0;
1170    }
1171 
1172    if ((xyz.trs3 = (float *) malloc((sizeof d)*ZSize*4*4)) == NULL) {
1173 	memstat = 0;
1174    }
1175 
1176    if ((xyz.trs4 = (float *) malloc((sizeof d)*ZSize*4*4)) == NULL) {
1177 	memstat = 0;
1178    }
1179 
1180    if ((xyz.itor = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1181 	memstat = 0;
1182    }
1183 
1184    if ((xyz.imptor = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1185 	memstat = 0;
1186    }
1187 
1188    if ((xyz.trsi1 = (float *) malloc((sizeof d)*ZSize*4*4)) == NULL) {
1189 	memstat = 0;
1190    }
1191 
1192    if ((xyz.trsi2 = (float *) malloc((sizeof d)*ZSize*4*4)) == NULL) {
1193 	memstat = 0;
1194    }
1195 
1196 
1197    if (!memstat) {
1198 	fprintf(stderr,"Out of memory\n");
1199 	xyz = TMPxyz;
1200    } else {
1201 	for (i=0; i < *xyz.mxnat; i++) {
1202 	   for (j=0; j<3; j++) {
1203 		xyz.coo[i*3+j] = TMPxyz.coo[i*3+j];
1204 		xyz.ctmp[i*3+j] = TMPxyz.ctmp[i*3+j];
1205 		xyz.fr[i*3+j] = TMPxyz.fr[i*3+j];
1206 	   }
1207 	   xyz.q[i] = TMPxyz.q[i];
1208 	   xyz.iaton[i] = TMPxyz.iaton[i];
1209 	   xyz.iopt[i] = TMPxyz.iopt[i];
1210 	   xyz.n13[i] = TMPxyz.n13[i];
1211 	   xyz.n14[i] = TMPxyz.n14[i];
1212 	   xyz.iresid[i] = TMPxyz.iresid[i];
1213 	   xyz.ityp[i] = TMPxyz.ityp[i];
1214 	   for (j=0; j<MXCON; j++)
1215 		xyz.iconn[i*(MXCON+1)+j] = TMPxyz.iconn[i*(MXCON+1)+j];
1216 	   for (j=0; j<MAX13; j++)
1217 		xyz.i13[i*MAX13+j] = TMPxyz.i13[i*MAX13+j];
1218 	   for (j=0; j<MAX14; j++)
1219 		xyz.i14[i*MAX14+j] = TMPxyz.i14[i*MAX14+j];
1220 	}
1221 	for (i=0; i < *xyz.nbnd; i++) {
1222 	   for (j=0; j<2; j++)
1223 		xyz.ibnd[i*2+j] = TMPxyz.ibnd[i*2+j];
1224 	   xyz.bl[i] = TMPxyz.bl[i];
1225 	   xyz.bk[i] = TMPxyz.bk[i];
1226 	}
1227 	for (i=0; i < *xyz.nang; i++) {
1228 	   for (j=0; j<3; j++)
1229 		xyz.iang[i*3+j] = TMPxyz.iang[i*3+j];
1230 	   xyz.ango[i] = TMPxyz.ango[i];
1231 	   xyz.ak[i] = TMPxyz.ak[i];
1232 	}
1233 	for (i=0; i < *xyz.nt; i++) {
1234 	   for (j=0; j<4; j++)
1235 		xyz.it[i*4+j] = TMPxyz.it[i*4+j];
1236 	   for (j=0; j<4; j++) {
1237 		xyz.trs1[i*4+j] = TMPxyz.trs1[i*4+j];
1238 		xyz.trs2[i*4+j] = TMPxyz.trs2[i*4+j];
1239 		xyz.trs3[i*4+j] = TMPxyz.trs3[i*4+j];
1240 		xyz.trs4[i*4+j] = TMPxyz.trs4[i*4+j];
1241 	   }
1242 	   xyz.itor[i] = TMPxyz.itor[i];
1243 	   xyz.imptor[i] = TMPxyz.imptor[i];
1244 	}
1245 	for (i=0; i < *xyz.nti; i++) {
1246 	   for (j=0; j<4; j++)
1247 		xyz.iti[i*4+j] = TMPxyz.iti[i*4+j];
1248 	   for (j=0; j<4; j++) {
1249 		xyz.trsi1[i*4+j] = TMPxyz.trsi1[i*4+j];
1250 		xyz.trsi2[i*4+j] = TMPxyz.trsi2[i*4+j];
1251 	   }
1252 	}
1253 
1254 	if (*TMPxyz.mxnat != TMPxyz.mxorg) {
1255 	   free(TMPxyz.coo);
1256 	   free(TMPxyz.ctmp);
1257 	   free(TMPxyz.q);
1258 	   free(TMPxyz.fr);
1259 	   free(TMPxyz.coot);
1260 	   free(TMPxyz.frt);
1261 	   free(TMPxyz.zr);
1262 	   free(TMPxyz.y);
1263 	   free(TMPxyz.yt);
1264 	   free(TMPxyz.pt);
1265 	   free(TMPxyz.s);
1266 	   free(TMPxyz.ftmp);
1267 	   free(TMPxyz.iaton);
1268 	   free(TMPxyz.iopt);
1269 	   free(TMPxyz.watprot);
1270 	   free(TMPxyz.n13);
1271 	   free(TMPxyz.i13);
1272 	   free(TMPxyz.n14);
1273 	   free(TMPxyz.i14);
1274 	   free(TMPxyz.iresid);
1275 	   free(TMPxyz.iconn);
1276 	   free(TMPxyz.ityp);
1277 	   free(TMPxyz.ibnd);
1278 	   free(TMPxyz.iang);
1279 	   free(TMPxyz.it);
1280 	   free(TMPxyz.iti);
1281 	   free(TMPxyz.bl);
1282 	   free(TMPxyz.bk);
1283 	   free(TMPxyz.ango);
1284 	   free(TMPxyz.ak);
1285 	   free(TMPxyz.trs1);
1286 	   free(TMPxyz.trs2);
1287 	   free(TMPxyz.trs3);
1288 	   free(TMPxyz.trs4);
1289 	   free(TMPxyz.itor);
1290 	   free(TMPxyz.imptor);
1291 	   free(TMPxyz.trsi1);
1292 	   free(TMPxyz.trsi2);
1293 	}
1294 	*xyz.mxnat   = ZSize;
1295 	*xyz.maxbnd  = ZSize*2;
1296 	*xyz.maxang  = ZSize*3;
1297 	*xyz.maxtors = ZSize*4;
1298    }
1299 }
1300 
1301 #if defined(VMS) || defined(UNDERSC)
allbck()1302 void allbck()
1303 #else
1304 #ifdef CRAY
1305 void ALLBCK()
1306 #else
1307 void allbck_()
1308 #endif
1309 #endif
1310 {
1311    int memstat;
1312    int i;
1313    int ZSize;
1314 
1315    if (xyz.watprot != NULL) return;
1316 
1317    ZSize = *xyz.mxnat;
1318    if ((xyz.watprot = (int *) malloc((sizeof i)*ZSize)) == NULL) {
1319 	memstat = 0;
1320    }
1321 }
1322 
1323 #if defined(VMS) || defined(UNDERSC)
allq()1324 void allq()
1325 #else
1326 #ifdef CRAY
1327 void ALLQ()
1328 #else
1329 void allq_()
1330 #endif
1331 #endif
1332 {
1333    int memstat;
1334    float d;
1335    int i;
1336    short int j;
1337    int ZSize, wsize;
1338 
1339    ZSize = *xyz.mxnat;
1340 
1341    if ((qpot = (float *) malloc((sizeof d)*ZSize)) == NULL) {
1342 	fprintf(stderr,"Out of memory\n");
1343    }
1344 
1345 }
1346 
1347 #if defined(VMS) || defined(UNDERSC)
angarr(istat)1348 void angarr(istat)
1349 #else
1350 #ifdef CRAY
1351 void ANGARR(istat)
1352 #else
1353 void angarr_(istat)
1354 #endif
1355 #endif
1356 int *istat;
1357 {
1358 
1359 #if defined(VMS) || defined(UNDERSC)
1360 	angard(istat,
1361 #else
1362 #ifdef CRAY
1363 	ANGARD(istat,
1364 #else
1365 	angard_(istat,
1366 #endif
1367 #endif
1368 	xyz.nang,xyz.iang,xyz.ango,xyz.ak,xyz.maxang,xyz.iconn,xyz.ityp,xyz.iopt);
1369 
1370 }
1371 
1372 #if defined(VMS) || defined(UNDERSC)
bndarr(istat)1373 void bndarr(istat)
1374 #else
1375 #ifdef CRAY
1376 void BNDARR(istat)
1377 #else
1378 void bndarr_(istat)
1379 #endif
1380 #endif
1381 int *istat;
1382 {
1383 
1384 #if defined(VMS) || defined(UNDERSC)
1385 	bndard(istat,
1386 #else
1387 #ifdef CRAY
1388 	BNDARD(istat,
1389 #else
1390 	bndard_(istat,
1391 #endif
1392 #endif
1393 	xyz.nbnd,xyz.ibnd,xyz.bl,xyz.bk,xyz.maxbnd,xyz.iconn,xyz.ityp,xyz.iopt);
1394 
1395 
1396 }
1397 
1398 #if defined(VMS) || defined(UNDERSC)
itrarr(istat)1399 void itrarr(istat)
1400 #else
1401 #ifdef CRAY
1402 void ITRARR(istat)
1403 #else
1404 void itrarr_(istat)
1405 #endif
1406 #endif
1407 int *istat;
1408 {
1409 #if defined(VMS) || defined(UNDERSC)
1410 	itrard(istat,
1411 #else
1412 #ifdef CRAY
1413 	ITRARD(istat,
1414 #else
1415 	itrard_(istat,
1416 #endif
1417 #endif
1418 		xyz.maxtors,xyz.nti,xyz.iti,
1419 		xyz.trsi1,xyz.trsi2,xyz.imptor,xyz.iconn,xyz.ityp,xyz.iopt);
1420 }
1421 
1422 #if defined(VMS) || defined(UNDERSC)
torarr(istat)1423 void torarr(istat)
1424 #else
1425 #ifdef CRAY
1426 void TORARR(istat)
1427 #else
1428 void torarr_(istat)
1429 #endif
1430 #endif
1431 int *istat;
1432 {
1433 
1434 #if defined(VMS) || defined(UNDERSC)
1435 	torard(istat,
1436 #else
1437 #ifdef CRAY
1438 	TORARD(istat,
1439 #else
1440 	torard_(istat,
1441 #endif
1442 #endif
1443 		xyz.maxtors,xyz.nbnd,xyz.ibnd,
1444 		xyz.nt,xyz.it,xyz.trs1,xyz.trs2,xyz.trs3,xyz.trs4,
1445 		xyz.itor,xyz.iconn,xyz.ityp,xyz.iopt);
1446 
1447 }
1448 
1449 #if defined(VMS) || defined(UNDERSC)
prttor(istat)1450 void prttor(istat)
1451 #else
1452 #ifdef CRAY
1453 void PRTTOR(istat)
1454 #else
1455 void prttor_(istat)
1456 #endif
1457 #endif
1458 int *istat;
1459 {
1460 #if defined(VMS) || defined(UNDERSC)
1461 	prttod(istat,
1462 #else
1463 #ifdef CRAY
1464 	PRTTOD(istat,
1465 #else
1466 	prttod_(istat,
1467 #endif
1468 #endif
1469 		xyz.maxtors,
1470 		xyz.nt,xyz.it,xyz.trs1,xyz.trs2,xyz.trs3,xyz.trs4,
1471 		xyz.iconn,xyz.ityp,xyz.iopt);
1472 }
1473 
1474 #if defined(VMS) || defined(UNDERSC)
pritor(istat)1475 void pritor(istat)
1476 #else
1477 #ifdef CRAY
1478 void PRITOR(istat)
1479 #else
1480 void pritor_(istat)
1481 #endif
1482 #endif
1483 int *istat;
1484 {
1485 #if defined(VMS) || defined(UNDERSC)
1486 	pritod(istat,
1487 #else
1488 #ifdef CRAY
1489 	PRITOD(istat,
1490 #else
1491 	pritod_(istat,
1492 #endif
1493 #endif
1494 		xyz.maxtors,
1495 		xyz.nti,xyz.iti,xyz.trsi1,xyz.trsi2,
1496 		xyz.iconn,xyz.ityp,xyz.iopt);
1497 }
1498 
wrtlam()1499 void wrtlam()
1500 {
1501 	FILE *out;
1502 	int i,j,l,it,iord,*shdtyp,*maptyp,*torr,*itorr,*ntorr,ntypes,its,impts;
1503 	float gf1,gf2,gf3,gf4,cv;
1504 	int gfa1,gfa2,gfa3,gfa4;
1505 
1506 	cv = powf(2.0,(5.0/6.0));
1507 
1508 	out = fopen("gaff.lammps","w");
1509 
1510 	if ((torr= (int *) malloc((sizeof i)*(MAXTORS))) == NULL) {
1511 	   fprintf(stderr,"failed to allocate memory!\n");
1512 	}
1513 
1514 	if ((itorr= (int *) malloc((sizeof i)*(MAXTORS))) == NULL) {
1515 	   fprintf(stderr,"failed to allocate memory!\n");
1516 	}
1517 
1518 	if ((ntorr= (int *) malloc((sizeof i)*(MAXTORS))) == NULL) {
1519 	   fprintf(stderr,"failed to allocate memory!\n");
1520 	}
1521 
1522 	if ((shdtyp = (int *) malloc((sizeof i)*(*xyz.iatoms))) == NULL) {
1523 	   fprintf(stderr,"failed to allocate memory!\n");
1524 	}
1525 
1526 	if ((maptyp = (int *) malloc((sizeof i)*(*xyz.iatoms))) == NULL) {
1527 	   fprintf(stderr,"failed to allocate memory!\n");
1528 
1529 	} else {
1530  	   ntypes = -1;
1531 	   for (i=0; i < *xyz.iatoms; i++) {
1532 		shdtyp[i] = -1; maptyp[i] = -1; torr[i] = -1; itorr[i] = -1;
1533 	   }
1534 
1535 	   for (i=0; i < *xyz.iatoms; i++) {
1536 
1537 		if (maptyp[i] == -1) {
1538 		   ntypes++;
1539 		   shdtyp[ntypes] = (int) xyz.ityp[i];
1540 
1541 // replace all occurences of type ityp[i] by ntypes
1542 
1543 		   for (j=0; j < *xyz.iatoms; j++) {
1544 			if (maptyp[j] == -1 && xyz.ityp[i] == xyz.ityp[j]) {
1545 			   maptyp[j] = ntypes + 1;
1546 			}
1547 		   }
1548 
1549  		}
1550 	   }
1551 	   ntypes++;
1552 	}
1553 
1554 	its = 0;
1555 
1556 	for (i=0; i < *xyz.nt; i++) {
1557 	   l = xyz.itor[i];
1558 
1559 	   if (torptr->gftor1[(l-1)][0] != 0.0) its++;
1560 	   if (torptr->gftor2[(l-1)][0] != 0.0) its++;
1561 	   if (torptr->gftor3[(l-1)][0] != 0.0) its++;
1562 	   if (torptr->gftor4[(l-1)][0] != 0.0) its++;
1563 
1564 	}
1565 
1566 	impts = 0;
1567 
1568 	for (i=0; i < *xyz.nti; i++) {
1569 	   l = xyz.imptor[i];
1570 
1571 	   if (itorptr->gftri1[(l-1)][0] != 0.0) impts++;
1572 	   if (itorptr->gftri2[(l-1)][0] != 0.0) impts++;
1573 	}
1574 
1575 fprintf(stderr,"wrtlmp: impts %d\n",impts);
1576 	fprintf(out,"LAMMPS data file.\n");
1577 	fprintf(out,"%4d atoms\n",*xyz.iatoms);
1578 	fprintf(out,"%4d bonds\n",*xyz.nbnd);
1579 	fprintf(out,"%4d angles\n",*xyz.nang);
1580 	fprintf(out,"%4d dihedrals\n",its+impts);
1581 	fprintf(out,"%4d impropers\n",*xyz.nti);
1582 	fprintf(out,"%4d atom types\n",ntypes);
1583 	fprintf(out,"%4d bond types\n",*xyz.nbnd);
1584 	fprintf(out,"%4d angle types\n",*xyz.nang);
1585 	fprintf(out,"%4d dihedral types\n",its+impts);
1586 	fprintf(out,"%4d improper types\n",*xyz.nti);
1587 
1588 	fprintf(out,"\n");
1589 	fprintf(out,"Pair Coeffs     #\n");
1590 	fprintf(out,"                  #\n");
1591 
1592 	for (i=0; i < ntypes; i++) {
1593 
1594 	   fprintf(out,"%2d %6.4f %6.4f       #     \n",
1595 		i+1,gffvdw[ABS(shdtyp[i]-1)*2+1],cv*gffvdw[ABS(shdtyp[i]-1)*2]);
1596 	}
1597 
1598 	fprintf(out,"\n");
1599 	fprintf(out," Bond Coeffs   #\n");
1600 	fprintf(out,"               #\n");
1601 	for (i=0; i < *xyz.nbnd; i++) {
1602 	   fprintf(out,"%2d %7.2f %7.3f       #     \n",
1603 			i+1,xyz.bk[i],xyz.bl[i]);
1604 	}
1605 
1606 	fprintf(out,"\n");
1607 	fprintf(out," Angle Coeffs     #\n");
1608 	fprintf(out,"                  #\n");
1609 	for (i=0; i < *xyz.nang; i++) {
1610 	   fprintf(out,"%2d %8.3f    %8.3f       #     \n",
1611 			i+1,xyz.ak[i],xyz.ango[i]);
1612 	}
1613 
1614 	fprintf(out,"\n");
1615 	fprintf(out," Dihedral Coeffs     #\n");
1616 	fprintf(out,"                     #\n");
1617 
1618 	its = 1;
1619 
1620 	for (i=0; i < *xyz.nt; i++) {
1621 
1622 	   l = xyz.itor[i];
1623 
1624 	   if ( torptr->gftor1[(l-1)][0] != 0.0 ||
1625 		torptr->gftor2[(l-1)][0] != 0.0 ||
1626 		torptr->gftor3[(l-1)][0] != 0.0 ||
1627 		torptr->gftor4[(l-1)][0] != 0.0) {
1628 		torr[i] = its;
1629 	   } else {
1630 		torr[i] = -1;
1631 	   }
1632 
1633 	   if (torptr->gftor1[(l-1)][0] != 0.0) {
1634 	   	fprintf(out,"%2d %8.3f  %2d %4d  %7.3f      #     \n",
1635 			its,torptr->gftor1[(l-1)][0],1,
1636 			(int) torptr->gftor1[(l-1)][1],0.0);
1637 		its++;
1638 	   }
1639 
1640 	   if (torptr->gftor2[(l-1)][0] != 0.0) {
1641 	   	fprintf(out,"%2d %8.3f  %2d %4d  %7.3f      #     \n",
1642 			its,torptr->gftor2[(l-1)][0],2,
1643 			(int) torptr->gftor2[(l-1)][1],0.0);
1644 		its++;
1645 	   }
1646 
1647 	   if (torptr->gftor3[(l-1)][0] != 0.0) {
1648 	   	fprintf(out,"%2d %8.3f  %2d %4d  %7.3f      #     \n",
1649 			its,torptr->gftor3[(l-1)][0],3,
1650 			(int) torptr->gftor3[(l-1)][1],0.0);
1651 		its++;
1652 	   }
1653 
1654 	   if (torptr->gftor4[(l-1)][0] != 0.0) {
1655 	   	fprintf(out,"%2d %8.3f  %2d %4d  %7.3f      #     \n",
1656 			its,torptr->gftor4[(l-1)][0],4,
1657 			(int) torptr->gftor4[(l-1)][1],0.0);
1658 		its++;
1659 	   }
1660 
1661 	}
1662 
1663 	impts = 1;
1664 
1665 	for (i=0; i < *xyz.nti; i++) {
1666 	   l = xyz.imptor[i];
1667 
1668 	   if ( itorptr->gftri1[(l-1)][0] != 0.0 ||
1669 		itorptr->gftri2[(l-1)][0] != 0.0) {
1670 		itorr[i] = impts;
1671 	   } else {
1672 		itorr[i] = -1;
1673 	   }
1674 
1675 	   if (itorptr->gftri1[(l-1)][0] != 0.0) {
1676 	   	fprintf(out,"%2d %8.3f  %2d %4d  %7.3f      #     \n",
1677 			impts,itorptr->gftri1[(l-1)][0],1,
1678 			(int) itorptr->gftri1[(l-1)][1],0.0);
1679 		impts++;
1680 	   }
1681 
1682 	   if (itorptr->gftri2[(l-1)][0] != 0.0) {
1683 	   	fprintf(out,"%2d %8.3f  %2d %4d  %7.3f      #     \n",
1684 			impts,itorptr->gftri2[(l-1)][0],2,
1685 			(int) itorptr->gftri2[(l-1)][1],0.0);
1686 		impts++;
1687 	   }
1688 
1689 	}
1690 
1691 	fprintf(out,"\n");
1692 	fprintf(out," Masses\n");
1693 	fprintf(out,"\n");
1694 
1695 	for (i=0; i < ntypes; i++) {
1696 
1697 	   fprintf(out,"%2d %9.6f #     \n",
1698 		i+1,gffmas[ABS(shdtyp[i]-1)]);
1699 	}
1700 
1701 	fprintf(out,"\n");
1702 	fprintf(out," Atoms\n");
1703 	fprintf(out,"\n");
1704 
1705 	for (i=0; i < *xyz.iatoms; i++) {
1706 	   fprintf(out,"%d 1 %2d %7.4f %9.6f %9.6f %9.6f #     \n",
1707 	i+1,maptyp[i],xyz.q[i],xyz.coo[3*i],xyz.coo[3*i+1],xyz.coo[3*i+2]);
1708 	}
1709 
1710 	fprintf(out,"\n");
1711 	fprintf(out," Bonds\n");
1712 	fprintf(out,"\n");
1713 
1714 	for (i=0; i < *xyz.nbnd; i++) {
1715 	   fprintf(out,"%d %d %d %d\n",
1716 			i+1,i+1,xyz.ibnd[i*2],xyz.ibnd[i*2+1]);
1717 	}
1718 
1719 	fprintf(out,"\n");
1720 	fprintf(out," Angles\n");
1721 	fprintf(out,"\n");
1722 
1723 	for (i=0; i < *xyz.nang; i++) {
1724 	   fprintf(out,"%d %d %d %d %d\n",
1725 			i+1,i+1,xyz.iang[i*3],xyz.iang[i*3+1],xyz.iang[i*3+2]);
1726 	}
1727 
1728 	fprintf(out,"\n");
1729 	fprintf(out," Dihedrals\n");
1730 	fprintf(out,"\n");
1731 
1732 	for (i=0; i < *xyz.nt; i++) {
1733 	   if (torr[i] != -1) {
1734 		l = xyz.itor[i];
1735 		its = torr[i];
1736 	   	if (torptr->gftor1[(l-1)][0] != 0.0) {
1737 		   fprintf(out,"%d %d %d %d %d %d\n",
1738 			its,its,xyz.it[i*4],xyz.it[i*4+1],
1739 				xyz.it[i*4+2],xyz.it[i*4+3]);
1740 		   its++;
1741 	   	}
1742 
1743 	   	if (torptr->gftor2[(l-1)][0] != 0.0) {
1744 		   fprintf(out,"%d %d %d %d %d %d\n",
1745 			its,its,xyz.it[i*4],xyz.it[i*4+1],
1746 				xyz.it[i*4+2],xyz.it[i*4+3]);
1747 		   its++;
1748 	   	}
1749 
1750 	   	if (torptr->gftor3[(l-1)][0] != 0.0) {
1751 		   fprintf(out,"%d %d %d %d %d %d\n",
1752 			its,its,xyz.it[i*4],xyz.it[i*4+1],
1753 				xyz.it[i*4+2],xyz.it[i*4+3]);
1754 		   its++;
1755 	   	}
1756 
1757 	   	if (torptr->gftor4[(l-1)][0] != 0.0) {
1758 		   fprintf(out,"%d %d %d %d %d %d\n",
1759 			its,its,xyz.it[i*4],xyz.it[i*4+1],
1760 				xyz.it[i*4+2],xyz.it[i*4+3]);
1761 		   its++;
1762 	   	}
1763 
1764 	   }
1765 	}
1766 
1767 	for (i=0; i < *xyz.nti; i++) {
1768 	   if (itorr[i] != -1) {
1769 
1770 		l = xyz.imptor[i];
1771 		impts = itorr[i];
1772 
1773 		if (itorptr->gftri1[(l-1)][0] != 0.0) {
1774 		   fprintf(out,"%d %d %d %d %d %d\n",
1775 			impts,impts,
1776 			xyz.iti[i*4],xyz.iti[i*4+1],
1777 			xyz.iti[i*4+2],xyz.iti[i*4+3]);
1778 		   impts++;
1779 		}
1780 
1781 		if (itorptr->gftri2[(l-1)][0] != 0.0) {
1782 		   fprintf(out,"%d %d %d %d %d %d\n",
1783 			impts,impts,
1784 			xyz.iti[i*4],xyz.iti[i*4+1],
1785 			xyz.iti[i*4+2],xyz.iti[i*4+3]);
1786 		   impts++;
1787 		}
1788 	   }
1789 
1790 	}
1791 
1792         fclose(out);
1793 }
1794 
1795 #if defined(VMS) || defined(UNDERSC)
asschg(idebug)1796 void asschg(idebug)
1797 #else
1798 #ifdef CRAY
1799 void ASSCHG(idebug)
1800 #else
1801 void asschg_(idebug)
1802 #endif
1803 #endif
1804 int *idebug;
1805 {
1806 
1807 #if defined(VMS) || defined(UNDERSC)
1808 	asschd(idebug,
1809 #else
1810 #ifdef CRAY
1811 	ASSCHD(idebug,
1812 #else
1813 	asschd_(idebug,
1814 #endif
1815 #endif
1816 		xyz.ityp,xyz.iconn,xyz.q);
1817 
1818 	if (*lammps) wrtlam();
1819 }
1820 
1821 #if defined(VMS) || defined(UNDERSC)
conn34(istat)1822 void conn34(istat)
1823 #else
1824 #ifdef CRAY
1825 void CONN34(istat)
1826 #else
1827 void conn34_(istat)
1828 #endif
1829 #endif
1830 int *istat;
1831 {
1832 #if defined(VMS) || defined(UNDERSC)
1833 	cond34(istat,
1834 #else
1835 #ifdef CRAY
1836 	COND34(istat,
1837 #else
1838 	cond34_(istat,
1839 #endif
1840 #endif
1841 		xyz.n13,xyz.i13,xyz.n14,xyz.i14,xyz.iconn);
1842 }
1843 
1844 #if defined(VMS) || defined(UNDERSC)
getinp(igtinp)1845 void getinp(igtinp)
1846 #else
1847 #ifdef CRAY
1848 void GETINP(igtinp)
1849 #else
1850 void getinp_(igtinp)
1851 #endif
1852 #endif
1853 int *igtinp;
1854 {
1855 	int i;
1856 
1857 #if defined(VMS) || defined(UNDERSC)
1858 	getind(igtinp,
1859 #else
1860 #ifdef CRAY
1861 	GETIND(igtinp,
1862 #else
1863 	getind_(igtinp,
1864 #endif
1865 #endif
1866 	 xyz.iconn,xyz.iopt,xyz.iresid,xyz.ityp,xyz.coo,xyz.q);
1867 
1868 	if (*igtinp == -1) {
1869 	   addat = *xyz.iatoms+2;
1870 
1871 /* +2 (2*3=6) for cell parameters */
1872 
1873 #if defined(VMS) || defined(UNDERSC)
1874 	   allcoo(&addat);
1875 #else
1876 #ifdef CRAY
1877 	   ALLCOO(&addat);
1878 #else
1879 	   allcoo_(&addat);
1880 #endif
1881 #endif
1882 #if defined(VMS) || defined(UNDERSC)
1883 	   getind(igtinp,
1884 #else
1885 #ifdef CRAY
1886 	   GETIND(igtinp,
1887 #else
1888 	   getind_(igtinp,
1889 #endif
1890 #endif
1891 	   xyz.iconn,xyz.iopt,xyz.iresid,xyz.ityp,xyz.coo,xyz.q);
1892 	}
1893 	for (i=0; i < 3*(*xyz.iatoms); i++) {
1894 	    xyz.ctmp[i] = xyz.coo[i];
1895 	}
1896 }
1897 
1898 #if defined(VMS) || defined(UNDERSC)
wrmon(ncyc,emin)1899 void wrmon(ncyc,emin)
1900 #else
1901 #ifdef CRAY
1902 void WRMON(ncyc,emin)
1903 #else
1904 void wrmon_(ncyc,emin)
1905 #endif
1906 #endif
1907 int *ncyc;
1908 float *emin;
1909 {
1910 	FILE *out;
1911 	char lckfile[80];
1912 	int status;
1913 
1914 	if (*nproc > 0 && *taskid != 0) return;
1915 
1916         sprintf(lckfile,"%d.ambforw",*ncyc);
1917 
1918 	out = fopen(lckfile,"w");
1919 	fprintf(out,"lock\n");
1920         fclose(out);
1921 
1922 #if defined(VMS) || defined(UNDERSC)
1923 	wrmod(ncyc,emin);
1924 #else
1925 #ifdef CRAY
1926 	WRMOD(ncyc,emin);
1927 #else
1928 	wrmod_(ncyc,emin);
1929 #endif
1930 #endif
1931 
1932 	status = remove(lckfile);
1933 }
1934 
1935 #if defined(VMS) || defined(UNDERSC)
wrtout(iun,emin)1936 void wrtout(iun,emin)
1937 #else
1938 #ifdef CRAY
1939 void WRTOUT(iun,emin)
1940 #else
1941 void wrtout_(iun,emin)
1942 #endif
1943 #endif
1944 int *iun;
1945 float *emin;
1946 {
1947 
1948 	if (*nproc > 0 && *taskid != 0) return;
1949 
1950 #if defined(VMS) || defined(UNDERSC)
1951 	wrtoud(iun,emin,
1952 #else
1953 #ifdef CRAY
1954 	WRTOUD(iun,emin,
1955 #else
1956 	wrtoud_(iun,emin,
1957 #endif
1958 #endif
1959 		xyz.iconn,xyz.ityp,xyz.coo,xyz.q,xyz.iopt);
1960 
1961 }
1962 
1963 #if defined(VMS) || defined(UNDERSC)
wrtbin(iun,emin)1964 void wrtbin(iun,emin)
1965 #else
1966 #ifdef CRAY
1967 void WRTBIN(iun,emin)
1968 #else
1969 void wrtbin_(iun,emin)
1970 #endif
1971 #endif
1972 int *iun;
1973 float *emin;
1974 {
1975 #if defined(VMS) || defined(UNDERSC)
1976 	wrtbid(iun,emin,
1977 #else
1978 #ifdef CRAY
1979 	WRTBID(iun,emin,
1980 #else
1981 	wrtbid_(iun,emin,
1982 #endif
1983 #endif
1984 		xyz.coo);
1985 }
1986 
1987 #if defined(VMS) || defined(UNDERSC)
restr(coo)1988 void restr(coo)
1989 #else
1990 #ifdef CRAY
1991 void RESTR(coo)
1992 #else
1993 void restr_(coo)
1994 #endif
1995 #endif
1996 float *coo;
1997 {
1998    int i,j,k;
1999 
2000    for (i=0; i < *xyz.iatoms; i++ ) {
2001      if (!xyz.iopt[i]) {
2002 	for (j=0; j < 3; j++) {
2003 	    coo[i*3+j] = xyz.ctmp[i*3+j];
2004 	}
2005      }
2006    }
2007 }
2008 
2009 static float *dftmp = NULL;
2010 static float *fwat = NULL;
2011 static float *fx = NULL;
2012 static float *fy = NULL;
2013 static float *fz = NULL;
2014 
2015 #if defined(VMS) || defined(UNDERSC)
enegrd(energy,par,forces)2016 void enegrd(energy,par,forces)
2017 #else
2018 #ifdef CRAY
2019 void ENEGRD(energy,par,forces)
2020 #else
2021 void enegrd_(energy,par,forces)
2022 #endif
2023 #endif
2024 float *energy;
2025 float *par;
2026 float *forces;
2027 {
2028     int memstat,wsize;
2029     float f;
2030     float d;
2031 
2032     memstat = 1;
2033     wsize = (*xyz.iatoms);
2034 
2035     if (fx == NULL) {
2036 	if ((fx = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2037 	if ((fy = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2038 	if ((fz = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2039     }
2040     if (dftmp == NULL) {
2041 	if ((dftmp = (float *) malloc((sizeof d)*3*wsize)) == NULL)
2042 		memstat = 0;
2043     }
2044 
2045     if (fwat == NULL) {
2046 	if ((fwat = (float *) malloc((sizeof d)*3*wsize)) == NULL)
2047 		memstat = 0;
2048     }
2049 
2050     if (!memstat) fprintf(stderr,"enegrd: Out of memory\n");
2051 
2052 #if defined(VMS) || defined(UNDERSC)
2053 	enegdd(energy,par,forces,
2054 #else
2055 #ifdef CRAY
2056 	ENEGDD(energy,par,forces,
2057 #else
2058 	enegdd_(energy,par,forces,
2059 #endif
2060 #endif
2061 		dftmp,fwat,fx,fy,fz,
2062 		xyz.ftmp,xyz.iopt,xyz.iresid,
2063 		xyz.n13,xyz.i13,xyz.n14,xyz.i14,
2064 		xyz.nbnd,xyz.ibnd,xyz.bl,xyz.bk,
2065 		xyz.nang,xyz.iang,xyz.ango,xyz.ak,
2066 		xyz.nt,xyz.it,xyz.trs1,xyz.trs2,xyz.trs3,xyz.trs4,
2067 		xyz.nti,xyz.iti,xyz.trsi1,xyz.trsi2,
2068 		xyz.q,xyz.iconn,xyz.ityp,xyz.watprot,nlst,lst);
2069 }
2070 
2071 #ifndef MD
2072 #if defined(VMS) || defined(UNDERSC)
optimise(energy,gtol,nsd)2073 void optimise(energy,gtol,nsd)
2074 #else
2075 #ifdef CRAY
2076 void OPTIMISE(energy,gtol,nsd)
2077 #else
2078 void optimise_(energy,gtol,nsd)
2079 #endif
2080 #endif
2081 float *energy;
2082 float *gtol;
2083 int *nsd;
2084 {
2085 #if defined(VMS) || defined(UNDERSC)
2086 	optimisd(energy,gtol,nsd,
2087 #else
2088 #ifdef CRAY
2089 	OPTIMISD(energy,gtol,nsd,
2090 #else
2091 	optimisd_(energy,gtol,nsd,
2092 #endif
2093 #endif
2094 		xyz.coo,xyz.coot,xyz.fr,xyz.frt,xyz.zr,xyz.y,xyz.yt,
2095 		xyz.pt,xyz.s,xyz.iopt,xyz.ityp);
2096 }
2097 
2098 #if defined(VMS) || defined(UNDERSC)
lbfgs(energy,gtol,nsd)2099 void lbfgs(energy,gtol,nsd)
2100 #else
2101 #ifdef CRAY
2102 void LBFGS(energy,gtol,nsd)
2103 #else
2104 void lbfgs_(energy,gtol,nsd)
2105 #endif
2106 #endif
2107 float *energy;
2108 float *gtol;
2109 int *nsd;
2110 {
2111    float d;
2112    int wsize, memstat;
2113 
2114    memstat = 1;
2115 
2116    wsize = (*xyz.iatoms)*3*(2*MSAVE+1)+2*MSAVE;
2117    if (xyz.work == NULL) {
2118 	if ((xyz.work = (float *) malloc((sizeof d)*wsize)) == NULL) {
2119 	   memstat = 0;
2120 	   fprintf(stderr,"sdrive: Out of memory\n");
2121 	}
2122    }
2123 
2124 #if defined(VMS) || defined(UNDERSC)
2125 	lbfgd(energy,gtol,nsd,
2126 #else
2127 #ifdef CRAY
2128 	LBFGD(energy,gtol,nsd,
2129 #else
2130 	lbfgd_(energy,gtol,nsd,
2131 #endif
2132 #endif
2133 		xyz.coo,xyz.fr,xyz.frt,xyz.work);
2134 }
2135 #endif
2136 
2137 static float *cx = NULL;
2138 static float *cy = NULL;
2139 static float *cz = NULL;
2140 static float *vdwe = NULL;
2141 static float *vdwr = NULL;
2142 static float *potq = NULL;
2143 static float *potv = NULL;
2144 static float *eps = NULL;
2145 static float *pre6 = NULL;
2146 static float *ftmp = NULL;
2147 static int *iag = NULL;
2148 static int *ikl = NULL;
2149 static int *idoq = NULL;
2150 static int *idov = NULL;
2151 
2152 static float *dvdwe = NULL;
2153 static float *dvdwr = NULL;
2154 static float *dpotq = NULL;
2155 static float *dpotv = NULL;
2156 static float *deps = NULL;
2157 static float *dpre6 = NULL;
2158 static float *dfftmp = NULL;
2159 static float *frac = NULL;
2160 static float *exyz = NULL;
2161 
2162 #if defined(VMS) || defined(UNDERSC)
qvdwr(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,iopt,ityp,fx,fy,fz)2163 void qvdwr(
2164 #else
2165 #ifdef CRAY
2166 void QVDWR(
2167 #else
2168 void qvdwr_(
2169 #endif
2170 #endif
2171 	ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,iopt,ityp,fx,fy,fz)
2172 float *ec;
2173 float *ev;
2174 int *nac;
2175 int *iac;
2176 int *nad;
2177 int *iad;
2178 int *iresid;
2179 float *coo;
2180 int *iconn;
2181 float *q;
2182 int *iopt;
2183 short int *ityp;
2184 float *fx;
2185 float *fy;
2186 float *fz;
2187 {
2188    float f;
2189    int i,wsize, memstat;
2190 
2191    memstat = 1;
2192 
2193    wsize = (*xyz.iatoms);
2194 
2195    if (cx == NULL) {
2196 	if ((cx = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2197 	if ((cy = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2198 	if ((cz = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2199 	if ((potq = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2200 	if ((potv = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2201 	if ((vdwe = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2202 	if ((vdwr = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2203 	if ((eps = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2204 	if ((pre6 = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2205 	if ((iag = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2206 	if ((ikl = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2207 
2208 	if (!memstat) fprintf(stderr,"qvdwr: Out of memory\n");
2209    }
2210 
2211 #if defined(VMS) || defined(UNDERSC)
2212    qvdwd(
2213 #else
2214 #ifdef CRAY
2215    QVDWD(
2216 #else
2217    qvdwd_(
2218 #endif
2219 #endif
2220 	ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,iopt,ityp,fx,fy,fz,
2221 	cx,cy,cz,vdwe,vdwr,potq,potv,eps,pre6,iag,ikl,ftmp);
2222 }
2223 
2224 
2225 #if defined(VMS) || defined(UNDERSC)
qvdwrd(ec,ev,fintr,nac,iac,nad,iad,iresid,coo,iconn,q,iopt,ityp)2226 void qvdwrd(
2227 #else
2228 #ifdef CRAY
2229 void QVDWRD(
2230 #else
2231 void qvdwrd_(
2232 #endif
2233 #endif
2234 	ec,ev,fintr,nac,iac,nad,iad,iresid,coo,iconn,q,iopt,ityp)
2235 float *ec;
2236 float *ev;
2237 float *fintr;
2238 int *nac;
2239 int *iac;
2240 int *nad;
2241 int *iad;
2242 int *iresid;
2243 float *coo;
2244 int *iconn;
2245 float *q;
2246 int *iopt;
2247 short int *ityp;
2248 {
2249    float f;
2250    int i,wsize, memstat;
2251 
2252    memstat = 1;
2253 
2254    wsize = (*xyz.iatoms);
2255    if (cx != NULL) {
2256 	free(cx);
2257 	free(cy);
2258 	free(cz);
2259 	free(fx);
2260 	free(fy);
2261 	free(fz);
2262 	free(potq);
2263 	free(potv);
2264 	free(vdwe);
2265 	free(vdwr);
2266 	free(eps);
2267 	free(pre6);
2268 	free(ftmp);
2269 	cx = NULL;
2270 	cy = NULL;
2271 	cz = NULL;
2272 /*
2273 	fx = NULL;
2274 	fy = NULL;
2275 	fz = NULL;
2276 */
2277 	vdwe = NULL;
2278 	vdwr = NULL;
2279 	potq = NULL;
2280 	potv = NULL;
2281 	eps = NULL;
2282 	pre6 = NULL;
2283 	ftmp = NULL;
2284    }
2285 
2286    if (dpotq == NULL) {
2287 	if ((dpotq = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2288 	if ((dpotv = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2289 	if ((dvdwe = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2290 	if ((dvdwr = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2291 	if ((deps = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2292 	if ((dpre6 = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2293 	if ((iag = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2294 	if ((ikl = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2295 	if ((dfftmp = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2296 
2297 	if (!memstat) fprintf(stderr,"qvdwd: Out of memory\n");
2298    }
2299 
2300 #if defined(VMS) || defined(UNDERSC)
2301    qvdwdd(
2302 #else
2303 #ifdef CRAY
2304    QVDWDD(
2305 #else
2306    qvdwdd_(
2307 #endif
2308 #endif
2309 	ec,ev,fintr,nac,iac,nad,iad,iresid,coo,iconn,q,iopt,ityp,
2310 	dvdwe,dvdwr,dpotq,dpotv,deps,dpre6,iag,ikl,dfftmp);
2311 }
2312 
2313 
2314 #if defined(VMS) || defined(UNDERSC)
qvc(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,forces,cellder,iopt,ityp)2315 void qvc(
2316 #else
2317 #ifdef CRAY
2318 void QVC(
2319 #else
2320 void qvc_(
2321 #endif
2322 #endif
2323 	ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,forces,cellder,iopt,ityp)
2324 float *ec;
2325 float *ev;
2326 int *nac;
2327 int *iac;
2328 int *nad;
2329 int *iad;
2330 int *iresid;
2331 float *coo;
2332 int *iconn;
2333 float *q;
2334 float *forces;
2335 float *cellder;
2336 int *iopt;
2337 short int *ityp;
2338 {
2339    float f;
2340    int i,wsize, memstat;
2341 
2342    memstat = 1;
2343 
2344    wsize = (*xyz.iatoms);
2345    if (cx != NULL) {
2346 	free(cx);
2347 	free(cy);
2348 	free(cz);
2349 	free(fx);
2350 	free(fy);
2351 	free(fz);
2352 	free(potq);
2353 	free(potv);
2354 	free(vdwe);
2355 	free(vdwr);
2356 	free(eps);
2357 	free(pre6);
2358 	free(ftmp);
2359 	cx = NULL;
2360 	cy = NULL;
2361 	cz = NULL;
2362 	fx = NULL;
2363 	fy = NULL;
2364 	fz = NULL;
2365 	vdwe = NULL;
2366 	vdwr = NULL;
2367 	potq = NULL;
2368 	potv = NULL;
2369 	eps = NULL;
2370 	pre6 = NULL;
2371 	ftmp = NULL;
2372    }
2373 
2374    if (dpotq == NULL) {
2375 	if ((dpotq = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2376 	if ((dpotv = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2377 	if ((dvdwe = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2378 	if ((dvdwr = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2379 	if ((deps = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2380 	if ((dpre6 = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2381 	if ((iag = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2382 	if ((ikl = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2383 	if ((dfftmp = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2384 	if ((frac = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2385 
2386 	if ((exyz = (float *) malloc((sizeof f)*3*wsize*125)) == NULL) memstat = 0;
2387 
2388 	if (!memstat) fprintf(stderr,"qvdwd: Out of memory\n");
2389    }
2390 
2391 #if defined(VMS) || defined(UNDERSC)
2392    qvd(
2393 #else
2394 #ifdef CRAY
2395    QVD(
2396 #else
2397    qvd_(
2398 #endif
2399 #endif
2400 	ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,forces,cellder,iopt,ityp,
2401 	dvdwe,dvdwr,dpotq,dpotv,deps,dpre6,iag,ikl,dftmp,dfftmp,frac,exyz);
2402 }
2403 
2404 
2405 #if defined(VMS) || defined(UNDERSC)
qenvdw(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,forces,iopt,nlst,lst,ityp)2406 void qenvdw(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2407       q,forces,iopt,nlst,lst,ityp)
2408 #else
2409 #ifdef CRAY
2410 void QENVDW(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2411       q,forces,iopt,nlst,lst,ityp)
2412 #else
2413 void qenvdw_(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2414       q,forces,iopt,nlst,lst,ityp)
2415 #endif
2416 #endif
2417 float *ec;
2418 float *ev;
2419 int *nac;
2420 int *iac;
2421 int *nad;
2422 int *iad;
2423 int *iresid;
2424 float *coo;
2425 int *iconn;
2426 float *q;
2427 float *forces;
2428 int *iopt;
2429 int *nlst;
2430 int *lst;
2431 short int *ityp;
2432 {
2433    float f;
2434    int i,wsize, memstat;
2435 
2436    memstat = 1;
2437 
2438    wsize = (*xyz.iatoms);
2439    if (cx != NULL) {
2440 	free(cx);
2441 	free(cy);
2442 	free(cz);
2443 	free(fx);
2444 	free(fy);
2445 	free(fz);
2446 	free(potq);
2447 	free(potv);
2448 	free(vdwe);
2449 	free(vdwr);
2450 	free(eps);
2451 	free(pre6);
2452 	free(ftmp);
2453 	cx = NULL;
2454 	cy = NULL;
2455 	cz = NULL;
2456 	fx = NULL;
2457 	fy = NULL;
2458 	fz = NULL;
2459 	vdwe = NULL;
2460 	vdwr = NULL;
2461 	potq = NULL;
2462 	potv = NULL;
2463 	eps = NULL;
2464 	pre6 = NULL;
2465 	ftmp = NULL;
2466    }
2467 
2468    if (dpotq == NULL) {
2469 	if ((dpotq = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2470 	if ((dpotv = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2471 	if ((dvdwe = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2472 	if ((dvdwr = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2473 	if ((deps = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2474 	if ((dpre6 = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2475 	if ((iag = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2476 	if ((ikl = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2477 	if ((idoq = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2478 	if ((idov = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2479 	if ((dftmp = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2480 	if ((dfftmp = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2481 
2482 	if (!memstat) fprintf(stderr,"qenvdw: Out of memory\n");
2483    }
2484 
2485 #if defined(VMS) || defined(UNDERSC)
2486    qenvdd(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2487          q,forces,iopt,nlst,lst,ityp,
2488 #else
2489 #ifdef CRAY
2490    QENVDD(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2491          q,forces,iopt,nlst,lst,ityp,
2492 #else
2493    qenvdd_(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2494          q,forces,iopt,nlst,lst,ityp,
2495 #endif
2496 #endif
2497 	 idoq,idov,dvdwe,dvdwr,dpotq,dpotv,deps,dpre6,iag,ikl,dftmp,dfftmp);
2498 }
2499 
2500 #if defined(VMS) || defined(UNDERSC)
qvnoe(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,q,forces,iopt,ityp,iwtpr)2501 void qvnoe(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2502       q,forces,iopt,ityp,iwtpr)
2503 #else
2504 #ifdef CRAY
2505 void QVNOE(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2506       q,forces,iopt,ityp,iwtpr)
2507 #else
2508 void qvnoe_(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2509       q,forces,iopt,ityp,iwtpr)
2510 #endif
2511 #endif
2512 float *ec;
2513 float *ev;
2514 int *nac;
2515 int *iac;
2516 int *nad;
2517 int *iad;
2518 int *iresid;
2519 float *coo;
2520 int *iconn;
2521 float *q;
2522 float *forces;
2523 int *iopt;
2524 int *ityp;
2525 int *iwtpr;
2526 {
2527    float f;
2528    int i,wsize, memstat;
2529 
2530    memstat = 1;
2531 
2532    wsize = (*xyz.iatoms);
2533    if (cx != NULL) {
2534 	free(cx);
2535 	free(cy);
2536 	free(cz);
2537 	free(fx);
2538 	free(fy);
2539 	free(fz);
2540 	free(potq);
2541 	free(potv);
2542 	free(vdwe);
2543 	free(vdwr);
2544 	free(eps);
2545 	free(pre6);
2546 	free(ftmp);
2547 	cx = NULL;
2548 	cy = NULL;
2549 	cz = NULL;
2550 	fx = NULL;
2551 	fy = NULL;
2552 	fz = NULL;
2553 	vdwe = NULL;
2554 	vdwr = NULL;
2555 	potq = NULL;
2556 	potv = NULL;
2557 	eps = NULL;
2558 	pre6 = NULL;
2559 	ftmp = NULL;
2560    }
2561 
2562    if (dpotq == NULL) {
2563 	if ((dpotq = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2564 	if ((dpotv = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2565 	if ((dvdwe = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2566 	if ((dvdwr = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2567 	if ((deps = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2568 	if ((dpre6 = (float *) malloc((sizeof f)*wsize)) == NULL) memstat = 0;
2569 	if ((iag = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2570 	if ((ikl = (int *) malloc((sizeof i)*wsize)) == NULL) memstat = 0;
2571 	if ((dftmp = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2572 	if ((dfftmp = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2573 
2574 	if (!memstat) fprintf(stderr,"qvnoe: Out of memory\n");
2575    }
2576 
2577 #if defined(VMS) || defined(UNDERSC)
2578    qvnod(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2579          q,forces,iopt,ityp,iwtpr,
2580 #else
2581 #ifdef CRAY
2582    QVNOD(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2583          q,forces,iopt,ityp,iwtpr,
2584 #else
2585    qvnod_(ec,ev,nac,iac,nad,iad,iresid,coo,iconn,
2586          q,forces,iopt,ityp,iwtpr,
2587 #endif
2588 #endif
2589 	 dvdwe,dvdwr,dpotq,dpotv,deps,dpre6,iag,ikl,dftmp,dfftmp);
2590 }
2591 
2592 #if defined(VMS) || defined(UNDERSC)
esolb()2593 void esolb()
2594 #else
2595 #ifdef CRAY
2596 void ESOLB()
2597 #else
2598 void esolb_()
2599 #endif
2600 #endif
2601 {
2602    int memstat,ZSize;
2603    float d;
2604 
2605    ZSize = *xyz.mxnat;
2606    memstat = 1;
2607 
2608    if (drb == NULL) {
2609    if ((drb = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
2610 	memstat = 0;
2611    }
2612    if ((rsolv = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2613 	memstat = 0;
2614    }
2615    if ((rborn = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2616 	memstat = 0;
2617    }
2618    if ((shct = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2619 	memstat = 0;
2620    }
2621    }
2622 
2623 #if defined(VMS) || defined(UNDERSC)
2624    esolv(
2625 #else
2626 #ifdef CRAY
2627    ESOLV(
2628 #else
2629    esolv_(
2630 #endif
2631 #endif
2632 	xyz.coo,xyz.fr,drb,rsolv,rborn,shct,xyz.q,xyz.iconn,xyz.ityp);
2633 }
2634 
2635 #if defined(VMS) || defined(UNDERSC)
mseed()2636 int mseed()
2637 #else
2638 #ifdef CRAY
2639 int MSEED()
2640 #else
2641 int mseed_()
2642 #endif
2643 #endif
2644 {
2645   return (int)(((long)time(NULL)+(long)getpid()) % (long)1000000);
2646 }
2647 
2648 
2649 #if defined(VMS) || defined(UNDERSC)
makbox()2650 void makbox()
2651 #else
2652 #ifdef CRAY
2653 void MAKBOX()
2654 #else
2655 void makbox_()
2656 #endif
2657 #endif
2658 {
2659 #if defined(VMS) || defined(UNDERSC)
2660 	makbod(
2661 #else
2662 #ifdef CRAY
2663 	MAKBOD(
2664 #else
2665 	makbod_(
2666 #endif
2667 #endif
2668 		xyz.coo);
2669 }
2670 
2671 #if defined(VMS) || defined(UNDERSC)
filbox()2672 void filbox()
2673 #else
2674 #ifdef CRAY
2675 void FILBOX()
2676 #else
2677 void filbox_()
2678 #endif
2679 #endif
2680 {
2681 #if defined(VMS) || defined(UNDERSC)
2682 	filbod(
2683 #else
2684 #ifdef CRAY
2685 	FILBOD(
2686 #else
2687 	filbod_(
2688 #endif
2689 #endif
2690 		water,xyz.coo,xyz.iconn,xyz.iresid,xyz.ityp,
2691 		xyz.n13,xyz.i13,xyz.n14,
2692 		xyz.nbnd,xyz.ibnd,xyz.bl,xyz.bk,
2693 		xyz.nang,xyz.iang,xyz.ango,xyz.ak,
2694 		xyz.q,xyz.iopt,xyz.watprot);
2695 }
2696 
2697 #if defined(VMS) || defined(UNDERSC)
cntwat()2698 void cntwat()
2699 #else
2700 #ifdef CRAY
2701 void CNTWAT()
2702 #else
2703 void cntwat_()
2704 #endif
2705 #endif
2706 {
2707 #if defined(VMS) || defined(UNDERSC)
2708 	cntwad(
2709 #else
2710 #ifdef CRAY
2711 	CNTWAD(
2712 #else
2713 	cntwad_(
2714 #endif
2715 #endif
2716 		water,xyz.coo,xyz.iconn,xyz.iresid,xyz.ityp,
2717 		xyz.q,xyz.iopt,qpot);
2718 }
2719 
2720 #if defined(VMS) || defined(UNDERSC)
watcnt()2721 void watcnt()
2722 #else
2723 #ifdef CRAY
2724 void WATCNT()
2725 #else
2726 void watcnt_()
2727 #endif
2728 #endif
2729 {
2730 
2731 #if defined(VMS) || defined(UNDERSC)
2732    watcnd(
2733 #else
2734 #ifdef CRAY
2735    WATCND(
2736 #else
2737    watcnd_(
2738 #endif
2739 #endif
2740 	xyz.coo);
2741 }
2742 
2743 #if defined(VMS) || defined(UNDERSC)
watlst(niwat)2744 void watlst(niwat)
2745 #else
2746 #ifdef CRAY
2747 void WATLST(niwat)
2748 #else
2749 void watlst_(niwat)
2750 #endif
2751 #endif
2752 int *niwat;
2753 {
2754    int i,nelem;
2755 
2756    nelem = 2*(*niwat);
2757 
2758    if (listw == NULL) {
2759 	if ((listw = (int *) malloc((sizeof i)*2*nelem)) == NULL) {
2760 	   fprintf(stderr,"Out of memory\n");
2761 	}
2762    }
2763 
2764 #if defined(VMS) || defined(UNDERSC)
2765    watlsd(
2766 #else
2767 #ifdef CRAY
2768    WATLSD(
2769 #else
2770    watlsd_(
2771 #endif
2772 #endif
2773 	xyz.coo,xyz.watprot,listw);
2774 }
2775 
2776 #if defined(VMS) || defined(UNDERSC)
stutab()2777 void stutab()
2778 #else
2779 #ifdef CRAY
2780 void STUTAB()
2781 #else
2782 void stutab_()
2783 #endif
2784 #endif
2785 {
2786 
2787    float d;
2788    int ZSize;
2789 
2790    ZSize = 10000;
2791 
2792    if ((woo = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2793 	fprintf(stderr,"Out of memory\n");
2794    }
2795 
2796    if ((dewoo = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2797 	fprintf(stderr,"Out of memory\n");
2798    }
2799 
2800    if ((whh = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2801 	fprintf(stderr,"Out of memory\n");
2802    }
2803 
2804    if ((dewhh = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2805 	fprintf(stderr,"Out of memory\n");
2806    }
2807 
2808    if ((woh = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2809 	fprintf(stderr,"Out of memory\n");
2810    }
2811 
2812    if ((dewoh = (float *) malloc((sizeof d)*ZSize)) == NULL) {
2813 	fprintf(stderr,"Out of memory\n");
2814    }
2815 
2816 #if defined(VMS) || defined(UNDERSC)
2817    stutad(
2818 #else
2819 #ifdef CRAY
2820    STUTAD(
2821 #else
2822    stutad_(
2823 #endif
2824 #endif
2825 	woo,whh,woh,dewoo,dewhh,dewoh);
2826 }
2827 
2828 #if defined(VMS) || defined(UNDERSC)
etutab(nsize)2829 void etutab(nsize)
2830 #else
2831 #ifdef CRAY
2832 void ETUTAB(nsize)
2833 #else
2834 void etutab_(nsize)
2835 #endif
2836 #endif
2837 int *nsize;
2838 {
2839 
2840    float r;
2841    int ZSize;
2842 
2843    ZSize = *nsize;
2844 
2845    if ((ewoo = (float *) malloc((sizeof r)*ZSize)) == NULL) {
2846 	fprintf(stderr,"Out of memory\n");
2847    }
2848 
2849    if ((edwoo = (float *) malloc((sizeof r)*ZSize)) == NULL) {
2850 	fprintf(stderr,"Out of memory\n");
2851    }
2852 
2853    if ((ewhh = (float *) malloc((sizeof r)*ZSize)) == NULL) {
2854 	fprintf(stderr,"Out of memory\n");
2855    }
2856 
2857    if ((edwhh = (float *) malloc((sizeof r)*ZSize)) == NULL) {
2858 	fprintf(stderr,"Out of memory\n");
2859    }
2860 
2861    if ((ewoh = (float *) malloc((sizeof r)*ZSize)) == NULL) {
2862 	fprintf(stderr,"Out of memory\n");
2863    }
2864 
2865    if ((edwoh = (float *) malloc((sizeof r)*ZSize)) == NULL) {
2866 	fprintf(stderr,"Out of memory\n");
2867    }
2868 
2869 #if defined(VMS) || defined(UNDERSC)
2870    etutad(nsize,
2871 #else
2872 #ifdef CRAY
2873    ETUTAD(nsize,
2874 #else
2875    etutad_(nsize,
2876 #endif
2877 #endif
2878 	ewoo,ewhh,ewoh,edwoo,edwhh,edwoh);
2879 }
2880 
2881 #if defined(VMS) || defined(UNDERSC)
fstwat(ew,coo,forces,q)2882 void fstwat(ew,coo,forces,q)
2883 #else
2884 #ifdef CRAY
2885 void FSTWAT(ew,coo,forces,q)
2886 #else
2887 void fstwat_(ew,coo,forces,q)
2888 #endif
2889 #endif
2890 float *ew;
2891 float *coo;
2892 float *forces;
2893 float *q;
2894 {
2895    float f;
2896    int wsize, memstat;
2897 
2898    memstat = 1;
2899 
2900    wsize = (*xyz.iatoms);
2901 
2902    if (dfftmp == NULL) {
2903 	if ((dfftmp = (float *) malloc((sizeof f)*3*wsize)) == NULL) memstat = 0;
2904 
2905 	if (!memstat) fprintf(stderr,"fstwat: Out of memory\n");
2906    }
2907 
2908 #if defined(VMS) || defined(UNDERSC)
2909 	fstwad(ew,coo,forces,q,
2910 #else
2911 #ifdef CRAY
2912 	FSTWAD(ew,coo,forces,q,
2913 #else
2914 	fstwad_(ew,coo,forces,q,
2915 #endif
2916 #endif
2917 		dfftmp,listw,woo,whh,woh,dewoo,dewhh,dewoh);
2918 }
2919 
2920 #if defined(VMS) || defined(UNDERSC)
bldlst()2921 void bldlst()
2922 #else
2923 #ifdef CRAY
2924 void BLDLST()
2925 #else
2926 void bldlst_()
2927 #endif
2928 #endif
2929 {
2930    int memstat,i,size;
2931 
2932    size = *xyz.iatoms;
2933    memstat = 1;
2934 
2935    if (nlst == NULL) {
2936 	if ((nlst = (int *) malloc((sizeof i)*size)) == NULL) {
2937 	   memstat = 0;
2938 	   fprintf(stderr,"bldlst: Out of memory\n");
2939 	}
2940    }
2941 
2942    size = MXNEIB*size;
2943    if (lst == NULL) {
2944 	if ((lst = (int *) malloc((sizeof i)*size)) == NULL) {
2945 	   memstat = 0;
2946 	   fprintf(stderr,"bldlst: Out of memory\n");
2947 	}
2948    }
2949 
2950 #if defined(VMS) || defined(UNDERSC)
2951    bldlsd(
2952 #else
2953 #ifdef CRAY
2954    BLDLSD(
2955 #else
2956    bldlsd_(
2957 #endif
2958 #endif
2959 	xyz.coo,xyz.iresid,nlst,lst,&memstat);
2960 }
2961 
2962 #if defined(VMS) || defined(UNDERSC)
allerf()2963 void allerf()
2964 #else
2965 #ifdef CRAY
2966 void ALLERF()
2967 #else
2968 void allerf_()
2969 #endif
2970 #endif
2971 {
2972 
2973    float f;
2974    int ZSize;
2975 /*
2976    RC = 15.0
2977    ZSize = 3000000;
2978 */
2979 
2980    ZSize = 2700000;
2981    if ((apprerf = (float *) malloc((sizeof f)*ZSize)) == NULL) {
2982 	fprintf(stderr,"Out of memory\n");
2983    }
2984 
2985 /*
2986    RC = 15.0
2987    ZSize = 9000000;
2988 */
2989    ZSize = 7290000;
2990 
2991    if ((appexp = (float *) malloc((sizeof f)*ZSize)) == NULL) {
2992 	fprintf(stderr,"Out of memory\n");
2993    }
2994 
2995 #if defined(VMS) || defined(UNDERSC)
2996    allerd(
2997 #else
2998 #ifdef CRAY
2999    ALLERD(
3000 #else
3001    allerd_(
3002 #endif
3003 #endif
3004 	apprerf,appexp);
3005 }
3006 
3007 #if defined(VMS) || defined(UNDERSC)
apperfc(r,fc,fc2)3008 void apperfc(r,fc,fc2)
3009 #else
3010 #ifdef CRAY
3011 void APPERFC(r,fc,fc2)
3012 #else
3013 void apperfc_(r,fc,fc2)
3014 #endif
3015 #endif
3016 float *r;
3017 float *fc;
3018 float *fc2;
3019 {
3020       float r1000,x;
3021       int ir;
3022       float rr,rr2;
3023 
3024       rr = *r;
3025       rr2 = rr*rr;
3026 
3027       if (*r <= 2.7) {
3028           r1000 = (float) (*r) * 1000000.0;
3029           ir = (int) r1000;
3030           x = (r1000 - (float) ir);
3031           *fc = ((1.0-(float) x)*apprerf[ir] + (float) x*apprerf[ir+1]);
3032       } else {
3033           *fc = apprerf[2699999];
3034       }
3035 
3036       if (rr2 <= 7.29) {
3037           r1000 = (float) (rr2) * 1000000.0;
3038           ir = (int) r1000;
3039           x = (r1000 - (float) ir);
3040           *fc2 = ((1.0-(float) x)*appexp[ir] + (float) x*appexp[ir+1]);
3041       } else {
3042           *fc2 = appexp[7289999];
3043       }
3044 
3045 }
3046 
3047 /*
3048 #if defined(VMS) || defined(UNDERSC)
3049 apperfc(r,fc,fc2)
3050 #else
3051 #ifdef CRAY
3052 APPERFC(r,fc,fc2)
3053 #else
3054 apperfc_(r,fc,fc2)
3055 #endif
3056 #endif
3057 float *r;
3058 float *fc;
3059 float *fc2;
3060 {
3061       float r1000,x;
3062       int ir;
3063       float rr,rr2;
3064 
3065       rr = *r;
3066       rr2 = rr*rr;
3067 
3068       if (*r <= 3.0) {
3069           r1000 = (float) (*r) * 1000000.0;
3070           ir = (int) r1000;
3071           x = (r1000 - (float) ir);
3072           *fc = ((1.0-(float) x)*apprerf[ir] + (float) x*apprerf[ir+1]);
3073       } else {
3074           *fc = apprerf[2999999];
3075       }
3076 
3077       if (rr2 <= 9.0) {
3078           r1000 = (float) (rr2) * 1000000.0;
3079           ir = (int) r1000;
3080           x = (r1000 - (float) ir);
3081           *fc2 = ((1.0-(float) x)*appexp[ir] + (float) x*appexp[ir+1]);
3082       } else {
3083           *fc2 = appexp[8999999];
3084       }
3085 
3086 }
3087 */
3088 
3089 #if defined(VMS) || defined(UNDERSC)
appbnx()3090 void appbnx()
3091 #else
3092 #ifdef CRAY
3093 void APPBNX()
3094 #else
3095 void appbnx_()
3096 #endif
3097 #endif
3098 {
3099 #if defined(VMS) || defined(UNDERSC)
3100 	appbnd(
3101 #else
3102 #ifdef CRAY
3103 	APPBND(
3104 #else
3105 	appbnd_(
3106 #endif
3107 #endif
3108 		xyz.coo,xyz.ityp);
3109 }
3110 
3111 #ifdef MD
3112 
3113 #if defined(VMS) || defined(UNDERSC)
allmd(ZSizep)3114 void allmd(ZSizep)
3115 #else
3116 #ifdef CRAY
3117 void ALLMD(ZSizep)
3118 #else
3119 void allmd_(ZSizep)
3120 #endif
3121 #endif
3122 int *ZSizep;
3123 {
3124    int memstat,i;
3125    float d;
3126    int ZSize;
3127 
3128    ZSize = *ZSizep;
3129    memstat = 1;
3130 
3131    if ((md.v = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
3132 	memstat = 0;
3133    }
3134 
3135    if ((md.a = (float *) malloc((sizeof d)*ZSize*3)) == NULL) {
3136 	memstat = 0;
3137    }
3138 
3139    if ((md.m = (float *) malloc((sizeof d)*ZSize)) == NULL) {
3140 	memstat = 0;
3141    }
3142 
3143    for (i=0; i < ZSize*3; i++) {
3144 	md.a[i] = 0.0;
3145    }
3146 }
3147 
3148 #if defined(VMS) || defined(UNDERSC)
assmas()3149 void assmas()
3150 #else
3151 #ifdef CRAY
3152 void ASSMAS()
3153 #else
3154 void assmas_()
3155 #endif
3156 #endif
3157 {
3158 #if defined(VMS) || defined(UNDERSC)
3159 	assmad(
3160 #else
3161 #ifdef CRAY
3162 	ASSMAD(
3163 #else
3164 	assmad_(
3165 #endif
3166 #endif
3167 		xyz.ityp,md.m);
3168 }
3169 
3170 #if defined(VMS) || defined(UNDERSC)
velini()3171 void velini()
3172 #else
3173 #ifdef CRAY
3174 void VELINI()
3175 #else
3176 void velini_()
3177 #endif
3178 #endif
3179 {
3180 #if defined(VMS) || defined(UNDERSC)
3181 	velind(
3182 #else
3183 #ifdef CRAY
3184 	VELIND(
3185 #else
3186 	velind_(
3187 #endif
3188 #endif
3189 		xyz.coo,xyz.fr,md.v,md.a,md.m);
3190 }
3191 
3192 #if defined(VMS) || defined(UNDERSC)
verlet(istep)3193 void verlet(istep)
3194 #else
3195 #ifdef CRAY
3196 void VERLET(istep)
3197 #else
3198 void verlet_(istep)
3199 #endif
3200 #endif
3201 int *istep;
3202 {
3203 #if defined(VMS) || defined(UNDERSC)
3204 	verled(istep,
3205 #else
3206 #ifdef CRAY
3207 	VERLED(istep,
3208 #else
3209 	verled_(istep,
3210 #endif
3211 #endif
3212 		xyz.coo,xyz.fr,md.v,md.a,md.m,xyz.ityp);
3213 }
3214 #endif
3215 
prtmas_(iopt)3216 void prtmas_(iopt)
3217 int *iopt;
3218 {
3219  int i;
3220 
3221 	for (i=0; i < *xyz.nang; i++) {
3222 	fprintf(stderr,"%d ang %d %d %d %f %f\n",i,xyz.iang[i*3],xyz.iang[i*3+1],xyz.iang[i*3+2],xyz.ango[i],xyz.ak[i]);
3223 	}
3224 }
3225