forked from markjessell/functionNoddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatchNod.c
218 lines (186 loc) · 5.06 KB
/
batchNod.c
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
#include "noddy.h"
#if (XVTWS == XOLWS) || (XVTWS == MTFWS)
#include <sys/time.h>
#define TIMER(X) X
#else
#define TIMER(X)
#endif
#define DEBUG(X)
#define EXIT_ERROR_VALUE 1
#define EXIT_SUCESS_VALUE 0
/* Functions in this File */
#if XVT_CC_PROTO
extern int Load_status(char *);
#else
extern int Load_status();
#endif
int batchNoddy ();
void initVariables ();
void processCommandLine ();
void displayUsage ();
void timeStart ();
void timeEnd ();
double timeElapsed ();
/* Functions external to this File */
/* Global Variables */
#ifdef FCN_NODDY_ONLY
int batchExecution = TRUE;
#else
int batchExecution = FALSE;
#endif
WINDOW_INFO batchWindowInfo;
/* Variables reintroduced from Sequential Noddy */
#if (XVTWS == XOLWS) || (XVTWS == MTFWS)
static struct timeval timeVal0;
static struct timeval timeVal1;
#endif
/*
======================================================================
FUNCTION batchNoddy
DESCRIPTION Run Noddy as a batch process
INPUT
OUTPUT
RETURNED
======================================================================
*/
int batchNoddy (argc, argv)
int argc;
char **argv;
{
static char *defaultOutputFile = "untitled";
char *historyFile = NULL;
char *outputFile = NULL;
char *blockFile = NULL;
char operationName[100];
OPERATIONS operation;
TIMER(double time;)
TIMER(timeStart ();)
batchExecution = TRUE;
fprintf (stdout,"\n************************************************************");
fprintf (stdout,"\n*** - Noddy - ***");
fprintf (stdout,"\n*** Batch Execution ***");
fprintf (stdout,"\n*** (c) 1994 Monash University ***");
fprintf (stdout,"\n");
if (!checkLicence())
return (0);
/* Initialise some variables we will use */
operation = ANOMALIES;
strcpy (operationName,"Anomalies");
outputFile = defaultOutputFile;
initVariables ();
/* Find out what calculation to perform */
processCommandLine (argv, argc, &historyFile, &outputFile, &blockFile,
operationName, &operation);
if (!blockFile)
blockFile = outputFile;
if (!historyFile)
{
displayUsage (argv[0]);
exit (EXIT_ERROR_VALUE);
}
fprintf (stdout,"\nOutput File is : %s (extensions may be appended)",outputFile);
fprintf (stdout,"\nOperation is : Calculating a %s\n",operationName);
fflush(stdout);
if (!Load_status(historyFile))
{
fprintf(stderr,"\nERROR: cannot read History File.\n");
exit (EXIT_ERROR_VALUE);
}
if (!performBatchOperations (outputFile, blockFile, operation))
exit (EXIT_ERROR_VALUE);
DEBUG(printf ("\n*************** END \n");)
TIMER(timeEnd ();)
TIMER(time = timeElapsed ();)
TIMER(fprintf(stdout,"\nProcessing took %.1lf sec.",time);)
fprintf(stdout,"\n");
exit (EXIT_SUCESS_VALUE);
}
/*
======================================================================
FUNCTION initVariables
DESCRIPTION
initialise all the variables used in the sequential version of
noddy
INPUT
OUTPUT
RETURNED
======================================================================
*/
void initVariables ()
{
memset(&batchWindowInfo, 0, sizeof(WINDOW_INFO));
}
/*
======================================================================
FUNCTION timeStart
DESCRIPTION
start timeer
INPUT
OUTPUT
======================================================================
*/
void timeStart ()
{
#if (XVTWS == XOLWS) || (XVTWS == MTFWS)
struct timezone timeZone;
gettimeofday(&timeVal0, &timeZone);
#endif
}
/*
======================================================================
FUNCTION timeEnd
DESCRIPTION
start timeer
INPUT
OUTPUT
======================================================================
*/
void timeEnd ()
{
#if (XVTWS == XOLWS) || (XVTWS == MTFWS)
struct timezone timeZone;
gettimeofday(&timeVal1, &timeZone);
#endif
}
/*
======================================================================
FUNCTION timeElapsed
DESCRIPTION
start timeer
INPUT
OUTPUT
======================================================================
*/
double timeElapsed ()
{
double time = 0.0;
#if (XVTWS == XOLWS) || (XVTWS == MTFWS)
time = timeVal1.tv_sec - timeVal0.tv_sec;
time += (timeVal1.tv_usec - timeVal0.tv_usec)/1000000;
#endif
return (time);
}
/*
======================================================================
FUNCTION updateBatchStatus
DESCRIPTION
write out a status message for batch progress
INPUT
OUTPUT
======================================================================
*/
int
#if XVT_CC_PROTO
updateBatchStatus (char *message)
#else
updateBatchStatus (message)
char *message;
#endif
{
FILE *batchProgressFile;
if (!(batchProgressFile = fopen ("noddyBatchProgress.txt", "w")))
return (FALSE);
fprintf(batchProgressFile, message);
fclose(batchProgressFile);
return (TRUE);
}