Commit 797519eb authored by Pfeiffer, Götz's avatar Pfeiffer, Götz
Browse files

Bugfix in lookup_1d_functiontable (tables with just one point).


lookup_1d_functiontable now handles the case of a table with a single
point (xp,yp) correctly. It then returns the associated yp for any value of
x. Before this change, it returned NAN for x!=xp and yp for x==xp.

Additionally, the functions lookup_1d_functiontable and
lookup_2d_functiontable now return NAN (not a number) in case the table
doesn't contain any values.
parent 1c3d50f1
......@@ -11,7 +11,7 @@
/* module: CSM-BASE */
/* version-number of module: 1.1 */
/* author: Götz Pfeiffer */
/* last modification date: 2008-06-05 */
/* last modification date: 2011-08-16 */
/* status: tested */
/*____________________________________________________________*/
......@@ -137,6 +137,13 @@ Version 0.96:
Date: 2007-11-14
* the usage of semaphores can no be disabled by a macro.
This was needed for better portability.
Date: 2011-08-16
* The functions lookup_1d_functiontable and lookup_2d_functiontable now
return NAN (not a number) in case the table doesn't contain any values.
* lookup_1d_functiontable now handles the case of a table with a single
point (xp,yp) correctly. It then returns the associated yp for any value of
x. Before this change, it returned NAN for x!=xp and yp for x==xp.
*/
/*----------------------------------------------------*/
......@@ -303,6 +310,22 @@ Version 0.96:
#include <stdio.h>
#include <string.h>
/* math.h for definition of NAN */
#include <math.h>
/*@ITI________________________________________________________*/
/* Defines */
/*@ET_________________________________________________________*/
/*................................................*/
/*@IL the NAN number type */
/*................................................*/
#ifndef NAN
/*! \internal \brief define NAN if it is not yet defined */
#define NAN (-(0.0/0.0))
#endif
/*@ITI________________________________________________________*/
/* Types */
/*@ET_________________________________________________________*/
......@@ -897,9 +920,12 @@ static double lookup_1d_functiontable(csm_1d_functiontable *ft, double x,
if (res==-1) /* error */
return(0);
if (res== 2) /* exact match */
{ c= (xcoords->coordinate)[a];
return(NAN);
if ((res== 2)||(a==b)) /* exact match or table with just a single value */
{
/* if the table has just a single value (only one [x,y] pair) we return
the corresponding y value. */
c= (xcoords->coordinate)[a];
return( (ycoords->coordinate)[c.index].value );
};
......@@ -979,11 +1005,11 @@ static double lookup_2d_functiontable(csm_2d_functiontable *ft,
res= coordinate_lookup_index(xcoords, x, &xia, &xib);
if (res==-1) /* error */
return(0);
return(NAN);
res= coordinate_lookup_index(ycoords, y, &yia, &yib);
if (res==-1) /* error */
return(0);
return(NAN);
/* res==2 with exact match is currently not treated separately */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment