Skip to content

Commit

Permalink
Bug [# 1678]
Browse files Browse the repository at this point in the history
fix return value for Modelica.Blocks.Tables.CombiTable2D if input signal is out of bound
- add warning if other smoothness than LinearSegment is used

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10927 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jan 19, 2012
1 parent 70fe4f8 commit 9f113c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SimulationRuntime/c/ModelicaExternalC/ModelicaTablesImpl.c
Expand Up @@ -75,7 +75,7 @@ int ModelicaTables_CombiTable2D_init(const char* tableName, const char* fileName
double const *table, int nRow, int nColumn,
int smoothness)
{
return omcTable2DIni(0,tableName,fileName,table,nRow,nColumn,0);
return omcTable2DIni(smoothness,tableName,fileName,table,nRow,nColumn,0);
}

void ModelicaTables_CombiTable2D_close(int tableID)
Expand Down
12 changes: 7 additions & 5 deletions SimulationRuntime/c/ModelicaExternalC/tables.c
Expand Up @@ -1148,9 +1148,13 @@ InterpolationTable2D* InterpolationTable2D_init(int ipoType, const char* tableNa
tpl = (InterpolationTable2D*)calloc(1,sizeof(InterpolationTable2D));
ASSERT1(tpl,"Not enough memory for Table: %s",tableName);

if (ipoType != 1)
WARNING2("Currently only LinearSegments interpolation is supported. For Table %s from file %s LinearSegments interpolation is used.",tableName,fileName);

tpl->rows = tableDim1;
tpl->cols = tableDim2;
tpl->colWise = colWise;
tpl->ipoType = ipoType;

tpl->tablename = copyTableNameFile(tableName);
tpl->filename = copyTableNameFile(fileName);
Expand Down Expand Up @@ -1200,14 +1204,12 @@ double InterpolationTable2D_interpolate(InterpolationTable2D *table, double x1,
x1 = tmp;
}

/* if out of boundary, just set to min/max */
x1 = fmin(fmax(x1,InterpolationTable2D_getElt(table,1,0)),InterpolationTable2D_getElt(table,table->rows-1,0));
x2 = fmin(fmax(x2,InterpolationTable2D_getElt(table,0,1)),InterpolationTable2D_getElt(table,0,table->cols-1));
/* if out of boundary, use first or last two points */

/* find intervals corresponding x1 and x2 */
for(i = 2; i < table->rows; ++i)
for(i = 2; i < table->rows-1; ++i)
if (InterpolationTable2D_getElt(table,i,0) >= x1) break;
for(j = 2; j < table->cols; ++j)
for(j = 2; j < table->cols-1; ++j)
if (InterpolationTable2D_getElt(table,0,j) >= x2) break;

/* bilinear interpolation */
Expand Down

0 comments on commit 9f113c7

Please sign in to comment.