Modified Files:
Makefile.am Makefile.in Added Files: interpolater.cxx interpolater.hxx
This commit is contained in:
parent
e5efd5bf69
commit
98f398c99a
4 changed files with 208 additions and 4 deletions
|
@ -8,7 +8,7 @@ libMath_la_SOURCES = \
|
|||
MAT3vec.c \
|
||||
fg_geodesy.c fg_geodesy.h \
|
||||
fg_random.c fg_random.h \
|
||||
interpolater.c interpolater.h \
|
||||
interpolater.cxx interpolater.hxx \
|
||||
mat3.h mat3defs.h mat3err.h \
|
||||
polar.c polar.h \
|
||||
vector.c vector.h
|
||||
|
|
|
@ -80,7 +80,7 @@ libMath_la_SOURCES = \
|
|||
MAT3vec.c \
|
||||
fg_geodesy.c fg_geodesy.h \
|
||||
fg_random.c fg_random.h \
|
||||
interpolater.c interpolater.h \
|
||||
interpolater.cxx interpolater.hxx \
|
||||
mat3.h mat3defs.h mat3err.h \
|
||||
polar.c polar.h \
|
||||
vector.c vector.h
|
||||
|
@ -102,6 +102,10 @@ libMath_la_LDFLAGS =
|
|||
libMath_la_LIBADD =
|
||||
libMath_la_OBJECTS = MAT3geom.lo MAT3inv.lo MAT3mat.lo MAT3vec.lo \
|
||||
fg_geodesy.lo fg_random.lo interpolater.lo polar.lo vector.lo
|
||||
CXXFLAGS = @CXXFLAGS@
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
|
||||
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
|
||||
CXXLINK = $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
|
||||
|
@ -116,13 +120,14 @@ GZIP = --best
|
|||
DEP_FILES = .deps/MAT3geom.P .deps/MAT3inv.P .deps/MAT3mat.P \
|
||||
.deps/MAT3vec.P .deps/fg_geodesy.P .deps/fg_random.P \
|
||||
.deps/interpolater.P .deps/polar.P .deps/vector.P
|
||||
CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)
|
||||
SOURCES = $(libMath_la_SOURCES)
|
||||
OBJECTS = $(libMath_la_OBJECTS)
|
||||
|
||||
all: Makefile $(LTLIBRARIES)
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .S .c .lo .o .s
|
||||
.SUFFIXES: .S .c .cxx .lo .o .s
|
||||
$(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --gnu Lib/Math/Makefile
|
||||
|
||||
|
@ -189,7 +194,11 @@ distclean-libtool:
|
|||
maintainer-clean-libtool:
|
||||
|
||||
libMath.la: $(libMath_la_OBJECTS) $(libMath_la_DEPENDENCIES)
|
||||
$(LINK) -rpath $(libdir) $(libMath_la_LDFLAGS) $(libMath_la_OBJECTS) $(libMath_la_LIBADD) $(LIBS)
|
||||
$(CXXLINK) -rpath $(libdir) $(libMath_la_LDFLAGS) $(libMath_la_OBJECTS) $(libMath_la_LIBADD) $(LIBS)
|
||||
.cxx.o:
|
||||
$(CXXCOMPILE) -c $<
|
||||
.cxx.lo:
|
||||
$(LTCXXCOMPILE) -c $<
|
||||
|
||||
tags: TAGS
|
||||
|
||||
|
@ -256,6 +265,17 @@ maintainer-clean-depend:
|
|||
@-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
|
||||
< .deps/$(*F).p > .deps/$(*F).P
|
||||
@-rm -f .deps/$(*F).p
|
||||
|
||||
%.o: %.cxx
|
||||
@echo '$(CXXCOMPILE) -c $<'; \
|
||||
$(CXXCOMPILE) -Wp,-MD,.deps/$(*F).P -c $<
|
||||
|
||||
%.lo: %.cxx
|
||||
@echo '$(LTCXXCOMPILE) -c $<'; \
|
||||
$(LTCXXCOMPILE) -Wp,-MD,.deps/$(*F).p -c $<
|
||||
@-sed -e 's/^\([^:]*\)\.o:/\1.lo \1.o:/' \
|
||||
< .deps/$(*F).p > .deps/$(*F).P
|
||||
@-rm -f .deps/$(*F).p
|
||||
info:
|
||||
dvi:
|
||||
check: all
|
||||
|
|
116
Math/interpolater.cxx
Normal file
116
Math/interpolater.cxx
Normal file
|
@ -0,0 +1,116 @@
|
|||
//
|
||||
// interpolater.cxx -- routines to handle linear interpolation from a table of
|
||||
// x,y The table must be sorted by "x" in ascending order
|
||||
//
|
||||
// Written by Curtis Olson, started April 1998.
|
||||
//
|
||||
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
// $Id$
|
||||
// (Log is kept at end of this file)
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <Debug/fg_debug.h>
|
||||
#include <zlib/zlib.h>
|
||||
|
||||
#include "interpolater.hxx"
|
||||
|
||||
|
||||
// Constructor -- loads the interpolation table from the specified
|
||||
// file
|
||||
fgINTERPTABLE::fgINTERPTABLE( char *file ) {
|
||||
char gzfile[256], line[256];
|
||||
gzFile fd;
|
||||
|
||||
fgPrintf( FG_MATH, FG_INFO, "Initializing Interpolator for %s\n", file);
|
||||
|
||||
// First try "file.gz"
|
||||
strcpy(gzfile, file);
|
||||
strcat(gzfile, ".gz");
|
||||
if ( (fd = gzopen(gzfile, "r")) == NULL ) {
|
||||
// Next try "path"
|
||||
if ( (fd = gzopen(file, "r")) == NULL ) {
|
||||
fgPrintf(FG_MATH, FG_ALERT, "Cannot open file: %s\n", file);
|
||||
}
|
||||
}
|
||||
|
||||
size = 0;
|
||||
while ( gzgets(fd, line, 250) != NULL ) {
|
||||
if ( size < MAX_TABLE_SIZE ) {
|
||||
sscanf(line, "%lf %lf\n", &(table[size][0]), &(table[size][1]));
|
||||
size++;
|
||||
} else {
|
||||
fgPrintf( FG_MATH, FG_ALERT,
|
||||
"fgInterpolateInit(): Exceed max table size = %d\n",
|
||||
MAX_TABLE_SIZE );
|
||||
}
|
||||
}
|
||||
|
||||
gzclose(fd);
|
||||
}
|
||||
|
||||
|
||||
// Given an x value, linearly interpolate the y value from the table
|
||||
double fgINTERPTABLE::interpolate(double x) {
|
||||
int i;
|
||||
double y;
|
||||
|
||||
i = 0;
|
||||
|
||||
while ( (x > table[i][0]) && (i < size) ) {
|
||||
i++;
|
||||
}
|
||||
|
||||
printf ("i = %d ", i);
|
||||
|
||||
if ( (i == 0) && (x < table[0][0]) ) {
|
||||
fgPrintf( FG_MATH, FG_ALERT,
|
||||
"fgInterpolateInit(): lookup error, x to small = %.2f\n", x);
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
if ( x > table[i][0] ) {
|
||||
fgPrintf( FG_MATH, FG_ALERT,
|
||||
"fgInterpolateInit(): lookup error, x to big = %.2f\n", x);
|
||||
return(0.0);
|
||||
}
|
||||
|
||||
// y = y1 + (y0 - y1)(x - x1) / (x0 - x1)
|
||||
y = table[i][1] +
|
||||
( (table[i-1][1] - table[i][1]) *
|
||||
(x - table[i][0]) ) /
|
||||
(table[i-1][0] - table[i][0]);
|
||||
|
||||
return(y);
|
||||
}
|
||||
|
||||
|
||||
// Destructor
|
||||
fgINTERPTABLE::~fgINTERPTABLE( void ) {
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.1 1998/04/21 19:14:23 curt
|
||||
// Modified Files:
|
||||
// Makefile.am Makefile.in
|
||||
// Added Files:
|
||||
// interpolater.cxx interpolater.hxx
|
||||
//
|
||||
//
|
68
Math/interpolater.hxx
Normal file
68
Math/interpolater.hxx
Normal file
|
@ -0,0 +1,68 @@
|
|||
/**************************************************************************
|
||||
* interpolater.hxx -- routines to handle linear interpolation from a table of
|
||||
* x,y The table must be sorted by "x" in ascending order
|
||||
*
|
||||
* Written by Curtis Olson, started April 1998.
|
||||
*
|
||||
* Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id$
|
||||
* (Log is kept at end of this file)
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
#ifndef _INTERPOLATER_H
|
||||
#define _INTERPOLATER_H
|
||||
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error This library requires C++
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_TABLE_SIZE 32
|
||||
|
||||
|
||||
class fgINTERPTABLE {
|
||||
int size;
|
||||
double table[MAX_TABLE_SIZE][2];
|
||||
|
||||
public:
|
||||
|
||||
// Constructor -- loads the interpolation table from the specified
|
||||
// file
|
||||
fgINTERPTABLE( char *file );
|
||||
|
||||
// Given an x value, linearly interpolate the y value from the table
|
||||
double interpolate(double x);
|
||||
|
||||
// Destructor
|
||||
~fgINTERPTABLE( void );
|
||||
};
|
||||
|
||||
|
||||
#endif /* _INTERPOLATER_H */
|
||||
|
||||
|
||||
/* $Log$
|
||||
/* Revision 1.1 1998/04/21 19:14:23 curt
|
||||
/* Modified Files:
|
||||
/* Makefile.am Makefile.in
|
||||
/* Added Files:
|
||||
/* interpolater.cxx interpolater.hxx
|
||||
/*
|
||||
*/
|
Loading…
Reference in a new issue