}
Data = Allocate();
-
+ lastRowIndex=lastColumnIndex=2;
Debug(0);
}
Data = Allocate();
Debug(0);
+ lastRowIndex=lastColumnIndex=2;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
double FGTable::GetValue(double key)
{
double Factor, Value, Span;
- int r;
-
- for (r=1; r<=nRows; r++) if (Data[r][0] >= key) break;
- r = r < 2 ? 2 : (r > nRows ? nRows : r);
-
+ int r=lastRowIndex;
+
+ //if the key is off the end of the table, just return the
+ //end-of-table value, do not extrapolate
+ if( key <= Data[1][0] ) {
+ lastRowIndex=2;
+ //cout << "Key underneath table: " << key << endl;
+ return Data[1][1];
+ } else if ( key >= Data[nRows][0] ) {
+ lastRowIndex=nRows;
+ //cout << "Key over table: " << key << endl;
+ return Data[nRows][1];
+ }
+
+ // the key is somewhere in the middle, search for the right breakpoint
+ // assume the correct breakpoint has not changed since last frame or
+ // has only changed very little
+
+ if ( r > 2 && Data[r-1][0] > key ) {
+ while( Data[r-1][0] > key && r > 2) { r--; }
+ } else if ( Data[r][0] < key ) {
+ while( Data[r][0] <= key && r <= nRows) { r++; }
+ }
+
+ lastRowIndex=r;
// make sure denominator below does not go to zero.
-
+
Span = Data[r][0] - Data[r-1][0];
if (Span != 0.0) {
Factor = (key - Data[r-1][0]) / Span;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
double FGTable::GetValue(double rowKey, double colKey)
{
double rFactor, cFactor, col1temp, col2temp, Value;
- int r, c;
-
- for (r=1;r<=nRows;r++) if (Data[r][0] >= rowKey) break;
- for (c=1;c<=nCols;c++) if (Data[0][c] >= colKey) break;
-
- c = c < 2 ? 2 : (c > nCols ? nCols : c);
- r = r < 2 ? 2 : (r > nRows ? nRows : r);
-
+ int r=lastRowIndex;
+ int c=lastColumnIndex;
+
+ if ( r > 2 && Data[r-1][0] > rowKey ) {
+ while ( Data[r-1][0] > rowKey && r > 2) { r--; }
+ } else if ( Data[r][0] < rowKey ) {
+// cout << Data[r][0] << endl;
+ while ( r <= nRows && Data[r][0] <= rowKey ) { r++; }
+ if ( r > nRows ) r = nRows;
+ }
+
+ if ( c > 2 && Data[0][c-1] > colKey ) {
+ while( Data[0][c-1] > colKey && c > 2) { c--; }
+ } else if ( Data[0][c] < colKey ) {
+ while( Data[0][c] <= colKey && c <= nCols) { c++; }
+ if ( c > nCols ) c = nCols;
+ }
+
+ lastRowIndex=r;
+ lastColumnIndex=c;
+
rFactor = (rowKey - Data[r-1][0]) / (Data[r][0] - Data[r-1][0]);
cFactor = (colKey - Data[0][c-1]) / (Data[0][c] - Data[0][c-1]);
if (Type == tt1D) startRow = 1;
else startRow = 0;
- cout.setf(ios::fixed); // set up output stream
+#if defined (sgi) && !defined(__GNUC__)
+ unsigned long flags = cout.setf(ios::fixed);
+#else
+ ios::fmtflags flags = cout.setf(ios::fixed); // set up output stream
+#endif
+
cout.precision(4);
for (int r=startRow; r<=nRows; r++) {
}
cout << endl;
}
- cout.setf((ios_base::fmtflags)0, ios::floatfield); // reset
+ cout.setf(flags); // reset
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%