1 // fixnode.cxx -- traverse the node file and fix the elevation of all the new
2 // interpolated points.
4 // Written by Curtis Olson, started November 1997.
6 // Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 // (Log is kept at end of this file)
34 #endif // HAVE_STDLIB_H
36 #include <Misc/fgstream.hxx>
38 #include "fixnode.hxx"
39 #include "triload.hxx"
42 // load the node information
43 void load_nodes(const string& filename, container& node_list) {
45 int dim, junk1, junk2;
48 cout << "Loading node file: " + filename + " ...\n";
50 fg_gzifstream in( filename );
52 cout << "Cannot open " + filename + "\n";
53 // exit immediately assuming an airport file for this tile
59 in.stream() >> nodecount >> dim >> junk1 >> junk2;
60 cout << " Expecting " << nodecount << " nodes\n";
62 // start with an empty list :-)
63 node_list.erase( node_list.begin(), node_list.end() );
66 while ( ! in.eof() ) {
67 in.stream() >> junk1 >> node.x >> node.y >> node.z >> junk2;
69 node_list.push_back(node);
74 // fix the node elevations
75 void fix_nodes( const string& filename, fgDEM& dem, container& node_list )
81 cout << "Fixing up node elevations\n";
84 iterator last = node_list.end();
85 for ( current = node_list.begin() ; current != last ; ++current ) {
86 // printf("Current: %d %.2f %.2f %.2f\n", i, nodes[i][0],
87 // nodes[i][1], nodes[i][2]);
90 dem.interpolate_altitude( (*current).x, (*current).y );
92 // printf("Fixed: %d %.2f %.2f %.2f\n", i, nodes[i][0],
93 // nodes[i][1], nodes[i][2]);
97 toname = filename + ".orig";
98 cout << "Moving " + filename + " to " + toname + "\n";
99 rename( filename.c_str(), toname.c_str() );
101 cout << "Saving new node file: " + filename + "\n";
103 fd = fopen(filename.c_str(), "w");
105 fprintf( fd, "%d 2 1 0\n", node_list.size() );
108 for ( current = node_list.begin() ; current != last ; ++current ) {
109 fprintf( fd, "%d %.2f %.2f %.2f 0\n", i,
110 (*current).x, (*current).y, (*current).z );
119 // Revision 1.4 1998/09/19 20:43:52 curt
120 // C++-ified and STL-ified the code. Combined triload.* and fixnode.* into
123 // Revision 1.3 1998/07/22 21:46:40 curt
124 // Fixed a bug that was triggering a seg fault.
126 // Revision 1.2 1998/04/14 02:26:03 curt
127 // Code reorganizations. Added a Lib/ directory for more general libraries.
129 // Revision 1.1 1998/04/08 23:05:56 curt
130 // Adopted Gnu automake/autoconf system.
132 // Revision 1.5 1998/03/19 02:50:19 curt
133 // Updated to support -lDEM class.
135 // Revision 1.4 1998/03/03 16:00:57 curt
136 // More c++ compile tweaks.
138 // Revision 1.3 1998/01/09 23:03:08 curt
139 // Restructured to split 1deg x 1deg dem's into 64 subsections.
141 // Revision 1.2 1997/12/02 13:12:07 curt
142 // Updated to fix every node.
144 // Revision 1.1 1997/11/27 00:17:33 curt