From: curt Date: Wed, 8 Apr 1998 22:54:56 +0000 (+0000) Subject: Adopted Gnu automake/autoconf system. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=079b3ad13d7387fd160c25e854c23072cd0d45ec;p=flightgear.git Adopted Gnu automake/autoconf system. --- diff --git a/AssemTris/Makefile b/AssemTris/Makefile deleted file mode 100644 index 842396e04..000000000 --- a/AssemTris/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -#--------------------------------------------------------------------------- -# Makefile -# -# Written by Curtis Olson, started January 1998. -# -# Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com -# -# 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) -#--------------------------------------------------------------------------- - - -TARGET = assemtris - -CFILES = assemtris.c -LDLIBS = -lMath -lScenery -lm - - -include $(FG_ROOT_SRC)/commondefs - - -#--------------------------------------------------------------------------- -# Rule for TARGET -#--------------------------------------------------------------------------- - -$(TARGET): $(OBJECTS) - $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(LDLIBS) - - -include $(COMMONRULES) - - -#--------------------------------------------------------------------------- -# $Log$ -# Revision 1.2 1998/01/21 02:55:46 curt -# Incorporated new make system from Bob Kuehne . -# -# Revision 1.1 1998/01/15 02:45:25 curt -# Initial revision. -# - diff --git a/AssemTris/Makefile.am b/AssemTris/Makefile.am new file mode 100644 index 000000000..aed518219 --- /dev/null +++ b/AssemTris/Makefile.am @@ -0,0 +1,48 @@ +#--------------------------------------------------------------------------- +# Makefile +# +# Written by Curtis Olson, started January 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) +#--------------------------------------------------------------------------- + + +bin_PROGRAMS = assemtris + +assemtris_SOURCES = assemtris.c assemtris.h + +assemtris_LDADD = \ + $(top_builddir)/Simulator/Scenery/Bucket/libBucket.la + +INCLUDES += -I../../Simulator + + +#--------------------------------------------------------------------------- +# $Log$ +# Revision 1.1 1998/04/08 22:54:57 curt +# Adopted Gnu automake/autoconf system. +# +# Revision 1.2 1998/01/21 02:55:46 curt +# Incorporated new make system from Bob Kuehne . +# +# Revision 1.1 1998/01/15 02:45:25 curt +# Initial revision. +# + diff --git a/AssemTris/Makefile.in b/AssemTris/Makefile.in new file mode 100644 index 000000000..1bcc681b3 --- /dev/null +++ b/AssemTris/Makefile.in @@ -0,0 +1,360 @@ +# Makefile.in generated automatically by automake 1.2h from Makefile.am + +# Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +#--------------------------------------------------------------------------- +# Makefile +# +# Written by Curtis Olson, started January 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) +#--------------------------------------------------------------------------- + + +SHELL = /bin/sh + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DISTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +CC = @CC@ +CXX = @CXX@ +LD = @LD@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +NM = @NM@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +VERSION = @VERSION@ + +bin_PROGRAMS = assemtris + +assemtris_SOURCES = assemtris.c assemtris.h + +assemtris_LDADD = \ + $(top_builddir)/Simulator/Scenery/Bucket/libBucket.la +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../Simulator/Include/config.h +CONFIG_CLEAN_FILES = +PROGRAMS = $(bin_PROGRAMS) + + +DEFS = @DEFS@ -I. -I$(srcdir) -I../../Simulator/Include +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_LIBS = @X_LIBS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +assemtris_OBJECTS = assemtris.o +assemtris_DEPENDENCIES = \ +$(top_builddir)/Simulator/Scenery/Bucket/libBucket.la +assemtris_LDFLAGS = +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) +LINK = $(LIBTOOL) --mode=link $(CC) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = tar +GZIP = --best +DEP_FILES = .deps/assemtris.P +SOURCES = $(assemtris_SOURCES) +OBJECTS = $(assemtris_OBJECTS) + +all: Makefile $(PROGRAMS) + +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .s +$(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu Tools/AssemTris/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-binPROGRAMS: + +clean-binPROGRAMS: + -test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS) + +distclean-binPROGRAMS: + +maintainer-clean-binPROGRAMS: + +install-binPROGRAMS: $(bin_PROGRAMS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(bindir) + @list='$(bin_PROGRAMS)'; for p in $$list; do \ + if test -f $$p; then \ + echo " $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`"; \ + $(LIBTOOL) --mode=install $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ + else :; fi; \ + done + +uninstall-binPROGRAMS: + @$(NORMAL_UNINSTALL) + list='$(bin_PROGRAMS)'; for p in $$list; do \ + rm -f $(DESTDIR)$(bindir)/`echo $$p|sed '$(transform)'`; \ + done + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +assemtris: $(assemtris_OBJECTS) $(assemtris_DEPENDENCIES) + @rm -f assemtris + $(LINK) $(assemtris_LDFLAGS) $(assemtris_OBJECTS) $(assemtris_LDADD) $(LIBS) + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $(SOURCES) $(HEADERS) $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = Tools/AssemTris + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu Tools/AssemTris/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + +maintainer-clean-depend: + -rm -rf .deps + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).P -c $< + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -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 + $(MAKE) +installcheck: +install-exec: install-binPROGRAMS + @$(NORMAL_INSTALL) + +install-data: + @$(NORMAL_INSTALL) + +install: install-exec install-data all + @: + +uninstall: uninstall-binPROGRAMS + +install-strip: + $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' INSTALL_SCRIPT='$(INSTALL_PROGRAM)' install +installdirs: + $(mkinstalldirs) $(DATADIR)$(bindir) + + +mostlyclean-generic: + -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f Makefile $(DISTCLEANFILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +mostlyclean: mostlyclean-binPROGRAMS mostlyclean-compile \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ + mostlyclean-generic + +clean: clean-binPROGRAMS clean-compile clean-libtool clean-tags \ + clean-depend clean-generic mostlyclean + +distclean: distclean-binPROGRAMS distclean-compile distclean-libtool \ + distclean-tags distclean-depend distclean-generic clean + -rm -f config.status + -rm -f libtool + +maintainer-clean: maintainer-clean-binPROGRAMS maintainer-clean-compile \ + maintainer-clean-libtool maintainer-clean-tags \ + maintainer-clean-depend maintainer-clean-generic \ + distclean + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +.PHONY: mostlyclean-binPROGRAMS distclean-binPROGRAMS clean-binPROGRAMS \ +maintainer-clean-binPROGRAMS uninstall-binPROGRAMS install-binPROGRAMS \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile mostlyclean-libtool distclean-libtool \ +clean-libtool maintainer-clean-libtool tags mostlyclean-tags \ +distclean-tags clean-tags maintainer-clean-tags distdir \ +mostlyclean-depend distclean-depend clean-depend \ +maintainer-clean-depend info dvi installcheck install-exec install-data \ +install uninstall all installdirs mostlyclean-generic distclean-generic \ +clean-generic maintainer-clean-generic clean mostlyclean distclean \ +maintainer-clean + + +INCLUDES += -I../../Simulator + +#--------------------------------------------------------------------------- +# $Log$ +# Revision 1.1 1998/04/08 22:54:57 curt +# Adopted Gnu automake/autoconf system. +# +# Revision 1.2 1998/01/21 02:55:46 curt +# Incorporated new make system from Bob Kuehne . +# +# Revision 1.1 1998/01/15 02:45:25 curt +# Initial revision. +# + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/AssemTris/assemtris.c b/AssemTris/assemtris.c index ab53c1a1c..835dc756e 100644 --- a/AssemTris/assemtris.c +++ b/AssemTris/assemtris.c @@ -33,10 +33,10 @@ #include #include -#include -#include -#include -#include +// #include +// #include +// #include +#include int nodecount = 0; @@ -454,9 +454,12 @@ int main(int argc, char **argv) { /* $Log$ -/* Revision 1.5 1998/03/03 16:00:52 curt -/* More c++ compile tweaks. +/* Revision 1.6 1998/04/08 22:54:58 curt +/* Adopted Gnu automake/autoconf system. /* + * Revision 1.5 1998/03/03 16:00:52 curt + * More c++ compile tweaks. + * * Revision 1.4 1998/01/31 00:41:23 curt * Made a few changes converting floats to doubles. * diff --git a/DEM/Makefile b/DEM/Makefile deleted file mode 100644 index fe04f0e9b..000000000 --- a/DEM/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -#--------------------------------------------------------------------------- -# Makefile -# -# Written by Curtis Olson, started March 1998. -# -# Copyright (C) 1997 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) -#--------------------------------------------------------------------------- - - -ARLIBRARY = libDEM.a -TARGETS = $(ARLIBRARY) - -CFILES = dem.c leastsqs.c -CXXFILES = - -LDIRT = $(FG_ROOT_LIB)/$(ARLIBRARY) - -include $(FG_ROOT_SRC)/commondefs - -include $(COMMONRULES) - - -#--------------------------------------------------------------------------- -# $Log$ -# Revision 1.1 1998/03/19 02:54:46 curt -# Reorganized into a class lib called fgDEM. -# - diff --git a/DEM/Makefile.am b/DEM/Makefile.am new file mode 100644 index 000000000..d24cc6b35 --- /dev/null +++ b/DEM/Makefile.am @@ -0,0 +1,8 @@ +libdir = ${exec_prefix}/lib + +lib_LTLIBRARIES = libDEM.la + +libDEM_la_SOURCES = dem.cxx dem.hxx leastsqs.cxx leastsqs.hxx + +INCLUDES += -I../../Simulator + diff --git a/DEM/Makefile.in b/DEM/Makefile.in new file mode 100644 index 000000000..81e385ab9 --- /dev/null +++ b/DEM/Makefile.in @@ -0,0 +1,335 @@ +# Makefile.in generated automatically by automake 1.2h from Makefile.am + +# Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = /bin/sh + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DISTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +CC = @CC@ +CXX = @CXX@ +LD = @LD@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +NM = @NM@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +VERSION = @VERSION@ + +libdir = ${exec_prefix}/lib + +lib_LTLIBRARIES = libDEM.la + +libDEM_la_SOURCES = dem.cxx dem.hxx leastsqs.cxx leastsqs.hxx +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../Simulator/Include/config.h +CONFIG_CLEAN_FILES = +LTLIBRARIES = $(lib_LTLIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) -I../../Simulator/Include +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +X_CFLAGS = @X_CFLAGS@ +X_LIBS = @X_LIBS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +libDEM_la_LDFLAGS = +libDEM_la_LIBADD = +libDEM_la_OBJECTS = dem.lo leastsqs.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 $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = tar +GZIP = --best +DEP_FILES = .deps/dem.P .deps/leastsqs.P +CXXMKDEP = $(CXX) -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS) +SOURCES = $(libDEM_la_SOURCES) +OBJECTS = $(libDEM_la_OBJECTS) + +all: Makefile $(LTLIBRARIES) + +.SUFFIXES: +.SUFFIXES: .S .c .cxx .lo .o .s +$(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu Tools/DEM/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-libLTLIBRARIES: + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + +distclean-libLTLIBRARIES: + +maintainer-clean-libLTLIBRARIES: + +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(libdir) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + echo "$(LIBTOOL) --mode=install $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$p"; \ + $(LIBTOOL) --mode=install $(INSTALL_DATA) $$p $(DESTDIR)$(libdir)/$$p; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \ + done + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +libDEM.la: $(libDEM_la_OBJECTS) $(libDEM_la_DEPENDENCIES) + $(CXXLINK) -rpath $(libdir) $(libDEM_la_LDFLAGS) $(libDEM_la_OBJECTS) $(libDEM_la_LIBADD) $(LIBS) +.cxx.o: + $(CXXCOMPILE) -c $< +.cxx.lo: + $(LTCXXCOMPILE) -c $< + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $(SOURCES) $(HEADERS) $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = Tools/DEM + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu Tools/DEM/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + +maintainer-clean-depend: + -rm -rf .deps + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).P -c $< + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -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 + +%.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 + $(MAKE) +installcheck: +install-exec: install-libLTLIBRARIES + @$(NORMAL_INSTALL) + +install-data: + @$(NORMAL_INSTALL) + +install: install-exec install-data all + @: + +uninstall: uninstall-libLTLIBRARIES + +install-strip: + $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' INSTALL_SCRIPT='$(INSTALL_PROGRAM)' install +installdirs: + $(mkinstalldirs) $(DATADIR)$(libdir) + + +mostlyclean-generic: + -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f Makefile $(DISTCLEANFILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +mostlyclean: mostlyclean-libLTLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ + mostlyclean-generic + +clean: clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \ + clean-depend clean-generic mostlyclean + +distclean: distclean-libLTLIBRARIES distclean-compile distclean-libtool \ + distclean-tags distclean-depend distclean-generic clean + -rm -f config.status + -rm -f libtool + +maintainer-clean: maintainer-clean-libLTLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-tags maintainer-clean-depend \ + maintainer-clean-generic distclean + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \ +clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \ +uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \ +distclean-compile clean-compile maintainer-clean-compile \ +mostlyclean-libtool distclean-libtool clean-libtool \ +maintainer-clean-libtool tags mostlyclean-tags distclean-tags \ +clean-tags maintainer-clean-tags distdir mostlyclean-depend \ +distclean-depend clean-depend maintainer-clean-depend info dvi \ +installcheck install-exec install-data install uninstall all \ +installdirs mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +INCLUDES += -I../../Simulator + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/DEM/dem.c b/DEM/dem.c deleted file mode 100644 index 0dc3aa5e8..000000000 --- a/DEM/dem.c +++ /dev/null @@ -1,779 +0,0 @@ -// -*- Mode: C++ -*- -// -// dem.c -- DEM management class -// -// Written by Curtis Olson, started March 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 // isspace() -#include // rint() -#include -#include // atoi() -#include -#include // stat() -#include // stat() - -#include "dem.h" -#include "leastsqs.h" - -#include - - -#ifdef WIN32 -# define MKDIR(a) mkdir(a,S_IRWXU) // I am just guessing at this flag (NHV) -#endif // WIN32 - - -fgDEM::fgDEM( void ) { - // printf("class fgDEM CONstructor called.\n"); -} - - -#ifdef WIN32 - -// return the file path name ( foo/bar/file.ext = foo/bar ) -void extract_path (char *in, char *base) { - int len, i; - - len = strlen (in); - strcpy (base, in); - - i = len - 1; - while ( (i >= 0) && (in[i] != '/') ) { - i--; - } - - base[i] = '\0'; -} - - -// Make a subdirectory -int my_mkdir (char *dir) { - struct stat stat_buf; - int result; - - printf ("mk_dir() "); - - result = stat (dir, &stat_buf); - - if (result != 0) { - MKDIR (dir); - result = stat (dir, &stat_buf); - if (result != 0) { - printf ("problem creating %s\n", dir); - } else { - printf ("%s created\n", dir); - } - } else { - printf ("%s already exists\n", dir); - } - - return (result); -} - -#endif // WIN32 - - -// open a DEM file -int fgDEM::open ( char *file ) { - // open input file (or read from stdin) - if ( strcmp(file, "-") == 0 ) { - printf("Loading DEM data file: stdin\n"); - fd = stdin; - } else { - if ( (fd = fopen(file, "r")) == NULL ) { - printf("Cannot open %s\n", file); - return(0); - } - printf("Loading DEM data file: %s\n", file); - } - - return(1); -} - - -// close a DEM file -int fgDEM::close ( void ) { - fclose(fd); - - return(1); -} - - -// return next token from input stream -static void next_token(FILE *fd, char *token) { - int result; - - result = fscanf(fd, "%s", token); - - if ( result == EOF ) { - strcpy(token, "__END_OF_FILE__"); - printf(" Warning: Reached end of file!\n"); - } - - // printf(" returning %s\n", token); -} - - -// return next integer from input stream -static int next_int(FILE *fd) { - char token[80]; - - next_token(fd, token); - return ( atoi(token) ); -} - - -// return next double from input stream -static double next_double(FILE *fd) { - char token[80]; - - next_token(fd, token); - return ( atof(token) ); -} - - -// return next exponential num from input stream -static int next_exp(FILE *fd) { - double mantissa; - int exp, acc; - int i; - - fscanf(fd, "%lfD%d", &mantissa, &exp); - - // printf(" Mantissa = %.4f Exp = %d\n", mantissa, exp); - - acc = 1; - if ( exp > 0 ) { - for ( i = 1; i <= exp; i++ ) { - acc *= 10; - } - } else if ( exp < 0 ) { - for ( i = -1; i >= exp; i-- ) { - acc /= 10; - } - } - - return( (int)rint(mantissa * (double)acc) ); -} - - -// read and parse DEM "A" record -void fgDEM::read_a_record( void ) { - int i, inum; - double dnum; - char name[144]; - char token[80]; - char *ptr; - - // get the name field (144 characters) - for ( i = 0; i < 144; i++ ) { - name[i] = fgetc(fd); - } - name[i+1] = '\0'; - - // clean off the whitespace at the end - for ( i = strlen(name)-2; i > 0; i-- ) { - if ( !isspace(name[i]) ) { - i=0; - } else { - name[i] = '\0'; - } - } - printf(" Quad name field: %s\n", name); - - // DEM level code, 3 reflects processing by DMA - inum = next_int(fd); - printf(" DEM level code = %d\n", inum); - - // Pattern code, 1 indicates a regular elevation pattern - inum = next_int(fd); - printf(" Pattern code = %d\n", inum); - - // Planimetric reference system code, 0 indicates geographic - // coordinate system. - inum = next_int(fd); - printf(" Planimetric reference code = %d\n", inum); - - // Zone code - inum = next_int(fd); - printf(" Zone code = %d\n", inum); - - // Map projection parameters (ignored) - for ( i = 0; i < 15; i++ ) { - dnum = next_double(fd); - // printf("%d: %f\n",i,dnum); - } - - // Units code, 3 represents arc-seconds as the unit of measure for - // ground planimetric coordinates throughout the file. - inum = next_int(fd); - if ( inum != 3 ) { - printf(" Unknown (X,Y) units code = %d!\n", inum); - exit(-1); - } - - // Units code; 2 represents meters as the unit of measure for - // elevation coordinates throughout the file. - inum = next_int(fd); - if ( inum != 2 ) { - printf(" Unknown (Z) units code = %d!\n", inum); - exit(-1); - } - - // Number (n) of sides in the polygon which defines the coverage of - // the DEM file (usually equal to 4). - inum = next_int(fd); - if ( inum != 4 ) { - printf(" Unknown polygon dimension = %d!\n", inum); - exit(-1); - } - - // Ground coordinates of bounding box in arc-seconds - dem_x1 = originx = next_exp(fd); - dem_y1 = originy = next_exp(fd); - printf(" Origin = (%.2f,%.2f)\n", originx, originy); - - dem_x2 = next_exp(fd); - dem_y2 = next_exp(fd); - - dem_x3 = next_exp(fd); - dem_y3 = next_exp(fd); - - dem_x4 = next_exp(fd); - dem_y4 = next_exp(fd); - - // Minimum/maximum elevations in meters - dem_z1 = next_exp(fd); - dem_z2 = next_exp(fd); - printf(" Elevation range %.4f %.4f\n", dem_z1, dem_z2); - - // Counterclockwise angle from the primary axis of ground - // planimetric referenced to the primary axis of the DEM local - // reference system. - next_token(fd, token); - - // Accuracy code; 0 indicates that a record of accuracy does not - // exist and that no record type C will follow. - - // DEM spacial resolution. Usually (3,3,1) (3,6,1) or (3,9,1) - // depending on latitude - - // I will eventually have to do something with this for data at - // higher latitudes */ - next_token(fd, token); - printf(" accuracy & spacial resolution string = %s\n", token); - i = strlen(token); - printf(" length = %d\n", i); - - ptr = token + i - 12; - printf(" last field = %s = %.2f\n", ptr, atof(ptr)); - ptr[0] = '\0'; - - ptr = ptr - 12; - col_step = atof(ptr); - printf(" last field = %s = %.2f\n", ptr, col_step); - ptr[0] = '\0'; - - ptr = ptr - 12; - row_step = atof(ptr); - printf(" last field = %s = %.2f\n", ptr, row_step); - ptr[0] = '\0'; - - // accuracy code = atod(token) - inum = atoi(token); - printf(" Accuracy code = %d\n", inum); - - printf(" column step = %.2f row step = %.2f\n", - col_step, row_step); - // dimension of arrays to follow (1) - next_token(fd, token); - - // number of profiles - dem_num_profiles = cols = next_int(fd); - printf(" Expecting %d profiles\n", dem_num_profiles); -} - - -// read and parse DEM "B" record -void fgDEM::read_b_record(float dem_data[DEM_SIZE_1][DEM_SIZE_1]) -{ - char token[80]; - int i; - - // row / column id of this profile - prof_row = next_int(fd); - prof_col = next_int(fd); - // printf("col id = %d row id = %d\n", prof_col, prof_row); - - // Number of columns and rows (elevations) in this profile - prof_num_rows = rows = next_int(fd); - prof_num_cols = next_int(fd); - // printf(" profile num rows = %d\n", prof_num_rows); - - // Ground planimetric coordinates (arc-seconds) of the first - // elevation in the profile - prof_x1 = next_exp(fd); - prof_y1 = next_exp(fd); - // printf(" Starting at %.2f %.2f\n", prof_x1, prof_y1); - - // Elevation of local datum for the profile. Always zero for - // 1-degree DEM, the reference is mean sea level. - next_token(fd, token); - - // Minimum and maximum elevations for the profile. - next_token(fd, token); - next_token(fd, token); - - // One (usually) dimensional array (prof_num_cols,1) of elevations - for ( i = 0; i < prof_num_rows; i++ ) { - prof_data = next_int(fd); - dem_data[cur_col][i] = (float)prof_data; - } -} - - -// parse dem file -int fgDEM::parse( float dem_data[DEM_SIZE_1][DEM_SIZE_1] ) { - int i; - - cur_row = 0; - - read_a_record(); - - for ( i = 0; i < dem_num_profiles; i++ ) { - read_b_record( dem_data ); - cur_col++; - - if ( cur_col % 100 == 0 ) { - printf(" loaded %d profiles of data\n", cur_col); - } - } - - printf(" Done parsing\n"); - - return(0); -} - - -// return the current altitude based on mesh data. We should rewrite -// this to interpolate exact values, but for now this is good enough -double fgDEM::interpolate_altitude( float dem_data[DEM_SIZE_1][DEM_SIZE_1], - double lon, double lat) -{ - // we expect incoming (lon,lat) to be in arcsec for now - - double xlocal, ylocal, dx, dy, zA, zB, elev; - int x1, x2, x3, y1, y2, y3; - float z1, z2, z3; - int xindex, yindex; - - /* determine if we are in the lower triangle or the upper triangle - ______ - | /| - | / | - | / | - |/ | - ------ - - then calculate our end points - */ - - xlocal = (lon - originx) / col_step; - ylocal = (lat - originy) / row_step; - - xindex = (int)(xlocal); - yindex = (int)(ylocal); - - // printf("xindex = %d yindex = %d\n", xindex, yindex); - - if ( xindex + 1 == cols ) { - xindex--; - } - - if ( yindex + 1 == rows ) { - yindex--; - } - - if ( (xindex < 0) || (xindex + 1 >= cols) || - (yindex < 0) || (yindex + 1 >= rows) ) { - return(-9999); - } - - dx = xlocal - xindex; - dy = ylocal - yindex; - - if ( dx > dy ) { - // lower triangle - // printf(" Lower triangle\n"); - - x1 = xindex; - y1 = yindex; - z1 = dem_data[x1][y1]; - - x2 = xindex + 1; - y2 = yindex; - z2 = dem_data[x2][y2]; - - x3 = xindex + 1; - y3 = yindex + 1; - z3 = dem_data[x3][y3]; - - // printf(" dx = %.2f dy = %.2f\n", dx, dy); - // printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1); - // printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2); - // printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); - - zA = dx * (z2 - z1) + z1; - zB = dx * (z3 - z1) + z1; - - // printf(" zA = %.2f zB = %.2f\n", zA, zB); - - if ( dx > FG_EPSILON ) { - elev = dy * (zB - zA) / dx + zA; - } else { - elev = zA; - } - } else { - // upper triangle - // printf(" Upper triangle\n"); - - x1 = xindex; - y1 = yindex; - z1 = dem_data[x1][y1]; - - x2 = xindex; - y2 = yindex + 1; - z2 = dem_data[x2][y2]; - - x3 = xindex + 1; - y3 = yindex + 1; - z3 = dem_data[x3][y3]; - - // printf(" dx = %.2f dy = %.2f\n", dx, dy); - // printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1); - // printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2); - // printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); - - zA = dy * (z2 - z1) + z1; - zB = dy * (z3 - z1) + z1; - - // printf(" zA = %.2f zB = %.2f\n", zA, zB ); - // printf(" xB - xA = %.2f\n", col_step * dy / row_step); - - if ( dy > FG_EPSILON ) { - elev = dx * (zB - zA) / dy + zA; - } else { - elev = zA; - } - } - - return(elev); -} - - -// Use least squares to fit a simpler data set to dem data -void fgDEM::fit( float dem_data[DEM_SIZE_1][DEM_SIZE_1], - float output_data[DEM_SIZE_1][DEM_SIZE_1], - char *fg_root, double error, struct fgBUCKET *p ) -{ - double x[DEM_SIZE_1], y[DEM_SIZE_1]; - double m, b, ave_error, max_error; - double cury, lasty; - int n, row, start, end, good_fit; - int colmin, colmax, rowmin, rowmax; - // FILE *dem, *fit, *fit1; - - printf("Initializing output mesh structure\n"); - outputmesh_init( output_data ); - - // determine dimensions - colmin = p->x * ( (cols - 1) / 8); - colmax = colmin + ( (cols - 1) / 8); - rowmin = p->y * ( (rows - 1) / 8); - rowmax = rowmin + ( (rows - 1) / 8); - printf("Fitting region = %d,%d to %d,%d\n", colmin, rowmin, colmax, rowmax); - - // include the corners explicitly - outputmesh_set_pt(output_data, colmin, rowmin, dem_data[colmin][rowmin]); - outputmesh_set_pt(output_data, colmin, rowmax, dem_data[colmin][rowmax]); - outputmesh_set_pt(output_data, colmax, rowmax, dem_data[colmax][rowmax]); - outputmesh_set_pt(output_data, colmax, rowmin, dem_data[colmax][rowmin]); - - printf("Beginning best fit procedure\n"); - - for ( row = rowmin; row <= rowmax; row++ ) { - // fit = fopen("fit.dat", "w"); - // fit1 = fopen("fit1.dat", "w"); - - start = colmin; - - // printf(" fitting row = %d\n", row); - - while ( start < colmax ) { - end = start + 1; - good_fit = 1; - - x[(end - start) - 1] = 0.0 + ( start * col_step ); - y[(end - start) - 1] = dem_data[start][row]; - - while ( (end <= colmax) && good_fit ) { - n = (end - start) + 1; - // printf("Least square of first %d points\n", n); - x[end - start] = 0.0 + ( end * col_step ); - y[end - start] = dem_data[end][row]; - least_squares(x, y, n, &m, &b); - ave_error = least_squares_error(x, y, n, m, b); - max_error = least_squares_max_error(x, y, n, m, b); - - /* - printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n", - start, end, ave_error, max_error, m, b); - - f = fopen("gnuplot.dat", "w"); - for ( j = 0; j <= end; j++) { - fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ), - dem_data[row][j]); - } - for ( j = start; j <= end; j++) { - fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ), - dem_data[row][j]); - } - fclose(f); - - printf("Please hit return: "); gets(junk); - */ - - if ( max_error > error ) { - good_fit = 0; - } - - end++; - } - - if ( !good_fit ) { - // error exceeded the threshold, back up - end -= 2; // back "end" up to the last good enough fit - n--; // back "n" up appropriately too - } else { - // we popped out of the above loop while still within - // the error threshold, so we must be at the end of - // the data set - end--; - } - - least_squares(x, y, n, &m, &b); - ave_error = least_squares_error(x, y, n, m, b); - max_error = least_squares_max_error(x, y, n, m, b); - - /* - printf("\n"); - printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n", - start, end, ave_error, max_error, m, b); - printf("\n"); - - fprintf(fit1, "%.2f %.2f\n", x[0], m * x[0] + b); - fprintf(fit1, "%.2f %.2f\n", x[end-start], m * x[end-start] + b); - */ - - if ( start > colmin ) { - // skip this for the first line segment - cury = m * x[0] + b; - outputmesh_set_pt(output_data, start, row, (lasty + cury) / 2); - // fprintf(fit, "%.2f %.2f\n", x[0], (lasty + cury) / 2); - } - - lasty = m * x[end-start] + b; - start = end; - } - - /* - fclose(fit); - fclose(fit1); - - dem = fopen("gnuplot.dat", "w"); - for ( j = 0; j < DEM_SIZE_1; j++) { - fprintf(dem, "%.2f %.2f\n", 0.0 + ( j * col_step ), - dem_data[j][row]); - } - fclose(dem); - */ - - // NOTICE, this is for testing only. This instance of - // output_nodes should be removed. It should be called only - // once at the end once all the nodes have been generated. - // newmesh_output_nodes(&nm, "mesh.node"); - // printf("Please hit return: "); gets(junk); - } - - outputmesh_output_nodes(output_data, fg_root, p); -} - - -// Initialize output mesh structure -void fgDEM::outputmesh_init( float output_data[DEM_SIZE_1][DEM_SIZE_1] ) { - int i, j; - - for ( j = 0; j < DEM_SIZE_1; j++ ) { - for ( i = 0; i < DEM_SIZE_1; i++ ) { - output_data[i][j] = -9999.0; - } - } -} - - -// Get the value of a mesh node -double fgDEM::outputmesh_get_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], - int i, int j ) -{ - return ( output_data[i][j] ); -} - - -// Set the value of a mesh node -void fgDEM::outputmesh_set_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], - int i, int j, double value ) -{ - // printf("Setting data[%d][%d] = %.2f\n", i, j, value); - output_data[i][j] = value; -} - - -// Write out a node file that can be used by the "triangle" program -void fgDEM::outputmesh_output_nodes( float output_data[DEM_SIZE_1][DEM_SIZE_1], - char *fg_root, struct fgBUCKET *p ) -{ - struct stat stat_buf; - char base_path[256], dir[256], file[256]; -#ifdef WIN32 - char tmp_path[256]; -#endif - char command[256]; - FILE *fd; - long int index; - int colmin, colmax, rowmin, rowmax; - int i, j, count, result; - - // determine dimensions - colmin = p->x * ( (cols - 1) / 8); - colmax = colmin + ( (cols - 1) / 8); - rowmin = p->y * ( (rows - 1) / 8); - rowmax = rowmin + ( (rows - 1) / 8); - printf(" dumping region = %d,%d to %d,%d\n", - colmin, rowmin, colmax, rowmax); - - // generate the base directory - fgBucketGenBasePath(p, base_path); - printf("fg_root = %s Base Path = %s\n", fg_root, base_path); - sprintf(dir, "%s/Scenery/%s", fg_root, base_path); - printf("Dir = %s\n", dir); - - // stat() directory and create if needed - result = stat(dir, &stat_buf); - if ( result != 0 ) { - printf("Stat error need to create directory\n"); - -#ifndef WIN32 - - sprintf(command, "mkdir -p %s\n", dir); - system(command); - -#else // WIN32 - - // Cygwin crashes when trying to output to node file - // explicitly making directory structure seems OK on Win95 - - extract_path (base_path, tmp_path); - - sprintf (dir, "%s/Scenery", fg_root); - if (my_mkdir (dir)) { exit (-1); } - - sprintf (dir, "%s/Scenery/%s", fg_root, tmp_path); - if (my_mkdir (dir)) { exit (-1); } - - sprintf (dir, "%s/Scenery/%s", fg_root, base_path); - if (my_mkdir (dir)) { exit (-1); } - -#endif // WIN32 - - } else { - // assume directory exists - } - - // get index and generate output file name - index = fgBucketGenIndex(p); - sprintf(file, "%s/%ld.node", dir, index); - - printf("Creating node file: %s\n", file); - fd = fopen(file, "w"); - - // first count nodes to generate header - count = 0; - for ( j = rowmin; j <= rowmax; j++ ) { - for ( i = colmin; i <= colmax; i++ ) { - if ( output_data[i][j] > -9000.0 ) { - count++; - } - } - // printf(" count = %d\n", count); - } - fprintf(fd, "%d 2 1 0\n", count); - - // now write out actual node data - count = 1; - for ( j = rowmin; j <= rowmax; j++ ) { - for ( i = colmin; i <= colmax; i++ ) { - if ( output_data[i][j] > -9000.0 ) { - fprintf(fd, "%d %.2f %.2f %.2f\n", - count++, - originx + (double)i * col_step, - originy + (double)j * row_step, - output_data[i][j]); - } - } - // printf(" count = %d\n", count); - } - - fclose(fd); -} - - -fgDEM::~fgDEM( void ) { - // printf("class fgDEM DEstructor called.\n"); -} - - -// $Log$ -// Revision 1.3 1998/04/06 21:09:41 curt -// Additional win32 support. -// Fixed a bad bug in dem file parsing that was causing the output to be -// flipped about x = y. -// -// Revision 1.2 1998/03/23 20:35:41 curt -// Updated to use FG_EPSILON -// -// Revision 1.1 1998/03/19 02:54:47 curt -// Reorganized into a class lib called fgDEM. -// -// Revision 1.1 1998/03/19 01:46:28 curt -// Initial revision. -// diff --git a/DEM/dem.cxx b/DEM/dem.cxx new file mode 100644 index 000000000..77a7c5c81 --- /dev/null +++ b/DEM/dem.cxx @@ -0,0 +1,782 @@ +// -*- Mode: C++ -*- +// +// dem.c -- DEM management class +// +// Written by Curtis Olson, started March 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 // isspace() +#include // rint() +#include +#include // atoi() +#include +#include // stat() +#include // stat() + +#include "dem.hxx" +#include "leastsqs.hxx" + +#include + + +#ifdef WIN32 +# define MKDIR(a) mkdir(a,S_IRWXU) // I am just guessing at this flag (NHV) +#endif // WIN32 + + +fgDEM::fgDEM( void ) { + // printf("class fgDEM CONstructor called.\n"); +} + + +#ifdef WIN32 + +// return the file path name ( foo/bar/file.ext = foo/bar ) +void extract_path (char *in, char *base) { + int len, i; + + len = strlen (in); + strcpy (base, in); + + i = len - 1; + while ( (i >= 0) && (in[i] != '/') ) { + i--; + } + + base[i] = '\0'; +} + + +// Make a subdirectory +int my_mkdir (char *dir) { + struct stat stat_buf; + int result; + + printf ("mk_dir() "); + + result = stat (dir, &stat_buf); + + if (result != 0) { + MKDIR (dir); + result = stat (dir, &stat_buf); + if (result != 0) { + printf ("problem creating %s\n", dir); + } else { + printf ("%s created\n", dir); + } + } else { + printf ("%s already exists\n", dir); + } + + return (result); +} + +#endif // WIN32 + + +// open a DEM file +int fgDEM::open ( char *file ) { + // open input file (or read from stdin) + if ( strcmp(file, "-") == 0 ) { + printf("Loading DEM data file: stdin\n"); + fd = stdin; + } else { + if ( (fd = fopen(file, "r")) == NULL ) { + printf("Cannot open %s\n", file); + return(0); + } + printf("Loading DEM data file: %s\n", file); + } + + return(1); +} + + +// close a DEM file +int fgDEM::close ( void ) { + fclose(fd); + + return(1); +} + + +// return next token from input stream +static void next_token(FILE *fd, char *token) { + int result; + + result = fscanf(fd, "%s", token); + + if ( result == EOF ) { + strcpy(token, "__END_OF_FILE__"); + printf(" Warning: Reached end of file!\n"); + } + + // printf(" returning %s\n", token); +} + + +// return next integer from input stream +static int next_int(FILE *fd) { + char token[80]; + + next_token(fd, token); + return ( atoi(token) ); +} + + +// return next double from input stream +static double next_double(FILE *fd) { + char token[80]; + + next_token(fd, token); + return ( atof(token) ); +} + + +// return next exponential num from input stream +static int next_exp(FILE *fd) { + double mantissa; + int exp, acc; + int i; + + fscanf(fd, "%lfD%d", &mantissa, &exp); + + // printf(" Mantissa = %.4f Exp = %d\n", mantissa, exp); + + acc = 1; + if ( exp > 0 ) { + for ( i = 1; i <= exp; i++ ) { + acc *= 10; + } + } else if ( exp < 0 ) { + for ( i = -1; i >= exp; i-- ) { + acc /= 10; + } + } + + return( (int)rint(mantissa * (double)acc) ); +} + + +// read and parse DEM "A" record +void fgDEM::read_a_record( void ) { + int i, inum; + double dnum; + char name[144]; + char token[80]; + char *ptr; + + // get the name field (144 characters) + for ( i = 0; i < 144; i++ ) { + name[i] = fgetc(fd); + } + name[i+1] = '\0'; + + // clean off the whitespace at the end + for ( i = strlen(name)-2; i > 0; i-- ) { + if ( !isspace(name[i]) ) { + i=0; + } else { + name[i] = '\0'; + } + } + printf(" Quad name field: %s\n", name); + + // DEM level code, 3 reflects processing by DMA + inum = next_int(fd); + printf(" DEM level code = %d\n", inum); + + // Pattern code, 1 indicates a regular elevation pattern + inum = next_int(fd); + printf(" Pattern code = %d\n", inum); + + // Planimetric reference system code, 0 indicates geographic + // coordinate system. + inum = next_int(fd); + printf(" Planimetric reference code = %d\n", inum); + + // Zone code + inum = next_int(fd); + printf(" Zone code = %d\n", inum); + + // Map projection parameters (ignored) + for ( i = 0; i < 15; i++ ) { + dnum = next_double(fd); + // printf("%d: %f\n",i,dnum); + } + + // Units code, 3 represents arc-seconds as the unit of measure for + // ground planimetric coordinates throughout the file. + inum = next_int(fd); + if ( inum != 3 ) { + printf(" Unknown (X,Y) units code = %d!\n", inum); + exit(-1); + } + + // Units code; 2 represents meters as the unit of measure for + // elevation coordinates throughout the file. + inum = next_int(fd); + if ( inum != 2 ) { + printf(" Unknown (Z) units code = %d!\n", inum); + exit(-1); + } + + // Number (n) of sides in the polygon which defines the coverage of + // the DEM file (usually equal to 4). + inum = next_int(fd); + if ( inum != 4 ) { + printf(" Unknown polygon dimension = %d!\n", inum); + exit(-1); + } + + // Ground coordinates of bounding box in arc-seconds + dem_x1 = originx = next_exp(fd); + dem_y1 = originy = next_exp(fd); + printf(" Origin = (%.2f,%.2f)\n", originx, originy); + + dem_x2 = next_exp(fd); + dem_y2 = next_exp(fd); + + dem_x3 = next_exp(fd); + dem_y3 = next_exp(fd); + + dem_x4 = next_exp(fd); + dem_y4 = next_exp(fd); + + // Minimum/maximum elevations in meters + dem_z1 = next_exp(fd); + dem_z2 = next_exp(fd); + printf(" Elevation range %.4f %.4f\n", dem_z1, dem_z2); + + // Counterclockwise angle from the primary axis of ground + // planimetric referenced to the primary axis of the DEM local + // reference system. + next_token(fd, token); + + // Accuracy code; 0 indicates that a record of accuracy does not + // exist and that no record type C will follow. + + // DEM spacial resolution. Usually (3,3,1) (3,6,1) or (3,9,1) + // depending on latitude + + // I will eventually have to do something with this for data at + // higher latitudes */ + next_token(fd, token); + printf(" accuracy & spacial resolution string = %s\n", token); + i = strlen(token); + printf(" length = %d\n", i); + + ptr = token + i - 12; + printf(" last field = %s = %.2f\n", ptr, atof(ptr)); + ptr[0] = '\0'; + + ptr = ptr - 12; + col_step = atof(ptr); + printf(" last field = %s = %.2f\n", ptr, col_step); + ptr[0] = '\0'; + + ptr = ptr - 12; + row_step = atof(ptr); + printf(" last field = %s = %.2f\n", ptr, row_step); + ptr[0] = '\0'; + + // accuracy code = atod(token) + inum = atoi(token); + printf(" Accuracy code = %d\n", inum); + + printf(" column step = %.2f row step = %.2f\n", + col_step, row_step); + // dimension of arrays to follow (1) + next_token(fd, token); + + // number of profiles + dem_num_profiles = cols = next_int(fd); + printf(" Expecting %d profiles\n", dem_num_profiles); +} + + +// read and parse DEM "B" record +void fgDEM::read_b_record(float dem_data[DEM_SIZE_1][DEM_SIZE_1]) +{ + char token[80]; + int i; + + // row / column id of this profile + prof_row = next_int(fd); + prof_col = next_int(fd); + // printf("col id = %d row id = %d\n", prof_col, prof_row); + + // Number of columns and rows (elevations) in this profile + prof_num_rows = rows = next_int(fd); + prof_num_cols = next_int(fd); + // printf(" profile num rows = %d\n", prof_num_rows); + + // Ground planimetric coordinates (arc-seconds) of the first + // elevation in the profile + prof_x1 = next_exp(fd); + prof_y1 = next_exp(fd); + // printf(" Starting at %.2f %.2f\n", prof_x1, prof_y1); + + // Elevation of local datum for the profile. Always zero for + // 1-degree DEM, the reference is mean sea level. + next_token(fd, token); + + // Minimum and maximum elevations for the profile. + next_token(fd, token); + next_token(fd, token); + + // One (usually) dimensional array (prof_num_cols,1) of elevations + for ( i = 0; i < prof_num_rows; i++ ) { + prof_data = next_int(fd); + dem_data[cur_col][i] = (float)prof_data; + } +} + + +// parse dem file +int fgDEM::parse( float dem_data[DEM_SIZE_1][DEM_SIZE_1] ) { + int i; + + cur_row = 0; + + read_a_record(); + + for ( i = 0; i < dem_num_profiles; i++ ) { + read_b_record( dem_data ); + cur_col++; + + if ( cur_col % 100 == 0 ) { + printf(" loaded %d profiles of data\n", cur_col); + } + } + + printf(" Done parsing\n"); + + return(0); +} + + +// return the current altitude based on mesh data. We should rewrite +// this to interpolate exact values, but for now this is good enough +double fgDEM::interpolate_altitude( float dem_data[DEM_SIZE_1][DEM_SIZE_1], + double lon, double lat) +{ + // we expect incoming (lon,lat) to be in arcsec for now + + double xlocal, ylocal, dx, dy, zA, zB, elev; + int x1, x2, x3, y1, y2, y3; + float z1, z2, z3; + int xindex, yindex; + + /* determine if we are in the lower triangle or the upper triangle + ______ + | /| + | / | + | / | + |/ | + ------ + + then calculate our end points + */ + + xlocal = (lon - originx) / col_step; + ylocal = (lat - originy) / row_step; + + xindex = (int)(xlocal); + yindex = (int)(ylocal); + + // printf("xindex = %d yindex = %d\n", xindex, yindex); + + if ( xindex + 1 == cols ) { + xindex--; + } + + if ( yindex + 1 == rows ) { + yindex--; + } + + if ( (xindex < 0) || (xindex + 1 >= cols) || + (yindex < 0) || (yindex + 1 >= rows) ) { + return(-9999); + } + + dx = xlocal - xindex; + dy = ylocal - yindex; + + if ( dx > dy ) { + // lower triangle + // printf(" Lower triangle\n"); + + x1 = xindex; + y1 = yindex; + z1 = dem_data[x1][y1]; + + x2 = xindex + 1; + y2 = yindex; + z2 = dem_data[x2][y2]; + + x3 = xindex + 1; + y3 = yindex + 1; + z3 = dem_data[x3][y3]; + + // printf(" dx = %.2f dy = %.2f\n", dx, dy); + // printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1); + // printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2); + // printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); + + zA = dx * (z2 - z1) + z1; + zB = dx * (z3 - z1) + z1; + + // printf(" zA = %.2f zB = %.2f\n", zA, zB); + + if ( dx > FG_EPSILON ) { + elev = dy * (zB - zA) / dx + zA; + } else { + elev = zA; + } + } else { + // upper triangle + // printf(" Upper triangle\n"); + + x1 = xindex; + y1 = yindex; + z1 = dem_data[x1][y1]; + + x2 = xindex; + y2 = yindex + 1; + z2 = dem_data[x2][y2]; + + x3 = xindex + 1; + y3 = yindex + 1; + z3 = dem_data[x3][y3]; + + // printf(" dx = %.2f dy = %.2f\n", dx, dy); + // printf(" (x1,y1,z1) = (%d,%d,%d)\n", x1, y1, z1); + // printf(" (x2,y2,z2) = (%d,%d,%d)\n", x2, y2, z2); + // printf(" (x3,y3,z3) = (%d,%d,%d)\n", x3, y3, z3); + + zA = dy * (z2 - z1) + z1; + zB = dy * (z3 - z1) + z1; + + // printf(" zA = %.2f zB = %.2f\n", zA, zB ); + // printf(" xB - xA = %.2f\n", col_step * dy / row_step); + + if ( dy > FG_EPSILON ) { + elev = dx * (zB - zA) / dy + zA; + } else { + elev = zA; + } + } + + return(elev); +} + + +// Use least squares to fit a simpler data set to dem data +void fgDEM::fit( float dem_data[DEM_SIZE_1][DEM_SIZE_1], + float output_data[DEM_SIZE_1][DEM_SIZE_1], + char *fg_root, double error, struct fgBUCKET *p ) +{ + double x[DEM_SIZE_1], y[DEM_SIZE_1]; + double m, b, ave_error, max_error; + double cury, lasty; + int n, row, start, end, good_fit; + int colmin, colmax, rowmin, rowmax; + // FILE *dem, *fit, *fit1; + + printf("Initializing output mesh structure\n"); + outputmesh_init( output_data ); + + // determine dimensions + colmin = p->x * ( (cols - 1) / 8); + colmax = colmin + ( (cols - 1) / 8); + rowmin = p->y * ( (rows - 1) / 8); + rowmax = rowmin + ( (rows - 1) / 8); + printf("Fitting region = %d,%d to %d,%d\n", colmin, rowmin, colmax, rowmax); + + // include the corners explicitly + outputmesh_set_pt(output_data, colmin, rowmin, dem_data[colmin][rowmin]); + outputmesh_set_pt(output_data, colmin, rowmax, dem_data[colmin][rowmax]); + outputmesh_set_pt(output_data, colmax, rowmax, dem_data[colmax][rowmax]); + outputmesh_set_pt(output_data, colmax, rowmin, dem_data[colmax][rowmin]); + + printf("Beginning best fit procedure\n"); + + for ( row = rowmin; row <= rowmax; row++ ) { + // fit = fopen("fit.dat", "w"); + // fit1 = fopen("fit1.dat", "w"); + + start = colmin; + + // printf(" fitting row = %d\n", row); + + while ( start < colmax ) { + end = start + 1; + good_fit = 1; + + x[(end - start) - 1] = 0.0 + ( start * col_step ); + y[(end - start) - 1] = dem_data[start][row]; + + while ( (end <= colmax) && good_fit ) { + n = (end - start) + 1; + // printf("Least square of first %d points\n", n); + x[end - start] = 0.0 + ( end * col_step ); + y[end - start] = dem_data[end][row]; + least_squares(x, y, n, &m, &b); + ave_error = least_squares_error(x, y, n, m, b); + max_error = least_squares_max_error(x, y, n, m, b); + + /* + printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n", + start, end, ave_error, max_error, m, b); + + f = fopen("gnuplot.dat", "w"); + for ( j = 0; j <= end; j++) { + fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ), + dem_data[row][j]); + } + for ( j = start; j <= end; j++) { + fprintf(f, "%.2f %.2f\n", 0.0 + ( j * col_step ), + dem_data[row][j]); + } + fclose(f); + + printf("Please hit return: "); gets(junk); + */ + + if ( max_error > error ) { + good_fit = 0; + } + + end++; + } + + if ( !good_fit ) { + // error exceeded the threshold, back up + end -= 2; // back "end" up to the last good enough fit + n--; // back "n" up appropriately too + } else { + // we popped out of the above loop while still within + // the error threshold, so we must be at the end of + // the data set + end--; + } + + least_squares(x, y, n, &m, &b); + ave_error = least_squares_error(x, y, n, m, b); + max_error = least_squares_max_error(x, y, n, m, b); + + /* + printf("\n"); + printf("%d - %d ave error = %.2f max error = %.2f y = %.2f*x + %.2f\n", + start, end, ave_error, max_error, m, b); + printf("\n"); + + fprintf(fit1, "%.2f %.2f\n", x[0], m * x[0] + b); + fprintf(fit1, "%.2f %.2f\n", x[end-start], m * x[end-start] + b); + */ + + if ( start > colmin ) { + // skip this for the first line segment + cury = m * x[0] + b; + outputmesh_set_pt(output_data, start, row, (lasty + cury) / 2); + // fprintf(fit, "%.2f %.2f\n", x[0], (lasty + cury) / 2); + } + + lasty = m * x[end-start] + b; + start = end; + } + + /* + fclose(fit); + fclose(fit1); + + dem = fopen("gnuplot.dat", "w"); + for ( j = 0; j < DEM_SIZE_1; j++) { + fprintf(dem, "%.2f %.2f\n", 0.0 + ( j * col_step ), + dem_data[j][row]); + } + fclose(dem); + */ + + // NOTICE, this is for testing only. This instance of + // output_nodes should be removed. It should be called only + // once at the end once all the nodes have been generated. + // newmesh_output_nodes(&nm, "mesh.node"); + // printf("Please hit return: "); gets(junk); + } + + outputmesh_output_nodes(output_data, fg_root, p); +} + + +// Initialize output mesh structure +void fgDEM::outputmesh_init( float output_data[DEM_SIZE_1][DEM_SIZE_1] ) { + int i, j; + + for ( j = 0; j < DEM_SIZE_1; j++ ) { + for ( i = 0; i < DEM_SIZE_1; i++ ) { + output_data[i][j] = -9999.0; + } + } +} + + +// Get the value of a mesh node +double fgDEM::outputmesh_get_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], + int i, int j ) +{ + return ( output_data[i][j] ); +} + + +// Set the value of a mesh node +void fgDEM::outputmesh_set_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], + int i, int j, double value ) +{ + // printf("Setting data[%d][%d] = %.2f\n", i, j, value); + output_data[i][j] = value; +} + + +// Write out a node file that can be used by the "triangle" program +void fgDEM::outputmesh_output_nodes( float output_data[DEM_SIZE_1][DEM_SIZE_1], + char *fg_root, struct fgBUCKET *p ) +{ + struct stat stat_buf; + char base_path[256], dir[256], file[256]; +#ifdef WIN32 + char tmp_path[256]; +#endif + char command[256]; + FILE *fd; + long int index; + int colmin, colmax, rowmin, rowmax; + int i, j, count, result; + + // determine dimensions + colmin = p->x * ( (cols - 1) / 8); + colmax = colmin + ( (cols - 1) / 8); + rowmin = p->y * ( (rows - 1) / 8); + rowmax = rowmin + ( (rows - 1) / 8); + printf(" dumping region = %d,%d to %d,%d\n", + colmin, rowmin, colmax, rowmax); + + // generate the base directory + fgBucketGenBasePath(p, base_path); + printf("fg_root = %s Base Path = %s\n", fg_root, base_path); + sprintf(dir, "%s/Scenery/%s", fg_root, base_path); + printf("Dir = %s\n", dir); + + // stat() directory and create if needed + result = stat(dir, &stat_buf); + if ( result != 0 ) { + printf("Stat error need to create directory\n"); + +#ifndef WIN32 + + sprintf(command, "mkdir -p %s\n", dir); + system(command); + +#else // WIN32 + + // Cygwin crashes when trying to output to node file + // explicitly making directory structure seems OK on Win95 + + extract_path (base_path, tmp_path); + + sprintf (dir, "%s/Scenery", fg_root); + if (my_mkdir (dir)) { exit (-1); } + + sprintf (dir, "%s/Scenery/%s", fg_root, tmp_path); + if (my_mkdir (dir)) { exit (-1); } + + sprintf (dir, "%s/Scenery/%s", fg_root, base_path); + if (my_mkdir (dir)) { exit (-1); } + +#endif // WIN32 + + } else { + // assume directory exists + } + + // get index and generate output file name + index = fgBucketGenIndex(p); + sprintf(file, "%s/%ld.node", dir, index); + + printf("Creating node file: %s\n", file); + fd = fopen(file, "w"); + + // first count nodes to generate header + count = 0; + for ( j = rowmin; j <= rowmax; j++ ) { + for ( i = colmin; i <= colmax; i++ ) { + if ( output_data[i][j] > -9000.0 ) { + count++; + } + } + // printf(" count = %d\n", count); + } + fprintf(fd, "%d 2 1 0\n", count); + + // now write out actual node data + count = 1; + for ( j = rowmin; j <= rowmax; j++ ) { + for ( i = colmin; i <= colmax; i++ ) { + if ( output_data[i][j] > -9000.0 ) { + fprintf(fd, "%d %.2f %.2f %.2f\n", + count++, + originx + (double)i * col_step, + originy + (double)j * row_step, + output_data[i][j]); + } + } + // printf(" count = %d\n", count); + } + + fclose(fd); +} + + +fgDEM::~fgDEM( void ) { + // printf("class fgDEM DEstructor called.\n"); +} + + +// $Log$ +// Revision 1.1 1998/04/08 22:57:22 curt +// Adopted Gnu automake/autoconf system. +// +// Revision 1.3 1998/04/06 21:09:41 curt +// Additional win32 support. +// Fixed a bad bug in dem file parsing that was causing the output to be +// flipped about x = y. +// +// Revision 1.2 1998/03/23 20:35:41 curt +// Updated to use FG_EPSILON +// +// Revision 1.1 1998/03/19 02:54:47 curt +// Reorganized into a class lib called fgDEM. +// +// Revision 1.1 1998/03/19 01:46:28 curt +// Initial revision. +// diff --git a/DEM/dem.h b/DEM/dem.h deleted file mode 100644 index 64f04e4b4..000000000 --- a/DEM/dem.h +++ /dev/null @@ -1,141 +0,0 @@ -// -*- Mode: C++ -*- -// -// dem.h -- DEM management class -// -// Written by Curtis Olson, started March 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 _DEM_H -#define _DEM_H - - -#include - -#include - - -#define DEM_SIZE 1200 -#define DEM_SIZE_1 1201 - - -class fgDEM { - // file pointer for input - FILE *fd; - - // coordinates (in arc seconds) of south west corner - double originx, originy; - - // number of columns and rows - int cols, rows; - - // Distance between column and row data points (in arc seconds) - double col_step, row_step; - - // the actual mesh data allocated here - // float dem_data[DEM_SIZE_1][DEM_SIZE_1]; - // float output_data[DEM_SIZE_1][DEM_SIZE_1]; - - // Current "A" Record Information - char dem_description[80], dem_quadrangle[80]; - double dem_x1, dem_y1, dem_x2, dem_y2, dem_x3, dem_y3, dem_x4, dem_y4; - double dem_z1, dem_z2; - int dem_resolution, dem_num_profiles; - - // Current "B" Record Information - int prof_col, prof_row; - int prof_num_cols, prof_num_rows; - double prof_x1, prof_y1; - int prof_data; - - // temporary values for the class to use - char option_name[32]; - int do_data; - int cur_col, cur_row; - -public: - - // Constructor (opens a DEM file) - fgDEM( void ); - - // open a DEM file (use "-" if input is coming from stdin) - int open ( char *file ); - - // close a DEM file - int close ( void ); - - // parse a DEM file - int parse( float dem_data[DEM_SIZE_1][DEM_SIZE_1] ); - - // read and parse DEM "A" record - void read_a_record( ); - - // read and parse DEM "B" record - void read_b_record( float dem_data[DEM_SIZE_1][DEM_SIZE_1] ); - - // Informational methods - double info_originx( void ) { return(originx); } - double info_originy( void ) { return(originy); } - - // return the current altitude based on mesh data. We should - // rewrite this to interpolate exact values, but for now this is - // good enough - double interpolate_altitude( float dem_data[DEM_SIZE_1][DEM_SIZE_1], - double lon, double lat); - - // Use least squares to fit a simpler data set to dem data - void fit( float dem_data[DEM_SIZE_1][DEM_SIZE_1], - float output_data[DEM_SIZE_1][DEM_SIZE_1], - char *fg_root, double error, struct fgBUCKET *p ); - - // Initialize output mesh structure - void outputmesh_init( float output_data[DEM_SIZE_1][DEM_SIZE_1] ); - - // Get the value of a mesh node - double outputmesh_get_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], - int i, int j ); - - // Set the value of a mesh node - void outputmesh_set_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], - int i, int j, double value ); - - // Write out a node file that can be used by the "triangle" program - void outputmesh_output_nodes( float output_data[DEM_SIZE_1][DEM_SIZE_1], - char *fg_root, struct fgBUCKET *p ); - - // Destructor - ~fgDEM( void ); -}; - - -#endif // _DEM_H - - -// $Log$ -// Revision 1.2 1998/03/23 20:35:42 curt -// Updated to use FG_EPSILON -// -// Revision 1.1 1998/03/19 02:54:47 curt -// Reorganized into a class lib called fgDEM. -// -// Revision 1.1 1998/03/19 01:46:29 curt -// Initial revision. -// diff --git a/DEM/dem.hxx b/DEM/dem.hxx new file mode 100644 index 000000000..a3b5f215c --- /dev/null +++ b/DEM/dem.hxx @@ -0,0 +1,144 @@ +// -*- Mode: C++ -*- +// +// dem.h -- DEM management class +// +// Written by Curtis Olson, started March 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 _DEM_H +#define _DEM_H + + +#include + +#include + + +#define DEM_SIZE 1200 +#define DEM_SIZE_1 1201 + + +class fgDEM { + // file pointer for input + FILE *fd; + + // coordinates (in arc seconds) of south west corner + double originx, originy; + + // number of columns and rows + int cols, rows; + + // Distance between column and row data points (in arc seconds) + double col_step, row_step; + + // the actual mesh data allocated here + // float dem_data[DEM_SIZE_1][DEM_SIZE_1]; + // float output_data[DEM_SIZE_1][DEM_SIZE_1]; + + // Current "A" Record Information + char dem_description[80], dem_quadrangle[80]; + double dem_x1, dem_y1, dem_x2, dem_y2, dem_x3, dem_y3, dem_x4, dem_y4; + double dem_z1, dem_z2; + int dem_resolution, dem_num_profiles; + + // Current "B" Record Information + int prof_col, prof_row; + int prof_num_cols, prof_num_rows; + double prof_x1, prof_y1; + int prof_data; + + // temporary values for the class to use + char option_name[32]; + int do_data; + int cur_col, cur_row; + +public: + + // Constructor (opens a DEM file) + fgDEM( void ); + + // open a DEM file (use "-" if input is coming from stdin) + int open ( char *file ); + + // close a DEM file + int close ( void ); + + // parse a DEM file + int parse( float dem_data[DEM_SIZE_1][DEM_SIZE_1] ); + + // read and parse DEM "A" record + void read_a_record( ); + + // read and parse DEM "B" record + void read_b_record( float dem_data[DEM_SIZE_1][DEM_SIZE_1] ); + + // Informational methods + double info_originx( void ) { return(originx); } + double info_originy( void ) { return(originy); } + + // return the current altitude based on mesh data. We should + // rewrite this to interpolate exact values, but for now this is + // good enough + double interpolate_altitude( float dem_data[DEM_SIZE_1][DEM_SIZE_1], + double lon, double lat); + + // Use least squares to fit a simpler data set to dem data + void fit( float dem_data[DEM_SIZE_1][DEM_SIZE_1], + float output_data[DEM_SIZE_1][DEM_SIZE_1], + char *fg_root, double error, struct fgBUCKET *p ); + + // Initialize output mesh structure + void outputmesh_init( float output_data[DEM_SIZE_1][DEM_SIZE_1] ); + + // Get the value of a mesh node + double outputmesh_get_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], + int i, int j ); + + // Set the value of a mesh node + void outputmesh_set_pt( float output_data[DEM_SIZE_1][DEM_SIZE_1], + int i, int j, double value ); + + // Write out a node file that can be used by the "triangle" program + void outputmesh_output_nodes( float output_data[DEM_SIZE_1][DEM_SIZE_1], + char *fg_root, struct fgBUCKET *p ); + + // Destructor + ~fgDEM( void ); +}; + + +#endif // _DEM_H + + +// $Log$ +// Revision 1.1 1998/04/08 22:57:23 curt +// Adopted Gnu automake/autoconf system. +// +// Revision 1.2 1998/03/23 20:35:42 curt +// Updated to use FG_EPSILON +// +// Revision 1.1 1998/03/19 02:54:47 curt +// Reorganized into a class lib called fgDEM. +// +// Revision 1.1 1998/03/19 01:46:29 curt +// Initial revision. +// diff --git a/DEM/leastsqs.c b/DEM/leastsqs.c deleted file mode 100644 index 1eebb0330..000000000 --- a/DEM/leastsqs.c +++ /dev/null @@ -1,121 +0,0 @@ -/* leastsqs.c -- Implements a simple linear least squares best fit routine - * - * Written by Curtis Olson, started September 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * 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 "leastsqs.h" - - -/* -Least squares fit: - -y = b0 + b1x - - n*sum(xi*yi) - (sum(xi)*sum(yi)) -b1 = -------------------------------- - n*sum(xi^2) - (sum(xi))^2 - - -b0 = sum(yi)/n - b1*(sum(xi)/n) -*/ - -void least_squares(double *x, double *y, int n, double *m, double *b) { - double sum_xi, sum_yi, sum_xi_2, sum_xi_yi; - int i; - - sum_xi = sum_yi = sum_xi_2 = sum_xi_yi = 0.0; - - for ( i = 0; i < n; i++ ) { - sum_xi += x[i]; - sum_yi += y[i]; - sum_xi_2 += x[i] * x[i]; - sum_xi_yi += x[i] * y[i]; - } - - /* printf("sum(xi)=%.2f sum(yi)=%.2f sum(xi^2)=%.2f sum(xi*yi)=%.2f\n", - sum_xi, sum_yi, sum_xi_2, sum_xi_yi); */ - - *m = ( (double)n * sum_xi_yi - sum_xi * sum_yi ) / - ( (double)n * sum_xi_2 - sum_xi * sum_xi ); - *b = (sum_yi / (double)n) - (*m) * (sum_xi / (double)n); - - /* printf("slope = %.2f intercept = %.2f\n", *m, *b); */ -} - - -/* - return the least squares error: - - (y[i] - y_hat[i])^2 - ------------------- - n - */ -double least_squares_error(double *x, double *y, int n, double m, double b) { - int i; - double error, sum; - - sum = 0.0; - - for ( i = 0; i < n; i++ ) { - error = y[i] - (m * x[i] + b); - sum += error * error; - /* printf("%.2f %.2f\n", error, sum); */ - } - - return ( sum / (double)n ); -} - - -/* - return the maximum least squares error: - - (y[i] - y_hat[i])^2 - */ -double least_squares_max_error(double *x, double *y, int n, double m, double b){ - int i; - double error, max_error; - - max_error = 0.0; - - for ( i = 0; i < n; i++ ) { - error = y[i] - (m * x[i] + b); - error = error * error; - if ( error > max_error ) { - max_error = error; - } - } - - return ( max_error ); -} - - -/* $Log$ -/* Revision 1.1 1998/03/19 02:54:47 curt -/* Reorganized into a class lib called fgDEM. -/* - * Revision 1.1 1997/10/13 17:02:35 curt - * Initial revision. - * - */ diff --git a/DEM/leastsqs.cxx b/DEM/leastsqs.cxx new file mode 100644 index 000000000..7414fa628 --- /dev/null +++ b/DEM/leastsqs.cxx @@ -0,0 +1,124 @@ +/* leastsqs.c -- Implements a simple linear least squares best fit routine + * + * Written by Curtis Olson, started September 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * 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 "leastsqs.hxx" + + +/* +Least squares fit: + +y = b0 + b1x + + n*sum(xi*yi) - (sum(xi)*sum(yi)) +b1 = -------------------------------- + n*sum(xi^2) - (sum(xi))^2 + + +b0 = sum(yi)/n - b1*(sum(xi)/n) +*/ + +void least_squares(double *x, double *y, int n, double *m, double *b) { + double sum_xi, sum_yi, sum_xi_2, sum_xi_yi; + int i; + + sum_xi = sum_yi = sum_xi_2 = sum_xi_yi = 0.0; + + for ( i = 0; i < n; i++ ) { + sum_xi += x[i]; + sum_yi += y[i]; + sum_xi_2 += x[i] * x[i]; + sum_xi_yi += x[i] * y[i]; + } + + /* printf("sum(xi)=%.2f sum(yi)=%.2f sum(xi^2)=%.2f sum(xi*yi)=%.2f\n", + sum_xi, sum_yi, sum_xi_2, sum_xi_yi); */ + + *m = ( (double)n * sum_xi_yi - sum_xi * sum_yi ) / + ( (double)n * sum_xi_2 - sum_xi * sum_xi ); + *b = (sum_yi / (double)n) - (*m) * (sum_xi / (double)n); + + /* printf("slope = %.2f intercept = %.2f\n", *m, *b); */ +} + + +/* + return the least squares error: + + (y[i] - y_hat[i])^2 + ------------------- + n + */ +double least_squares_error(double *x, double *y, int n, double m, double b) { + int i; + double error, sum; + + sum = 0.0; + + for ( i = 0; i < n; i++ ) { + error = y[i] - (m * x[i] + b); + sum += error * error; + /* printf("%.2f %.2f\n", error, sum); */ + } + + return ( sum / (double)n ); +} + + +/* + return the maximum least squares error: + + (y[i] - y_hat[i])^2 + */ +double least_squares_max_error(double *x, double *y, int n, double m, double b){ + int i; + double error, max_error; + + max_error = 0.0; + + for ( i = 0; i < n; i++ ) { + error = y[i] - (m * x[i] + b); + error = error * error; + if ( error > max_error ) { + max_error = error; + } + } + + return ( max_error ); +} + + +/* $Log$ +/* Revision 1.1 1998/04/08 22:57:24 curt +/* Adopted Gnu automake/autoconf system. +/* + * Revision 1.1 1998/03/19 02:54:47 curt + * Reorganized into a class lib called fgDEM. + * + * Revision 1.1 1997/10/13 17:02:35 curt + * Initial revision. + * + */ diff --git a/DEM/leastsqs.h b/DEM/leastsqs.h deleted file mode 100644 index c2b8866ef..000000000 --- a/DEM/leastsqs.h +++ /dev/null @@ -1,67 +0,0 @@ -/* leastsqs.h -- Implements a simple linear least squares best fit routine - * - * Written by Curtis Olson, started September 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * 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) - */ - - -/* -Least squares fit: - -y = b0 + b1x - - n*sum(xi*yi) - (sum(xi)*sum(yi)) -b1 = -------------------------------- - n*sum(xi^2) - (sum(xi))^2 - - -b0 = sum(yi)/n - b1*(sum(xi)/n) -*/ - -void least_squares(double *x, double *y, int n, double *m, double *b); - - -/* - return the least squares error: - - (y[i] - y_hat[i])^2 - ------------------- - n - */ -double least_squares_error(double *x, double *y, int n, double m, double b); - - -/* - return the maximum least squares error: - - (y[i] - y_hat[i])^2 - */ -double least_squares_max_error(double *x, double *y, int n, double m, double b); - - -/* $Log$ -/* Revision 1.1 1998/03/19 02:54:48 curt -/* Reorganized into a class lib called fgDEM. -/* - * Revision 1.1 1997/10/13 17:02:35 curt - * Initial revision. - * - */ diff --git a/DEM/leastsqs.hxx b/DEM/leastsqs.hxx new file mode 100644 index 000000000..8e0d3dec8 --- /dev/null +++ b/DEM/leastsqs.hxx @@ -0,0 +1,70 @@ +/* leastsqs.h -- Implements a simple linear least squares best fit routine + * + * Written by Curtis Olson, started September 1997. + * + * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com + * + * 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) + */ + + +/* +Least squares fit: + +y = b0 + b1x + + n*sum(xi*yi) - (sum(xi)*sum(yi)) +b1 = -------------------------------- + n*sum(xi^2) - (sum(xi))^2 + + +b0 = sum(yi)/n - b1*(sum(xi)/n) +*/ + +void least_squares(double *x, double *y, int n, double *m, double *b); + + +/* + return the least squares error: + + (y[i] - y_hat[i])^2 + ------------------- + n + */ +double least_squares_error(double *x, double *y, int n, double m, double b); + + +/* + return the maximum least squares error: + + (y[i] - y_hat[i])^2 + */ +double least_squares_max_error(double *x, double *y, int n, double m, double b); + + +/* $Log$ +/* Revision 1.1 1998/04/08 22:57:25 curt +/* Adopted Gnu automake/autoconf system. +/* + * Revision 1.1 1998/03/19 02:54:48 curt + * Reorganized into a class lib called fgDEM. + * + * Revision 1.1 1997/10/13 17:02:35 curt + * Initial revision. + * + */