[go: up one dir, main page]

Menu

[r79]: / tags / xmd-2.5.37 / src / xmd.c  Maximize  Restore  History

Download this file

384 lines (307 with data), 8.6 kB

  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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/*
xmd - molecular dynamics for metals and ceramics
By Jonathan Rifkin <jon.rifkin@uconn.edu>
Copyright 1995-2004 Jonathan Rifkin
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
************************************************************************
File Includes
************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <signal.h>
#include "iomngr.h"
#include "strsub.h"
#include "cdsubs.h"
#include "cddoc.h"
#include "cdhouse.h"
#include "cdthread.h" /* SetNumProc() */
#include "config.h" /* automake/autoconf defines */
#ifdef __TURBOC__
#include <alloc.h>
#endif
/*
************************************************************************
Defines
************************************************************************
*/
#ifdef __TURBOC__
#define SIGNUMBER 15
#else
#define SIGNUMBER SIGTERM
#endif
#define BOOLEAN int
#define FALSE 0
#define TRUE 1
/* Test ZETA calculcation in CSi calculation */
#define TEST_ZETA
#undef TEST_ZETA
/*
************************************************************************
Local Function Prototypes
************************************************************************
*/
void ihandler (int cursig);
char *newpath (char *, char *);
/*
************************************************************************
External Variables
************************************************************************
*/
/* Defined in cdsubs.c */
extern Particle_t *a,*b;
extern Simulation_t *s;
extern FILE *out;
extern LIST *inlist;
/* Signal Handler (for handling program interupts) */
int isig = 0;
/* XMD Version and Release (used to identify state files */
int XMD_Version_g = 2;
int XMD_Release_g = 5;
/* Tersoff C-Si Zeta Test */
#ifdef TEST_ZETA
double MinZeta_g;
int MinStep_g=0;
int MinI_g;
int MinJ_g;
#endif
/*
************************************************************************
Main Routine
************************************************************************
*/
int main (int argc, char *argv[])
{
/* DECLARE VARIALBES */
char instr[256];
BOOLEAN IsProgramDone;
FILE *infile;
int iopt;
int imacro;
char MacroName[2];
/* PRINT ID */
#ifdef __TURBOC__
printf ("XMD (Version %s %s) (PC)\n", VERSION, __DATE__);
#else
printf ("XMD (Version %s %s)\n",VERSION, __DATE__);
#endif
/* Thread Message */
#ifdef HAVE_LIBPTHREAD
printf ("\nUsing pthread library.\n");
#else
printf ("\nNot using pthread library.\n");
#endif
/* Patch message */
#ifdef INTEL
printf ("Using asm(\"finit\"); patch in thread routines.\n");
#endif
CheckMem_g = FALSE;
iopt = 1;
/* Read command lines options until non-option found ( '-' is non-option ) */
while (argc-iopt > 0 && argv[iopt][0]=='-' && argv[iopt][1])
{
/* Request for help */
if
(
!strcmpi("-?", argv[iopt]) ||
!strcmpi("-h", argv[iopt]) ||
!strcmpi("-help",argv[iopt])
)
{
write_doc();
return 0;
}
/* Check memory option -c */
else if (!strcmpi(argv[iopt],"-c"))
{
CheckMem_g = TRUE;
}
/* Debug option */
else if (!strcmpi(argv[iopt],"-d"))
{
Debug_g = TRUE;
}
/* Number of Thread option -pn or -p n */
else if (argv[iopt][0]=='-' && argv[iopt][1]=='p')
{
/* Number of threads is part of token */
if (argv[iopt][2]>='0' && argv[iopt][2]<='9')
{
SetNumProc (atoi(argv[iopt]+2));
}
/* Number of threads is separate token */
else
{
SetNumProc (atoi(argv[iopt+1]));
iopt++;
}
/* Print number of processors requested */
printf ("\nNumber of processors requested = %i\n", GetNumProc());
}
iopt++;
}
/* Test for incorrect input format - write messages */
if (argc-iopt==0)
{
write_usage();
return 0;
}
/* Start program timer */
StartProgramTimer();
/* Read command line macros (upto nine) */
LOOP (imacro, 9)
{
/* Don't read to many */
if (iopt+imacro+1 >= argc)
break;
/* Add Macro to list */
MacroName[0] = '1' + imacro;
MacroName[1] = '\0';
AddMacro (MacroName, argv[imacro+iopt+1]);
}
/* INITIALIZE VARIABLES */
init();
/* INSTALL SIGNAL HANDLERS */
signal (SIGINT, ihandler); /* intercepts ^C */
signal (SIGNUMBER, ihandler); /* intercepts "kill <pid>" */
/* OPEN OUTPUT FILE */
out = stdout;
/* INITIALIZE LIST OF INPUT FILES */
inlist = m_ini_list ();
/***********************/
/* READ INITIAL FILE */
/***********************/
infile = fopen ("config.xmd", "rt");
if (infile==NULL)
infile = fopen ( newpath (argv[0], "config.xmd"), "rt");
if (infile)
{
m_add_list (&inlist, infile, "f");
/* PROCESS COMMANDS */
IsProgramDone = FALSE;
while (!isig && !IsProgramDone && m_gets_list_f(instr,256,inlist)!=NULL)
{
/* ECHO STRING */
if (s->echo)
printf ("%s\n",instr);
read_command (instr, &IsProgramDone);
CHECK_HEAP
}
/* CLOSE CURRENT INPUT */
m_del_list (&inlist);
}
/*********************/
/* OPEN INPUT FILE */
/*********************/
if (!strcmp("-",argv[iopt]))
infile = stdin;
else {
infile = fopen (argv[iopt], "rt");
if (infile==NULL)
{
printf("Sorry. Cannot open %s\n",argv[iopt]);
return(1);
}
}
/* ADD TO FILE MANAGER LIST */
m_add_list (&inlist, infile, "f");
/* MOVE THROUGH FILE STACK */
while (inlist)
{
/* PROCESS COMMANDS */
IsProgramDone = FALSE;
while (!isig && !IsProgramDone && m_gets_list_f(instr,256,inlist)!=NULL)
{
/* ECHO STRING */
if (s->echo)
printf ("%s\n",instr);
/* Send command string to command function */
read_command (instr, &IsProgramDone);
CHECK_HEAP
}
/* CLOSE CURRENT INPUT */
m_del_list (&inlist);
}
/* If Termineated by External Signal save state */
if (isig==1)
CleanAfterError();
/* Call clean up routine */
CleanBeforeEnd();
#ifdef TEST_ZETA
if (Debug_g)
{
printf ("MinZeta = %le\n", MinZeta_g);
printf ("MinStep = %i\n", MinStep_g);
printf ("MinI = %i\n", MinI_g);
printf ("MinJ = %i\n", MinJ_g);
}
#endif
/* END PROGRAM */
return(0);
}
/*
************************************************************************
Local Functions
************************************************************************
*/
/*
Interupt handler (called when program recieves operating system signal
*/
void ihandler (int cursig)
{
/* SET SIGNAL FLAG */
isig = 1;
/* FLUSH BUFFERS */
fflush (stdout);
/* PRINT MESSAGE */
printf ("Interupt signal %i is caught.\n", cursig);
/* RE-INSTALL SIGNAL HANDLER */
signal (cursig, ihandler);
}
/* EXTRACT DIRECTORY PATH FROM FILE PATH */
char *newpath (char *dpath, char *fpath)
{
static char tpath[512];
char colon = ':';
#ifdef __TURBOC__
char slash = '\\';
#else
char slash = '/';
#endif
int l;
l = strlen(dpath) + strlen(fpath) + 1;
if (l==0)
return(NULL);
/* PUT DIRECTORY PATH AT FRONT */
strcpy (tpath, dpath);
l = strlen(tpath);
while (tpath[l]!=slash && tpath[l]!=colon && l>=0)
l--;
l++;
ASSERT(l>=0)
tpath[l] = 0;
/* ISOLATE FILE NAME FROM PATH */
l = strlen(fpath);
while (fpath[l]!=slash && fpath[l]!=colon && l>=0)
l--;
l++;
ASSERT(l>=0)
/* APPEND FILE NAME */
strcat (tpath, fpath+l);
/* RETURN */
return (tpath);
}