3 * Copyright 2002 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
28 #include "quicksort_index.h"
29 #include "interleaver.h"
31 interleaver::interleaver()
38 interleaver::interleaver(const interleaver &INTERLEAVER)
41 d_INTER=INTERLEAVER.INTER();
42 d_DEINTER=INTERLEAVER.DEINTER();
45 interleaver::interleaver(int K, const std::vector<int> &INTER)
49 d_DEINTER.resize(d_K);
51 // generate DEINTER table
52 for(int i=0;i<d_K;i++) {
53 d_DEINTER[d_INTER[i]]=i;
57 //######################################################################
58 //# Read an INTERLEAVER specification from a file.
59 //# Format (hopefully will become more flexible in the future...):
62 //# list of space separated K integers from 0 to K-1 in appropriate order
64 //######################################################################
65 interleaver::interleaver(const char *name)
67 FILE *interleaverfile;
69 if((interleaverfile=fopen(name,"r"))==NULL)
70 throw std::runtime_error ("file open error in interleaver()");
71 //printf("file open error in interleaver()\n");
73 fscanf(interleaverfile,"%d\n",&d_K);
75 d_DEINTER.resize(d_K);
77 for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));
79 // generate DEINTER table
80 for(int i=0;i<d_K;i++) {
81 d_DEINTER[d_INTER[i]]=i;
85 //######################################################################
86 //# Generate a random interleaver
87 //######################################################################
88 interleaver::interleaver(int K, unsigned int seed)
92 d_DEINTER.resize(d_K);
95 std::vector<int> tmp(d_K);
96 for(int i=0;i<d_K;i++) {
100 //quicksort_index <int> (tmp,d_INTER,0,d_K-1); //got to resolve this...
101 quicksort_index1 (tmp,d_INTER,0,d_K-1);
103 // generate DEINTER table
104 for(int i=0;i<d_K;i++) {
105 d_DEINTER[d_INTER[i]]=i;