diff --git a/scilab/modules/scicos_blocks/src/c/cmscope.c b/scilab/modules/scicos_blocks/src/c/cmscope.c index d47ee17cb70..b57da9c2bdf 100644 --- a/scilab/modules/scicos_blocks/src/c/cmscope.c +++ b/scilab/modules/scicos_blocks/src/c/cmscope.c @@ -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 + * Copyright (C) 2016 - Lakshmi Prasanna Mutyala + * * 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, @@ -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]++;