forked from billkarsh/Alignment_Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathptestx.cpp
317 lines (240 loc) · 7.78 KB
/
ptestx.cpp
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
//
// ptestx is a wrapper function for ptest that first creates a disk
// folder/file structure that ptest expects, and then calls ptest.
//
// E.g.
// > ptestx za.ia^zb.ib -d=temp -prm=matchparams.txt
// [-idb=xxx]
// [-ima=xxx -imb=xxx]
// [-fma=xxx -fmb=xxx]
//
// Required params:
// za.ia^zb.ib: z/tileid numerical labels (A onto B)
// d: output directory to create
// prm: path to parameter file
//
// Options:
// idb: path to IDB
// ima, imb: paths to the images
// fma, fmb: paths to foldmasks
//
// Image specs:
// If any of {ima, imb, fma, fmb} are specified, they override
// any idb-derived specs. However, idb is required if any image
// is to be fetched from a given IDB.
//
// Other ptest options:
// Any params not eaten by ptestx are passed on to ptest.
//
#include "Cmdline.h"
#include "Disk.h"
#include "File.h"
#include "PipeFiles.h"
#include <string.h>
#include <unistd.h>
/* --------------------------------------------------------------- */
/* Macros -------------------------------------------------------- */
/* --------------------------------------------------------------- */
/* --------------------------------------------------------------- */
/* Types --------------------------------------------------------- */
/* --------------------------------------------------------------- */
/* --------------------------------------------------------------- */
/* CArgs_ptx ----------------------------------------------------- */
/* --------------------------------------------------------------- */
class CArgs_ptx {
public:
vector<char*> passon;
char im[2][2048],
fm[2][2048],
tmp[2048],
idb[2048],
prm[2048];
int z[2], tile[2],
clrtmp;
public:
CArgs_ptx()
{
im[0][0] = 0;
im[1][0] = 0;
fm[0][0] = 0;
fm[1][0] = 0;
tmp[0] = 0;
idb[0] = 0;
prm[0] = 0;
clrtmp = false;
};
void SetCmdLine( int argc, char* argv[] );
void TopLevel();
void ALayer();
void Call_ptest();
};
/* --------------------------------------------------------------- */
/* Statics ------------------------------------------------------- */
/* --------------------------------------------------------------- */
static CArgs_ptx gArgs;
static FILE* flog = NULL;
/* --------------------------------------------------------------- */
/* SetCmdLine ---------------------------------------------------- */
/* --------------------------------------------------------------- */
void CArgs_ptx::SetCmdLine( int argc, char* argv[] )
{
// start log
flog = FileOpenOrDie( "ptestx.log", "w" );
// log start time
time_t t0 = time( NULL );
char atime[32];
strcpy( atime, ctime( &t0 ) );
atime[24] = '\0'; // remove the newline
fprintf( flog, "Start: %s ", atime );
// parse command line args
if( argc < 5 ) {
usage:
printf( "Usage: ptestx <za.ia^zb.ib> -d=temp"
" -prm=matchparams.txt [-idb=xxx]"
" [-ima=xxx -imb=xxx -fma=zzz -fmb=xxx]"
" [options].\n" );
exit( 42 );
}
const char *key, *_arg;
int ok = true;
passon.push_back( argv[1] ); // key
for( int i = 1; i < argc; ++i ) {
// echo to log
fprintf( flog, "%s ", argv[i] );
if( argv[i][0] != '-' )
key = argv[i];
else if( GetArgStr( _arg, "-d=", argv[i] ) )
ok = DskAbsPath( tmp, sizeof(tmp), _arg, flog );
else if( GetArgStr( _arg, "-idb=", argv[i] ) )
ok = DskAbsPath( idb, sizeof(idb), _arg, flog );
else if( GetArgStr( _arg, "-prm=", argv[i] ) )
ok = DskAbsPath( prm, sizeof(prm), _arg, flog );
else if( GetArgStr( _arg, "-ima=", argv[i] ) )
ok = DskAbsPath( im[0], sizeof(im[0]), _arg, flog );
else if( GetArgStr( _arg, "-imb=", argv[i] ) )
ok = DskAbsPath( im[1], sizeof(im[1]), _arg, flog );
else if( GetArgStr( _arg, "-fma=", argv[i] ) )
ok = DskAbsPath( fm[0], sizeof(fm[0]), _arg, flog );
else if( GetArgStr( _arg, "-fmb=", argv[i] ) )
ok = DskAbsPath( fm[1], sizeof(fm[1]), _arg, flog );
else if( IsArg( "-clr", argv[i] ) )
clrtmp = true;
else
passon.push_back( argv[i] );
if( !ok ) {
fprintf( flog, "\nBad arg path '%s'.\n", argv[i] );
exit( 42 );
}
}
fprintf( flog, "\n\n" );
if( !key || !tmp[0] || !prm[0] )
goto usage;
// Decode labels in key
if( 4 != sscanf( key, "%d.%d^%d.%d",
&z[0], &tile[0], &z[1], &tile[1] ) ) {
fprintf( flog, "Bad label string '%s'.\n", key );
exit( 42 );
}
fflush( flog );
}
/* --------------------------------------------------------------- */
/* TopLevel ------------------------------------------------------ */
/* --------------------------------------------------------------- */
void CArgs_ptx::TopLevel()
{
char buf[2048];
// preclear
if( clrtmp ) {
sprintf( buf, "rm -rf %s", tmp );
system( buf );
}
// create top directory
DskCreateDir( tmp, flog );
// copy param files
if( idb[0] ) {
sprintf( buf, "cp %s/imageparams.txt %s", idb, tmp );
system( buf );
}
sprintf( buf, "cp %s %s/matchparams.txt", prm, tmp );
system( buf );
}
/* --------------------------------------------------------------- */
/* ALayer -------------------------------------------------------- */
/* --------------------------------------------------------------- */
void CArgs_ptx::ALayer()
{
char buf[2048];
int len;
/* ---------------------------- */
/* Create A layer and jobs dirs */
/* ---------------------------- */
len = sprintf( buf, "%s/%d", tmp, z[0] );
DskCreateDir( buf, flog );
CreateJobsDir( buf, 0, 0, z[0], z[1], flog );
/* --------------- */
/* Create tile dir */
/* --------------- */
sprintf( buf + len, "/%d", tile[0] );
DskCreateDir( buf, flog );
}
/* --------------------------------------------------------------- */
/* Call_ptest ---------------------------------------------------- */
/* --------------------------------------------------------------- */
void CArgs_ptx::Call_ptest()
{
char buf[2048],
ptsbuf[32],
logbuf[32];
int len, narg;
// set jobs dir
sprintf( buf, "%s/%d/%c0_0", tmp, z[0],
(z[1] == z[0] ? 'S' : 'D') );
chdir( buf );
// build command line with any passon args
len = sprintf( buf, "ptest >>%s 2>%s",
NamePtsFile( ptsbuf, z[0], z[1] ),
NameLogFile( logbuf, z[0], tile[0], z[1], tile[1] ) );
narg = passon.size();
for( int i = 0; i < narg; ++i )
len += sprintf( buf + len, " %s", passon[i] );
// add optional image args
if( im[0][0] )
len += sprintf( buf + len, " -ima=%s", im[0] );
if( im[1][0] )
len += sprintf( buf + len, " -imb=%s", im[1] );
if( fm[0][0] )
len += sprintf( buf + len, " -fma=%s", fm[0] );
if( fm[1][0] )
len += sprintf( buf + len, " -fmb=%s", fm[1] );
// call ptest
fprintf( flog, "%s\n.", buf );
system( buf );
}
/* --------------------------------------------------------------- */
/* main ---------------------------------------------------------- */
/* --------------------------------------------------------------- */
int main( int argc, char* argv[] )
{
/* ------------------ */
/* Parse command line */
/* ------------------ */
gArgs.SetCmdLine( argc, argv );
/* --------- */
/* Top level */
/* --------- */
gArgs.TopLevel();
/* ------- */
/* A layer */
/* ------- */
gArgs.ALayer();
/* --------------------- */
/* Call through to ptest */
/* --------------------- */
gArgs.Call_ptest();
/* ---- */
/* Done */
/* ---- */
fprintf( flog, "\n" );
fclose( flog );
return 0;
}