From: curt Date: Tue, 21 Apr 1998 19:14:21 +0000 (+0000) Subject: Modified Files: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=98f398c99ae66e5ab35d57b1384b724b04b98384;p=simgear.git Modified Files: Makefile.am Makefile.in Added Files: interpolater.cxx interpolater.hxx --- diff --git a/Math/Makefile.am b/Math/Makefile.am index 5518161f..6d743e92 100644 --- a/Math/Makefile.am +++ b/Math/Makefile.am @@ -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 diff --git a/Math/Makefile.in b/Math/Makefile.in index c838ac7f..28c6909e 100644 --- a/Math/Makefile.in +++ b/Math/Makefile.in @@ -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 diff --git a/Math/interpolater.cxx b/Math/interpolater.cxx new file mode 100644 index 00000000..5c552a4e --- /dev/null +++ b/Math/interpolater.cxx @@ -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 + +#include +#include + +#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 +// +// diff --git a/Math/interpolater.hxx b/Math/interpolater.hxx new file mode 100644 index 00000000..00d448f2 --- /dev/null +++ b/Math/interpolater.hxx @@ -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 +/* + */