Skip to content

implement Run time Auto Scaling - CMSCOPE block #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions scilab/modules/scicos_blocks/src/c/cmscope.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2011-2012 - Scilab Enterprises - Clement DAVID
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* Copyright (C) 2016 - Pulkit Mittal <[email protected]>
* Copyright (C) 2016 - Lakshmi Prasanna Mutyala <[email protected]>
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally licensed under the terms of the CeCILL v2.1,
Expand Down Expand Up @@ -662,13 +664,60 @@ static void appendData(scicos_block * block, int input, double t, double *data)

/*
* Update data
*
* Implements Run-Time Auto scaling of graphs
*
*/
if (sco != NULL)
{
for (i = 0; i < block->insz[input]; i++)
{
const double value = data[i];
double value = data[i];
//printf("value(to be plotted)=%lf\n",value);
setBuffersCoordinates(block, input, sco->internal.bufferCoordinates[input][i], sco->internal.numberOfPoints[input], block->ipar[2], t, value);

double max_curr_val,prev_max_curr_val;
//Get the current maximum value of the axes
max_curr_val = block->rpar[block->nrpar - 2 * (block->nin) + 2 * input+1];
prev_max_curr_val = max_curr_val;

double min_curr_val,prev_min_curr_val;
//Get the current minimum value of the axes
min_curr_val = block->rpar[block->nrpar - 2 * (block->nin) + 2 * input];
prev_min_curr_val = min_curr_val;

/* If the value to be plotted exceeds the current range, then we update the range.
* We could update the range from current value to the new value i.e. (value + R)
* where R varies from 0 to approx 150. So we have used (value + 100.0) to give the graph good feature.
*
* However, the auto-scaling feature implemented is general and will work fine even for
*/

//If the value to be plotted is greater than or equal to the current max, then update the current max
if(value >= max_curr_val)
{
max_curr_val = value + 10.0;
block->rpar[block->nrpar - 2 * (block->nin) + 2 * input+1] = max_curr_val;
}

//If the value to be plotted is smaller than or equal to the current min, then update the current min
if(value <= min_curr_val)
{
min_curr_val = value - 10.0;
block->rpar[block->nrpar - 2 * (block->nin) + 2 * input] = min_curr_val;
}

//If value has changed, call the setPolylinesBounds function to update the ranges
if((max_curr_val != prev_max_curr_val) || (min_curr_val != prev_min_curr_val))
{
if (setPolylinesBounds(block, input, sco->scope.periodCounter[input]) == FALSE)
{
set_block_error(-5);
freeScoData(block);
sco = NULL;
}
}

}

sco->internal.numberOfPoints[input]++;
Expand Down