/* Prints in "stdout" a list of candidate pairings with their curvature chains. */ /* Last edited on 2015-01-20 16:55:59 by stolfilocal */ #include #include #include #include #include #include #include TYPE Options = struct ??? { char *input; /* Input candidate file name. */ char *chainDir; /* Directory where chains reside. */ char *chainPrefix; /* Invariant chain file name prefix. */ unsigned band; /* Nominal band width (lambda) for file names. */ bool_t pairing; /* TRUE to print the pairing. */ unsigned maxCands; /* MAX num candidates to print. */ } ???; int main(int argc, char **argv ) { { /* with */ ??? o = pz_get_options(int argc, char **argv); /* do */ fprintf(stderr, "pz_print_cands %s\n", o.input ); if (( o.maxCands > 0 )){ { /* with */ ??? candData = pz_candidate_read(open_read(o.input & ".can", TRUE)); ??? cand = candData.c^; ??? chainUsed = pz_candidate_chains_used(cand)^; chAllData = pz_symbol_chain_read_all( o.chainPrefix, o.band, ".cvc"; sel := chainUsed, header_only := FALSE ); /* do */ PrintCandidates(chAllData.chData^, cand, o.band, o.maxCands);; };; }; }; } /* 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); if (( argparser_keyword_present(pp, "-chainDir") )){ o.chainDir = argparser_get_next(pp) }else{ o.chainDir = "."; }; argparser_get_keyword(pp, "-chainPrefix"); o.chainPrefix = argparser_get_next(pp); argparser_get_keyword(pp, "-band"); o.band = argparser_get_next_int(pp); o.pairing = argparser_keyword_present(pp, "-pairing"); if (( argparser_keyword_present(pp, "-maxCands") )){ o.maxCands = argparser_get_next_int(pp, 1) }else{ o.maxCands = 1000; }; argparser_finish(pp); EXCEPT | ParseParams.Error ==> fprintf(stderr, "Usage: pz_print_cands \\\n"); fprintf(stderr, " -input NAME \\\n"); fprintf(stderr, " [ -chainDir DIR ] -chainPrefix NAME \\\n"); fprintf(stderr, " -band NUMBER \\\n"); fprintf(stderr, " [ -pairing ] \\\n"); fprintf(stderr, " [ -maxCands NUMBER ]\n"); Process.Exit(1);; };; }; return o } /* GetOptions */ void PrintCandidates ( ARRAY *OF pz_symbol_chain_read_data ch, pz_candidate.List *cand, unsigned band, unsigned maxCands ) { { /* with */ ??? nCands = (cand.ne); /* do */ fprintf(stdout, "===== band == %s =====\n", Fmt.Int(band) ); for (i = 0; i <= min(nCands, maxCands)-1 ; i++){ { /* with */ ??? c = cand[i]; /* do */ fprintf(stdout, "cand[%s]\n", Fmt.Int(i) ); PrintCandidate(stdout, c, ch[c.seg[0].cvx].c, ch[c.seg[1].cvx].c); for (i = 1; i <= 80 ; i++){ Wr.PutChar(stdout, '-') ;}; fprintf(stdout, "\n");; }; ; }; }; } /* PrintCandidates */ void PrintCandidate( FILE *wr, pz_candidate_t *cand, REF *pz_symbol_chain_t ch0, REF *pz_symbol_chain_t ch1, bool_t pairing /* (:= TRUE) */ ) void PrintHalf( [0..1] j, pz_segment_t s, REF *pz_symbol_chain_t ch ) { fprintf(wr, " "); fprintf(wr, "seg [%s]: ", Fmt.Int(j) ); pz_segment_print(wr, s); if (( ch != NULL )){ affirm(s.tot == (ch^.ne) ); fprintf(wr, " == "); pz_symbol_chain_print_segment(wr, ch^, s); }; fprintf(wr, "\n"); } /* PrintHalf */ { fprintf(wr, "chains == ("); fprintf(wr, Fmt.Int(cand.seg[0].cvx) & "," & Fmt.Int(cand.seg[1].cvx)); fprintf(wr, ") "); fprintf(wr,"mismatch == " & FLR(cand.mismatch, 6, 2)); fprintf(wr, " "); fprintf(wr,"length == " & FLR(cand.length, 9, 4)); fprintf(wr, " "); fprintf(wr, "matchedLength == %s\n", FLR(cand.matchedLength, 9, 4) ); PrintHalf(0, cand.seg[0], ch0); PrintHalf(1, cand.seg[1], ch1); if (( pairing ) ANDAND ( cand.pm != NULL )){ pz_match_write_packed(wr, cand.pm^); fprintf(wr, "\n");; }; for (i = 1; i <= 80 ; i++){ Wr.PutChar(wr, '-') ;}; fprintf(wr, "\n"); } /* PrintCandidate */ char *FLR( double x, unsigned w, unsigned p ) { return Fmt.Pad(Fmt.LongReal(x, Fmt.Style.Fix, prec = p), w) } /* FLR */ { /* 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. */