From 529ce3118a00af873c846e98f43d95f1eed7ceb6 Mon Sep 17 00:00:00 2001 From: anastas Date: Tue, 6 Feb 2007 16:59:40 +0000 Subject: [PATCH] added method in fsm to generate an svg description of the fsm (by Tim Meehan) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4395 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-trellis/src/lib/fsm.cc | 66 ++++++++++++++++++++++++++++++++++++--- gr-trellis/src/lib/fsm.h | 1 + gr-trellis/src/lib/fsm.i | 1 + 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/gr-trellis/src/lib/fsm.cc b/gr-trellis/src/lib/fsm.cc index 6e393389..10ad553c 100644 --- a/gr-trellis/src/lib/fsm.cc +++ b/gr-trellis/src/lib/fsm.cc @@ -21,6 +21,9 @@ */ #include +#include +#include +#include #include #include #include "base.h" @@ -320,10 +323,63 @@ bool fsm::find_es(int es) +//###################################################################### +//# generate trellis representation of FSM as an SVG file +//###################################################################### +void fsm::write_trellis_svg( std::string filename ,int number_stages) +{ + std::ofstream trellis_fname (filename.c_str()); + if (!trellis_fname) {std::cout << "file not found " << std::endl ; exit(-1);} + const int TRELLIS_Y_OFFSET = 30; + const int TRELLIS_X_OFFSET = 20; + const int STAGE_LABEL_Y_OFFSET = 25; + const int STAGE_LABEL_X_OFFSET = 20; + const int STATE_LABEL_Y_OFFSET = 30; + const int STATE_LABEL_X_OFFSET = 5; + const int STAGE_STATE_OFFSETS = 10; +// std::cout << "################## BEGIN SVG TRELLIS PIC #####################" << std::endl; + trellis_fname << "" << std::endl; + + for(unsigned int stage_num = 0;stage_num < number_stages;stage_num ++){ + // draw states + for (unsigned int state_num = 0;state_num < d_S ; state_num ++ ) { + trellis_fname << "" << std::endl; + //draw branches + if(stage_num != number_stages-1){ + for(unsigned int branch_num = 0;branch_num < d_I; branch_num++){ + trellis_fname << "" << std::endl; + } + } + } + } + // label the stages + trellis_fname << "" << std::endl; + for(unsigned int stage_num = 0;stage_num < number_stages ;stage_num ++){ + trellis_fname << "" << std::endl; + trellis_fname << stage_num << std::endl; + trellis_fname << "" << std::endl; + } + trellis_fname << "" << std::endl; + + // label the states + trellis_fname << "" << std::endl; + for(unsigned int state_num = 0;state_num < d_S ; state_num ++){ + trellis_fname << "" << std::endl; + trellis_fname << state_num << std::endl; + trellis_fname << "" << std::endl; + } + trellis_fname << "" << std::endl; - - - - - + trellis_fname << "" << std::endl; +// std::cout << "################## END SVG TRELLIS PIC ##################### " << std::endl; + trellis_fname.close(); +} diff --git a/gr-trellis/src/lib/fsm.h b/gr-trellis/src/lib/fsm.h index 66b1f1cc..75255874 100644 --- a/gr-trellis/src/lib/fsm.h +++ b/gr-trellis/src/lib/fsm.h @@ -58,6 +58,7 @@ public: const std::vector< std::vector > & PI () const { return d_PI; } const std::vector & TMi () const { return d_TMi; } const std::vector & TMl () const { return d_TMl; } + void write_trellis_svg( std::string filename ,int number_stages); }; #endif diff --git a/gr-trellis/src/lib/fsm.i b/gr-trellis/src/lib/fsm.i index cec45fce..e4c9e51a 100644 --- a/gr-trellis/src/lib/fsm.i +++ b/gr-trellis/src/lib/fsm.i @@ -49,5 +49,6 @@ public: const std::vector< std::vector > & PI () const { return d_PI; } const std::vector & TMi () const { return d_TMi; } const std::vector & TMl () const { return d_TMl; } + void fsm::write_trellis_svg( std::string filename ,int number_stages); }; -- 2.30.2