# Vector Source variable from file

**URL:** <https://www.ruby-forum.com/t/vector-source-variable-from-file/234581>\
**Category:** GNU Radio\
**Created:** [March 15, 2015, 12:38am UTC](https://www.ruby-forum.com/t/vector-source-variable-from-file/234581 "2015-03-15T00:38:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [March 15, 2015, 12:38am UTC](https://www.ruby-forum.com/t/vector-source-variable-from-file/234581/1 "2015-03-15T00:38:05Z")

</div>

Hi all,

I have a vector source that repeats and points to two variables A + B ,  
within variable A is 1100 is it possible to have variable B point to a  
file  
that contains a whole bunch of binary combinations separated line by  
line.

Ideally I would like to run a flow graph and upon every repeat cycle to  
go  
down the list of possible combinations within the file for variable B.

Cheers

---

<div class="post-metadata">

**Author:** ![tom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@tom](https://www.ruby-forum.com/u/tom)\
**Post date:** [March 15, 2015, 1:56am UTC](https://www.ruby-forum.com/t/vector-source-variable-from-file/234581/2 "2015-03-15T01:56:05Z")

</div>

Tom,

I’m new to gnuradio, so let’s see if any replies offer better advice.  
But I did something similar to what you ask. In my case, the value of  
the variable is a call to my python code. You can see what I did in the  
top two examples at

[Gnuradio Mini Projects](http://udel.edu/~mm/gr/)

Both grc file and my code are there. You can write something that pulls  
the numbers from your file.

Good luck,  
Mike

---

<div class="post-metadata">

**Author:** ![tom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@tom](https://www.ruby-forum.com/u/tom)\
**Post date:** [March 15, 2015, 5:17am UTC](https://www.ruby-forum.com/t/vector-source-variable-from-file/234581/3 "2015-03-15T05:17:23Z")

</div>

Ill just explain a little different, it may prompt somebody to say hey  
this  
is easy just do this… ( I wish)

I have a variable called Data2, within this variable is S+S+S+L  
Variable S is 1000  
Variable L is 100

Data2 is feed into a vector source, this source looks like Data1+Data2  
(repeat=yes) Data1 is static data.

I would like to cycle through all possible combinations of the variable  
Data2 on each repeat cycle of the vector source.

S+S+S+S  
S+S+S+L  
S+S+L+L  
S+L+L+L  
L+L+L+L  
L+S+S+S  
L+S+S+L  
Etc…  
Etc…

---

<div class="post-metadata">

**Author:** ![tom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@tom](https://www.ruby-forum.com/u/tom)\
**Post date:** [March 15, 2015, 4:11am UTC](https://www.ruby-forum.com/t/vector-source-variable-from-file/234581/4 "2015-03-15T04:11:17Z")

</div>

Thanks Mike,

I created python code to open the file which has the random data in in  
it  
however unfortunately the vector source complains "can only concatenate  
list  
(not module) to list, not quite sure what I’m doing wrong.

Will keep at it lol

---

<div class="post-metadata">

**Author:** ![tom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@tom](https://www.ruby-forum.com/u/tom)\
**Post date:** [March 15, 2015, 11:09am UTC](https://www.ruby-forum.com/t/vector-source-variable-from-file/234581/5 "2015-03-15T11:09:30Z")

</div>

Hi Tom,

A few things;

> I have a vector source that repeats and points to two variables A + B  
> How do I have to read that? Do you have a vector source, and you set its  
> data to be the concatenation of list A and list B?

> variable A is 1100  
> I assume you mean that A is [1,1,0,0] (a python list of integers), not  
> 1100 (an integer, which is 1 more than 1099).  
> a file that contains a whole bunch of binary combinations separated  
> line by line.  
> Ah, I think you’re talking about a text file containing lines that look  
> like “11010100101”, right? Notice that these are strings of characters,  
> not binary data.  
> Why are they separated line by line?

Please confirm I understand you correctly:  
You want the vector source to emit the following:  
[1,1,0,0,bits,from,the,first,line,1,1,0,0,bits,from,the,second,line,1,1,0,0  
…]

If that’s the case, it’s not impossible to do:

in your vector source, you’ll have to put in some ugly-ish python.  
Something like

numpy.ravel([[1,1,0,0] + [ ord(character) - ord(“0”) for character in  
line[:-1]] for line in open(“txt.xt”,“r”).readlines() ])

(you might need to add an import block “import numpy” for this to work).

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![tom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/3d9bf3/32.png) [@tom](https://www.ruby-forum.com/u/tom)\
**Post date:** [March 15, 2015, 11:39pm UTC](https://www.ruby-forum.com/t/vector-source-variable-from-file/234581/6 "2015-03-15T23:39:17Z")

</div>

Thanks Marcus for getting back to me,

You will have to forgive me as i am new to Gnuradio and Python but I  
will  
try my best to answer these.

> How do I have to read that? Do you have a vector source, and you set its  
> data to be the concatenation of list A and list B?

Correct

> I assume you mean that A is [1,1,0,0] (a python list of integers), not  
> 1100 (an integer, which is 1 more than 1099).

Correct my variable A contains [1,1,0,0]

> Ah, I think you’re talking about a text file containing lines that look  
> like “11010100101”, right? Notice that these are strings of characters,  
> not  
> binary data.  
> Why are they separated line by line?

I could put them in square brackets to look like

[1,0,0,0]  
[1,0,0,0,0,0]  
etc

> Please confirm I understand you correctly:  
> You want the vector source to emit the following:

[1,1,0,0,bits,from,the,first,line,1,1,0,0,bits,from,the,second,line,1,1,0,0

> …]

> If that’s the case, it’s not impossible to do:

> in your vector source, you’ll have to put in some ugly-ish python.  
> Something like

> numpy.ravel([[1,1,0,0] + [ ord(character) - ord(“0”) for character in  
> line[:-1]] for line in open(“txt.xt”,“r”).readlines() ])

> (you might need to add an import block “import numpy” for this to work).

> Greetings,  
> Marcus

Since I have variable A defined as [1,0,0,0] and variable B defined as  
[1,0,0,0,0,0] do you think it’s possible with some Python code to get my  
vector source to cycle through all possible combinations of those  
variables  
up to four? Hope that makes sense.

A+A+A+A  
A+A+A+B  
A+A+B+B  
A+B+B+B  
B+B+B+B  
B+B+B+A  
B+B+A+A  
B+A+A+A  
etc…  
…  
…
