# Something about forecast()

**URL:** <https://www.ruby-forum.com/t/something-about-forecast/230184>\
**Category:** GNU Radio\
**Created:** [June 4, 2014, 8:39am UTC](https://www.ruby-forum.com/t/something-about-forecast/230184 "2014-06-04T08:39:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 4, 2014, 8:39am UTC](https://www.ruby-forum.com/t/something-about-forecast/230184/1 "2014-06-04T08:39:46Z")

</div>

Hi all:  
I want to know something about the forecast().  
I have already known that forcast() can tell scheduler how  
many input items are required for each output item.  
1.But now i have read two example:  
The first one:  
void your\_block::forecast(int  
noutput\_items,gr\_vector\_int &ninput\_items\_required){  
ninput\_items\_required[0]=100 \*  
noutput\_items;

```
                                ninput_items_required[1]=100 * 

```

noutput\_items; }  
I have already understand it.  
But the second one:  
void forecast (int noutput\_items,  
gr\_vector\_int &ninput\_items\_required)  
{  
unsigned ninputs =  
ninput\_items\_required.size ();  
for (unsigned i = 0; i \< ninputs; i++)  
ninput\_items\_required[i] = 1;}  
I can’t understand since we can’t know how many  
input items we required,why use ninput\_items\_required.size ().Can  
someone help me?  
2.I want to know if we use the general\_work().Is it means  
that we must use the forcast()?Thanks.  
Best regards

---

<div class="post-metadata">

**Author:** ![xianda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/b38774/32.png) [@xianda](https://www.ruby-forum.com/u/xianda)\
**Post date:** [June 4, 2014, 9:12am UTC](https://www.ruby-forum.com/t/something-about-forecast/230184/2 "2014-06-04T09:12:46Z")

</div>

Hi Xianda,

Easiest answer first:

1. You need to write a forecast if, and only if, you’re using  
general\_work. I generally try to avoid doing that.

Then:  
1.  
ninput\_items\_required is, as you can see in the function signature, a  
reference to a vector.  
The size of the vector is the number of input ports.  
Compare to  
[http://gnuradio.org/doc/doxygen/classgr\_1\_1block.html#a5bc118d94944d2ff71e378f807fb8d28](http://gnuradio.org/doc/doxygen/classgr_1_1block.html#a5bc118d94944d2ff71e378f807fb8d28)

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![xianda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/b38774/32.png) [@xianda](https://www.ruby-forum.com/u/xianda)\
**Post date:** [June 4, 2014, 9:22am UTC](https://www.ruby-forum.com/t/something-about-forecast/230184/3 "2014-06-04T09:22:12Z")

</div>

On Wed, Jun 4, 2014 at 2:22 PM, xianda [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> ninput_items_required[1]=100 * 
> 
> ```

noutput\_items; }

> 

In your first example above, you have exactly two input ports.  
That’s why you need to specify “ninput\_items\_required[0]” and  
“ninput\_items\_required[1]”, there are in total 2 ports.  
In fact in this example the value of “ninput\_items\_required.size()” is  
2.  
In alternative, you could also replace above two lines with:

```
for (unsigned i=0; i < 2; i++)
   ninput_items_required[i] = 100 * noutput_items;

```

Or, to be more generic, you could also use this:

for (unsigned i=0; i \< ninput\_items\_required.size(); i++)  
ninput\_items\_required[i] = 100 \* noutput\_items;

> ```
> 2.I want to know if we use the general_work().Is it means that we 
> 
> ```

must use the forcast()?Thanks.

> Best regards

If you use “general” block, you need to specify “forecast()”.  
“General” block has “general\_work()” function but not “general()”  
function.

If you use sync block, decim, interpolation block etc, you have “work()”  
but not “general\_work()”, and you don’t need to write “forecast()”.  
This is very straight-forward.

---

<div class="post-metadata">

**Author:** ![xianda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/b38774/32.png) [@xianda](https://www.ruby-forum.com/u/xianda)\
**Post date:** [June 5, 2014, 4:15am UTC](https://www.ruby-forum.com/t/something-about-forecast/230184/4 "2014-06-05T04:15:11Z")

</div>

Hi Xianda,  
the io\_signature specifies a minimum and a maximum number of inputs, so  
this might be 1,2 or 3.

Greetings,  
Marcus
