[go: up one dir, main page]

Menu

[r6]: / trunk / src / cdrepeat.c  Maximize  Restore  History

Download this file

262 lines (207 with data), 5.4 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
/*
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.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "cdhouse.h"
#include "rcvio.h"
#include "cdcor.h"
#include "iomngr.h"
#include "parse.h"
#include "strsub.h"
#include "cdsubs.h"
#define REPEATCOR
/************************/
/** GLOBAL VARIABLES **/
/************************/
extern Particle_t *a,*b;
extern Simulation_t *s;
extern FILE *out;
extern LIST *inlist;
extern int isig; /* SIGNAL SET BY kill OR Cntl-C */
/* READ REPEAT BLOCK */
void read_repeat (char *instr)
{
int n;
int qflag = 0, nread, nest;
char origstr[256];
char copystr[256], *tailstr, *cmdstr;
BUFF *b;
BOOLEAN CorFileFlag;
BOOLEAN RcvFileFlag;
BOOLEAN UseStep;
BOOLEAN UseSkip;
BOOLEAN ReadToEnd;
FILE *InputFile;
char *InputFileName;
int Step1;
int Step2;
int SkipInterval;
/* Parse command options */
cmdstr = strhed (&instr);
CorFileFlag = FALSE;
RcvFileFlag = FALSE;
UseStep = FALSE;
UseSkip = FALSE;
/* Read from COR or RCV file */
CorFileFlag = (strcmpi(cmdstr,"COR")==0);
RcvFileFlag = (strcmpi(cmdstr,"RCV")==0);
ReadToEnd = FALSE;
if (CorFileFlag || RcvFileFlag)
{
/* Get input file name */
InputFileName = strhed (&instr);
/* Test for reading from specpfied steps */
UseStep = !IsBlank(instr);
/* Get step numbers */
if (UseStep)
{
/* Get starting step */
Step1 = intstrf(&instr);
/* Read to end of file */
if (IsBlank(instr) || instr[0]=='*')
{
ReadToEnd = TRUE;
/* Remove token if '*' */
if (instr[0]=='*')
strhed (&instr);
}
/* Read to specified step */
else
{
Step2 = intstrf(&instr);
}
/* Test for skip interval */
UseSkip = !IsBlank(instr);
if (UseSkip)
SkipInterval = intstrf(&instr);
}
}
/* Repeat N times */
else
{
n = intstrf (&cmdstr);
}
/* INTIALIZE BUFFER */
b = m_ini_buff();
/* READ INPUT LINES UNTIL "END" */
nread = 0;
nest = 1;
while (nest && m_gets_list_f(origstr,256,inlist)!=NULL)
{
/* COPY STRING */
strcpy (copystr, origstr);
tailstr = copystr;
/* ECHO STRING IF NOT FROM BUFFER */
if (!inlist->IsBuffer && s->echo)
printf ("%s\n", origstr);
/* PARSE COMMAND */
cmdstr = strhed (&tailstr);
/* IF END REDUCE NEST COUNT */
if (!strcmpi(cmdstr, "END"))
nest--;
/* IF REPEAT INCREASE NEST COUNT */
else if (!strcmpi(cmdstr, "REPEAT"))
nest++;
/* ADD COMMAND TO BUFFER */
if (nest)
m_add_buff (b, origstr);
nread++;
}
/* CHECK FOR PROPER NESTING */
if (nest)
{
printf ("ERROR (read_repeat): Improper nesting of REPEAT and END.\n");
CleanAfterError();
}
/* ADD BUFFER TO INPUT LIST */
m_add_list (&inlist, b, "b");
/* PROCESS COMMANDS n TIMES */
/* (break if signal set, i.e. isig==1) */
/* Repeat for each step in COR file */
if (CorFileFlag || RcvFileFlag)
{
/* Open binary Cor file */
if (CorFileFlag)
InputFile = fopen (InputFileName, "rb");
/* Open text Rcv file */
else
InputFile = fopen (InputFileName, "rt");
/* Test for input file present */
if (InputFile==NULL)
{
printf ("ERROR: Cannot open file %s\n", InputFileName);
}
/* Process commands for each COR or RCV step */
do
{
/* Read step */
if (CorFileFlag)
ReadCorFile (InputFile, a);
else
readrcv (InputFile, a);
/* Stop input if end of file */
if (feof(InputFile))
break;
/* Stop if above range */
if (UseStep && !ReadToEnd && a->step>Step2)
break;
/* Skip if below range */
if (UseStep && a->step<Step1)
continue;
/* Skip if not on skip interval */
if (UseSkip && ((a->step - Step1) % SkipInterval != 0))
continue;
/* Process command list */
qflag = 0;
while (!qflag && m_gets_list(origstr,256,inlist)!=NULL && !qflag)
{
read_command (origstr, &qflag);
}
if (qflag) {
CleanBeforeEnd();
exit(0);
}
/* "REWIND" BUFFER */
m_rew_list (inlist);
}
while (!feof(InputFile) && isig!=1);
/* Close COR or RCV File */
fclose (InputFile);
}
else
{
while (n-- && isig!=1 && !qflag)
{
qflag = 0;
while (!qflag && m_gets_list(origstr,256,inlist)!=NULL)
{
read_command (origstr, &qflag);
}
/* "REWIND" BUFFER */
m_rew_list (inlist);
}
/* Quit program */
if (qflag) {
CleanBeforeEnd();
exit(0);
}
}
/* CLOSE CURRENT INPUT (AUTOMATICALLY REMOVES BUFFER STORAGE */
m_del_list (&inlist);
}