From c9717248b32083565bdbdd8cbacde1dac92daf31 Mon Sep 17 00:00:00 2001 From: anastas Date: Tue, 13 Feb 2007 04:50:17 +0000 Subject: [PATCH] added methods to fsm class for writting to text file git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@4461 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-trellis/src/lib/fsm.cc | 40 +++++++++++++++++++++++++++++++++------ gr-trellis/src/lib/fsm.h | 3 ++- gr-trellis/src/lib/fsm.i | 8 +++++--- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/gr-trellis/src/lib/fsm.cc b/gr-trellis/src/lib/fsm.cc index 10ad553c..a27bc87d 100644 --- a/gr-trellis/src/lib/fsm.cc +++ b/gr-trellis/src/lib/fsm.cc @@ -103,7 +103,6 @@ fsm::fsm(const char *name) - //###################################################################### //# Automatically generate the FSM from the generator matrix //# of a (n,k) binary convolutional code @@ -340,14 +339,14 @@ void fsm::write_trellis_svg( std::string filename ,int number_stages) // std::cout << "################## BEGIN SVG TRELLIS PIC #####################" << std::endl; trellis_fname << "" << std::endl; - for(unsigned int stage_num = 0;stage_num < number_stages;stage_num ++){ + for( int stage_num = 0;stage_num < number_stages;stage_num ++){ // draw states - for (unsigned int state_num = 0;state_num < d_S ; state_num ++ ) { + for ( 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++){ + for( int branch_num = 0;branch_num < d_I; branch_num++){ trellis_fname << "" << std::endl; - for(unsigned int stage_num = 0;stage_num < number_stages ;stage_num ++){ + for( int stage_num = 0;stage_num < number_stages ;stage_num ++){ trellis_fname << "" << std::endl; trellis_fname << stage_num << std::endl; @@ -370,7 +369,7 @@ void fsm::write_trellis_svg( std::string filename ,int number_stages) // label the states trellis_fname << "" << std::endl; - for(unsigned int state_num = 0;state_num < d_S ; state_num ++){ + for( int state_num = 0;state_num < d_S ; state_num ++){ trellis_fname << "" << std::endl; trellis_fname << state_num << std::endl; @@ -383,3 +382,32 @@ void fsm::write_trellis_svg( std::string filename ,int number_stages) // std::cout << "################## END SVG TRELLIS PIC ##################### " << std::endl; trellis_fname.close(); } + + + + + + +//###################################################################### +//# Write trellis specification to a text files, +//# in the same format used when reading FSM files +//###################################################################### +void fsm::write_fsm_txt(std::string filename) +{ + std::ofstream trellis_fname (filename.c_str()); + if (!trellis_fname) {std::cout << "file not found " << std::endl ; exit(-1);} + trellis_fname << d_I << ' ' << d_S << ' ' << d_O << std::endl; + trellis_fname << std::endl; + for(int i=0;i > & 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); + void write_trellis_svg(std::string filename ,int number_stages); + void write_fsm_txt(std::string filename); }; #endif diff --git a/gr-trellis/src/lib/fsm.i b/gr-trellis/src/lib/fsm.i index e4c9e51a..6cfc2968 100644 --- a/gr-trellis/src/lib/fsm.i +++ b/gr-trellis/src/lib/fsm.i @@ -45,10 +45,12 @@ public: int O () const { return d_O; } const std::vector & NS () const { return d_NS; } const std::vector & OS () const { return d_OS; } - const std::vector< std::vector > & PS () const { return d_PS; } - const std::vector< std::vector > & PI () const { return d_PI; } + // disable these accessors until we find out how to swig them + //const std::vector< std::vector > & PS () const { return d_PS; } + //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); + void fsm::write_trellis_svg(std::string filename ,int number_stages); + void fsm::write_fsm_txt(std::string filename); }; -- 2.30.2