make maintainer-clean removes these, and we want a clean orig.tar.gz
[debian/gnuradio] / gr-trellis / src / lib / interleaver.cc
index 5e8a912d94d5fe74aef86cfa4d81227484aceaaa..077416f808715506ae5309ae8ad11a92f5463ef3 100644 (file)
@@ -6,7 +6,7 @@
  *
  * GNU Radio is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
+ * the Free Software Foundation; either version 3, or (at your option)
  * any later version.
  *
  * GNU Radio is distributed in the hope that it will be useful,
  *
  * You should have received a copy of the GNU General Public License
  * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
  */
 
 #include <cstdlib> 
 #include <cstdio>
 #include <iostream>
+#include <string>
+#include <fstream>
 #include <stdexcept>
 #include <cmath>
 #include "quicksort_index.h"
 #include "interleaver.h"
 
+
+
+
 interleaver::interleaver()
 {
   d_K=0;
@@ -85,20 +90,19 @@ interleaver::interleaver(const char *name)
 //######################################################################
 //# Generate a random interleaver
 //######################################################################
-interleaver::interleaver(int K, unsigned int seed)
+interleaver::interleaver(int K, int seed)
 {
   d_K=K;
   d_INTER.resize(d_K);
   d_DEINTER.resize(d_K);
 
-  srand(seed); 
+  if(seed>=0) srand((unsigned int)seed); 
   std::vector<int> tmp(d_K);
   for(int i=0;i<d_K;i++) {
     d_INTER[i]=i;
     tmp[i] = rand(); 
   }
-  //quicksort_index <int> (tmp,d_INTER,0,d_K-1); //got to resolve this...
-  quicksort_index1 (tmp,d_INTER,0,d_K-1);
+  quicksort_index <int> (tmp,d_INTER,0,d_K-1);
 
   // generate DEINTER table
   for(int i=0;i<d_K;i++) {
@@ -106,3 +110,26 @@ interleaver::interleaver(int K, unsigned int seed)
   }
 }
 
+
+
+
+
+//######################################################################
+//# Write an INTERLEAVER specification from a file.
+//# Format
+//# K
+//# blank line
+//# list of space separated K integers from 0 to K-1 in appropriate order
+//# optional comments
+//######################################################################
+void interleaver::write_interleaver_txt(std::string filename)
+{
+   std::ofstream interleaver_fname (filename.c_str());
+   if (!interleaver_fname) {std::cout << "file not found " << std::endl ; exit(-1);}
+   interleaver_fname << d_K << std::endl;
+   interleaver_fname << std::endl;
+   for(int i=0;i<d_K;i++)
+     interleaver_fname << d_INTER[i] << ' ';
+   interleaver_fname << std::endl;
+   interleaver_fname.close();
+}