/* Last edited on 2015-01-20 16:56:10 by stolfilocal */ /* Converts candidate files from old to new format. */ #include #include #include #include #include #include TYPE Options = struct ??? { char *input; /* Input candidate file name. */ char *chainDir; /* Directory where to find chains. */ char *chainPrefix; /* Chain file name prefix. */ unsigned band; /* Input nominal filtering bandwidth. */ unsigned nChains; /* Total num of chains. */ ARRAY [0..1] OF bool_t rev; /* Segment reversal flags. */ char *output; /* Output candidate file name. */ } ???; int main(int argc, char **argv ) { { /* with */ ??? o = pz_get_options(int argc, char **argv); ??? chains = GetAllChains(o.nChains)^; chAllData = pz_symbol_chain_read_all( o.chainPrefix, o.band, ".cvc"; sel := chains, header_only := TRUE; dir := o.chainDir ); ??? m = GetSampleNumbers(chAllData.chData^)^; ??? candData = pz_candidate_read_old(open_read(o.input & ".can", TRUE), m, o.rev); ??? cand = candData.c^; ??? band = FLOAT(o.band,double); ??? wr = open_write(o.output & ".can", TRUE); /* do */ pz_candidate_write(wr, candData.cmt & UpdateComments(o), cand, band);; }; } /* Main */ Options pz_get_options(int argc, char **argv ) VAR o: Options; { argparser_t *pp = argparser_new(stderr, argc, argv); argparser_set_help(pp, PROG_NAME " version " PROG_VERS ", usage:\n" PROG_HELP); argparser_set_info(pp, PROG_INFO); argparser_process_help_info_options(pp); { /* with */ /* do */ TRY argparser_get_keyword(pp, "-input"); o.input = argparser_get_next(pp); argparser_get_keyword(pp, "-chainPrefix"); o.chainPrefix = argparser_get_next(pp); if (( argparser_keyword_present(pp, "-chainDir") )){ o.chainDir = argparser_get_next(pp) }else{ o.chainDir = "."; }; argparser_get_keyword(pp, "-band"); o.band = argparser_get_next_int(pp); argparser_get_keyword(pp, "-nChains"); o.nChains = argparser_get_next_int(pp); if (( argparser_keyword_present(pp, "-directions") )){ for (j = 0; j <= 1 ; j++){ { /* with */ ??? d = argparser_get_next(pp); /* do */ if (( Text.Equal(d, "+") )){ o.rev[j] = FALSE }else if (( Text.Equal(d, "-") )){ o.rev[j] = TRUE }else{ argparser_error(pp, "bad segment direction"); }; }; } }else{ o.rev[0] = FALSE; o.rev[1] = TRUE; }; argparser_get_keyword(pp, "-output"); o.output = argparser_get_next(pp); argparser_finish(pp); EXCEPT | ParseParams.Error ==> fprintf(stderr, "Usage: pz_update_cands \\\n"); fprintf(stderr, " -input NAME \\\n"); fprintf(stderr, " [ -chainDir DIR ] -chainPrefix NAME \\\n"); fprintf(stderr, " [ -directions {+|-} {+|-} ] \\\n"); fprintf(stderr, " -band NUMBER \\\n"); fprintf(stderr, " -nChains NUMBER \\\n"); fprintf(stderr, " -output NAME\n"); Process.Exit(1);; };; }; return o } /* GetOptions */ bool_vec_t *GetAllChains( unsigned n ) { { /* with */ ??? rseen = bool_vec_new(n); ??? seen = rseen^; /* do */ for (k = 0; k < (seen.ne ) ; k++){ seen[k] = TRUE ;}; return rseen; } } /* GetAllChains */ PROCEDURE GetSampleNumbers( ARRAY *OF pz_symbol_chain_read_data ch ): REF int_vec_t = { { /* with */ ??? n = (ch.ne); ??? rm = int_vec_new(n); ??? m = rm^; /* do */ for (k = 0; k <= n-1 ; k++){ m[k] = ch[k].samples; }; return rm; } } /* GetSampleNumbers */ char *UpdateComments( Options *o ) { { /* with */ ??? wr = NEW(TextFILE *).init(); /* do */ fprintf( wr, "pz_update_cands:\n"); fprintf(wr, " input == %s\n", o.input ); fprintf(wr, " chainDir == %s\n", o.chainDir ); fprintf(wr, " chainPrefix == %s\n", o.chainPrefix ); fprintf(wr, " band == %s\n", Fmt.Int(o.band) ); fprintf(wr, " output == %s\n", o.output ); return(TextFILE *oText(wr)); } /* ){ */; } /* UpdateComments */ { /* Copyright © 2001 Universidade Estadual de Campinas (UNICAMP). Authors: Helena C. G. Leitão and Jorge Stolfi. This file can be freely distributed, used, and modified, provided that this copyright and authorship notice is preserved, and that any modified versions are clearly marked as such. This software has NO WARRANTY of correctness or applicability for any purpose. Neither the authors nor their employers chall be held responsible for any losses or damages that may result from its use. */