133#include <sys/types.h>
139#include <lal/LALConfig.h>
140#include <lal/LALgetopt.h>
141#include <lal/LALStdio.h>
142#include <lal/LALStdlib.h>
143#include <lal/LALError.h>
144#include <lal/LALDatatypes.h>
145#include <lal/LIGOLwXML.h>
146#include <lal/LIGOLwXMLRead.h>
147#include <lal/LIGOMetadataTables.h>
148#include <lal/LIGOMetadataUtils.h>
153#define CVS_ID_STRING "$Id$"
154#define CVS_REVISION "$Revision$"
155#define CVS_SOURCE "$Source$"
156#define CVS_DATE "$Date$"
157#define PROGRAM_NAME "splitbank"
160"Usage: %s [options] [LIGOLW XML input files]\n\n"\
161" --help display this message\n"\
162" --verbose print progress information\n"\
163" --version print version information\n"\
164" --user-tag STRING set the process_params usertag to STRING\n"\
165" --comment STRING set the process table comment to STRING\n"\
167" --bank-file FILE read template bank parameters from FILE\n"\
168" --number-of-banks N split template bank into N files\n"\
169" --minimal-match M set minimal match of triggered bank to M\n"\
174int main (
int argc,
char *argv[] )
180 CHAR *bankFileName = NULL;
181 INT4 numOutBanks = 0;
195 INT4 numTmpltsWritten = 0;
198 char outBankFileName[FILENAME_MAX];
199 CHAR bankFileNameHead[FILENAME_MAX];
200 CHAR bankFileNameTail[FILENAME_MAX];
231 setvbuf( stdout, NULL, _IONBF, 0 );
238 this_proc_param = procparams =
253 int option_index = 0;
254 size_t LALoptarg_len;
258 long_options, &option_index );
270 if ( long_options[option_index].
flag != 0 )
276 fprintf( stderr,
"error parsing option %s with argument %s\n",
284 bankFileName = (
CHAR *) calloc( LALoptarg_len,
sizeof(
CHAR));
285 memcpy( bankFileName,
LALoptarg, LALoptarg_len );
289 snprintf( procparams->
param,
296 if ( numOutBanks < 0 )
298 fprintf( stderr,
"invalid argument to --%s:\n"
299 "Number of output banks must be greater than zero:"
301 long_options[option_index].
name, numOutBanks );
304 else if ( numOutBanks > 99 )
307 "Warning: generating more than 99 banks is not reccomended!\n" );
315 "--%s", long_options[option_index].
name );
323 fprintf( stderr,
"invalid argument to --%s:\n"
324 "comment must be less than %d characters\n",
354 fprintf( stdout,
"invalid argument to --%s:\n"
355 "minimal match of bank must be > 0: "
366 long_options[option_index].
name );
373 fprintf( stdout,
"Inspiral Template Bank Splitter\n"
374 "Duncan Brown <duncan@gravity.phys.uwm.edu>\n");
385 fprintf( stderr,
"unknown error while parsing options\n" );
393 fprintf( stderr,
"extraneous command line arguments:\n" );
402 if ( ! bankFileName )
404 fprintf( stderr,
"Error: --bank-file must be specified\n" );
410 fprintf( stderr,
"Error: --number-of-banks must be specified\n" );
416 fprintf( stderr,
"Error: --minimal-match must be specified\n" );
432 fprintf( stderr,
"error: unable to read templates from %s\n",
442 if (
vrbflg )
fprintf( stdout,
"read %d templates from %s\n",
447 gpsHyphen = strstr( bankFileName,
"-" );
450 fprintf( stderr,
"Error: could not find first hypen in file name %s\n",
454 gpsHyphen = strstr( gpsHyphen + 1,
"-" );
457 fprintf( stderr,
"Error: could not find second hypen in file name %s\n",
463 memcpy( bankFileNameHead, bankFileName,
464 (
size_t) gpsHyphen - (
size_t) bankFileName < FILENAME_MAX ?
465 (gpsHyphen - bankFileName) *
sizeof(
CHAR) : FILENAME_MAX *
sizeof(
CHAR) );
466 strncpy( bankFileNameTail, gpsHyphen + 1, FILENAME_MAX - 1 );
470 fprintf( stdout,
"head of bank file name is %s\n", bankFileNameHead );
471 fprintf( stdout,
"tail of bank file name is %s\n", bankFileNameTail );
483 numPerFile = floor( (
numTmplts - 0.5 )/ numOutBanks + 1 );
484 thisTmplt = inputBank;
485 if (
vrbflg )
fprintf( stdout,
"writing around %d templates per file\n",
488 for (
i = 0;
i < numOutBanks; ++
i )
491 memset( outBankFileName, 0, FILENAME_MAX *
sizeof(
CHAR) );
492 if(snprintf( outBankFileName, FILENAME_MAX,
"%s_%02d-%s",
493 bankFileNameHead,
i, bankFileNameTail ) >= FILENAME_MAX)
498 fprintf( stdout,
"writing templates to %s... ", outBankFileName );
508 outputBank = thisTmplt;
509 numTmpltsWritten = 0;
513 for (
j = 0;
j < numPerFile - 1 && thisTmplt->
next; ++
j )
515 thisTmplt = thisTmplt->
next;
517 tmpTmplt = thisTmplt->
next;
518 thisTmplt->
next = NULL;
519 thisTmplt = tmpTmplt;
527 tmpTmplt = outputBank;
528 outputBank = outputBank->
next;
534 if (
vrbflg )
fprintf( stdout,
"%d templates\n", numTmpltsWritten );
const LALVCSInfoList lalAppsVCSInfoList
NULL-terminated list of VCS and build information for LALApps and its dependencies
const LALVCSInfo lalAppsVCSIdentInfo
Identable VCS and build information for LALApps.
lal_errhandler_t lal_errhandler
int LAL_ERR_EXIT(LALStatus *stat, const char *func, const char *file, const int line, volatile const char *id)
void LALCheckMemoryLeaks(void)
int LALgetopt_long_only(int argc, char *const *argv, const char *options, const struct LALoption *long_options, int *opt_index)
#define required_argument
int XLALCloseLIGOLwXMLFile(LIGOLwXMLStream *xml)
LIGOLwXMLStream * XLALOpenLIGOLwXMLFile(const char *path)
int XLALWriteLIGOLwXMLProcessTable(LIGOLwXMLStream *, const ProcessTable *)
int XLALWriteLIGOLwXMLProcessParamsTable(LIGOLwXMLStream *, const ProcessParamsTable *)
int XLALWriteLIGOLwXMLSnglInspiralTable(LIGOLwXMLStream *xml, const SnglInspiralTable *sngl_inspiral)
SnglInspiralTable * XLALSnglInspiralTableFromLIGOLw(const char *fileName)
LIGOTimeGPS * XLALGPSTimeNow(LIGOTimeGPS *gpstime)
#define XLAL_INIT_DECL(var,...)
int XLALOutputVCSInfo(FILE *fp, const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
CHAR comment[LIGOMETA_COMMENT_MAX]
char name[LIGOMETA_SOURCE_MAX]
int main(int argc, char *argv[])
int vrbflg
defined in lal/lib/std/LALError.c
const char *const vcsDate
const char *const vcsStatus
CHAR type[LIGOMETA_TYPE_MAX]
CHAR param[LIGOMETA_PARAM_MAX]
CHAR value[LIGOMETA_VALUE_MAX]
struct tagProcessParamsTable * next
CHAR program[LIGOMETA_PROGRAM_MAX]
struct tagSnglInspiralTable * next