commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4461 - gnuradio/trunk/gr-trellis/src/lib


From: anastas
Subject: [Commit-gnuradio] r4461 - gnuradio/trunk/gr-trellis/src/lib
Date: Mon, 12 Feb 2007 21:50:17 -0700 (MST)

Author: anastas
Date: 2007-02-12 21:50:17 -0700 (Mon, 12 Feb 2007)
New Revision: 4461

Modified:
   gnuradio/trunk/gr-trellis/src/lib/fsm.cc
   gnuradio/trunk/gr-trellis/src/lib/fsm.h
   gnuradio/trunk/gr-trellis/src/lib/fsm.i
Log:
added methods to fsm class for writting to text file

Modified: gnuradio/trunk/gr-trellis/src/lib/fsm.cc
===================================================================
--- gnuradio/trunk/gr-trellis/src/lib/fsm.cc    2007-02-12 23:04:42 UTC (rev 
4460)
+++ gnuradio/trunk/gr-trellis/src/lib/fsm.cc    2007-02-13 04:50:17 UTC (rev 
4461)
@@ -103,7 +103,6 @@
 
 
 
-
 //######################################################################
 //# Automatically generate the FSM from the generator matrix
 //# of a (n,k) binary convolutional code
@@ -340,14 +339,14 @@
 //   std::cout << "################## BEGIN SVG TRELLIS PIC 
#####################" << std::endl;
    trellis_fname << "<svg viewBox = \"0 0 200 200\" version = \"1.1\">" << 
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 << "<circle cx = \"" << stage_num * STAGE_STATE_OFFSETS 
+ TRELLIS_X_OFFSET << 
         "\" cy = \"" << state_num * STAGE_STATE_OFFSETS + TRELLIS_Y_OFFSET << 
"\" r = \"1\"/>" << 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 << "<line x1 =\"" << STAGE_STATE_OFFSETS * 
stage_num+ TRELLIS_X_OFFSET  << "\" ";
             trellis_fname << "y1 =\"" << state_num * STAGE_STATE_OFFSETS + 
TRELLIS_Y_OFFSET<< "\" ";
             trellis_fname << "x2 =\"" <<  STAGE_STATE_OFFSETS *stage_num + 
STAGE_STATE_OFFSETS+ TRELLIS_X_OFFSET << "\" ";
@@ -360,7 +359,7 @@
     }
   // label the stages
   trellis_fname << "<g font-size = \"4\" font= \"times\" fill = \"black\">" << 
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 << "<text x = \"" << stage_num * STAGE_STATE_OFFSETS + 
STAGE_LABEL_X_OFFSET << 
       "\" y = \""  << STAGE_LABEL_Y_OFFSET  << "\" >" << std::endl;
     trellis_fname << stage_num <<  std::endl;
@@ -370,7 +369,7 @@
 
   // label the states
   trellis_fname << "<g font-size = \"4\" font= \"times\" fill = \"black\">" << 
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 << "<text y = \"" << state_num * STAGE_STATE_OFFSETS + 
STATE_LABEL_Y_OFFSET << 
       "\" x = \""  << STATE_LABEL_X_OFFSET  << "\" >" << std::endl;
     trellis_fname << state_num <<  std::endl;
@@ -383,3 +382,32 @@
 //  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<d_S;i++) {
+     for(int j=0;j<d_I;j++)  trellis_fname << d_NS[i*d_I+j] << ' ';
+     trellis_fname << std::endl;
+   }
+   trellis_fname << std::endl;
+   for(int i=0;i<d_S;i++) {
+     for(int j=0;j<d_I;j++) trellis_fname << d_OS[i*d_I+j] << ' ';
+     trellis_fname << std::endl;
+   }
+   trellis_fname << std::endl;
+   trellis_fname.close();
+}
+

Modified: gnuradio/trunk/gr-trellis/src/lib/fsm.h
===================================================================
--- gnuradio/trunk/gr-trellis/src/lib/fsm.h     2007-02-12 23:04:42 UTC (rev 
4460)
+++ gnuradio/trunk/gr-trellis/src/lib/fsm.h     2007-02-13 04:50:17 UTC (rev 
4461)
@@ -58,7 +58,8 @@
   const std::vector< std::vector<int> > & PI () const { return d_PI; }
   const std::vector<int> & TMi () const { return d_TMi; }
   const std::vector<int> & 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

Modified: gnuradio/trunk/gr-trellis/src/lib/fsm.i
===================================================================
--- gnuradio/trunk/gr-trellis/src/lib/fsm.i     2007-02-12 23:04:42 UTC (rev 
4460)
+++ gnuradio/trunk/gr-trellis/src/lib/fsm.i     2007-02-13 04:50:17 UTC (rev 
4461)
@@ -45,10 +45,12 @@
   int O () const { return d_O; }
   const std::vector<int> & NS () const { return d_NS; }
   const std::vector<int> & OS () const { return d_OS; }
-  const std::vector< std::vector<int> > & PS () const { return d_PS; }
-  const std::vector< std::vector<int> > & PI () const { return d_PI; }
+  // disable these accessors until we find out how to swig them
+  //const std::vector< std::vector<int> > & PS () const { return d_PS; }
+  //const std::vector< std::vector<int> > & PI () const { return d_PI; }
   const std::vector<int> & TMi () const { return d_TMi; }
   const std::vector<int> & 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);
 };
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]