3 * Copyright 2002 Free Software Foundation, Inc.
\r
5 * This file is part of GNU Radio
\r
7 * GNU Radio is free software; you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation; either version 2, or (at your option)
\r
10 * any later version.
\r
12 * GNU Radio is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with GNU Radio; see the file COPYING. If not, write to
\r
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
\r
20 * Boston, MA 02111-1307, USA.
\r
25 #include <stdexcept>
\r
27 #include "quicksort_index.h"
\r
28 #include "interleaver.h"
\r
30 interleaver::interleaver()
\r
34 d_DEINTER.resize(0);
\r
37 interleaver::interleaver(const interleaver &INTERLEAVER)
\r
39 d_K=INTERLEAVER.K();
\r
40 d_INTER=INTERLEAVER.INTER();
\r
41 d_DEINTER=INTERLEAVER.DEINTER();
\r
44 interleaver::interleaver(const int K, const std::vector<int> &INTER)
\r
48 d_DEINTER.resize(d_K);
\r
50 // generate DEINTER table
\r
51 for(int i=0;i<d_K;i++) {
\r
52 d_DEINTER[d_INTER[i]]=i;
\r
56 //######################################################################
\r
57 //# Read an INTERLEAVER specification from a file.
\r
58 //# Format (hopefully will become more flexible in the future...):
\r
61 //# list of space separated K integers from 0 to K-1 in appropriate order
\r
62 //# optional comments
\r
63 //######################################################################
\r
64 interleaver::interleaver(const char *name)
\r
66 FILE *interleaverfile;
\r
68 if((interleaverfile=fopen(name,"r"))==NULL)
\r
69 throw std::runtime_error ("file open error in interleaver()");
\r
70 //printf("file open error in interleaver()\n");
\r
72 fscanf(interleaverfile,"%d\n",&d_K);
\r
73 d_INTER.resize(d_K);
\r
74 d_DEINTER.resize(d_K);
\r
76 for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));
\r
78 // generate DEINTER table
\r
79 for(int i=0;i<d_K;i++) {
\r
80 d_DEINTER[d_INTER[i]]=i;
\r
84 //######################################################################
\r
85 //# Generate a random interleaver
\r
86 //######################################################################
\r
87 interleaver::interleaver(const int K, unsigned int seed)
\r
90 d_INTER.resize(d_K);
\r
91 d_DEINTER.resize(d_K);
\r
93 std::runtime_error ("Not yet implemented: something wrong with quicksort\n");
\r
96 std::vector<int> tmp(d_K);
\r
97 for(int i=0;i<d_K;i++)
\r
100 quicksort_index <int> (tmp,d_INTER,0,d_K);
\r
102 // generate DEINTER table
\r
103 for(int i=0;i<d_K;i++) {
\r
104 d_DEINTER[d_INTER[i]]=i;
\r