]> git.mxchange.org Git - flightgear.git/blob - FixNode/main.cxx
Initial revision.
[flightgear.git] / FixNode / main.cxx
1 // main.cxx -- read in a .node file and fix the z values of the interpolated 
2 //             points
3 //
4 // Written by Curtis Olson, started November 1997.
5 //
6 // Copyright (C) 1997  Curtis L. Olson  - curt@infoplane.com
7 //
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.
12 //
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.
17 //
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.
21 //
22 // $Id$
23 // (Log is kept at end of this file)
24 //
25
26
27 #include <sys/types.h>
28 #include <dirent.h>
29 // #include <stdio.h>
30 #include <string.h>
31 #include <string>
32
33 #ifdef HAVE_STDLIB_H
34 #  include <stdlib.h>
35 #endif // HAVE_STDLIB_H
36
37 #include <DEM/dem.hxx>
38
39 #include "fixnode.hxx"
40
41
42 // find all the matching files in the specified directory and fix them
43 void process_files(const string& root_path, fgDEM& dem) {
44     container node_list;
45     DIR *d;
46     struct dirent *de;
47     string file_path;
48     char *ptr;
49     int len;
50
51     if ( (d = opendir( root_path.c_str() )) == NULL ) {
52         cout << "cannot open directory " + root_path + "\n";
53         exit(-1);
54     }
55
56     while ( (de = readdir(d)) != NULL ) {
57         len = strlen(de->d_name);
58         if ( len > 7 ) {
59             ptr = de->d_name;
60             ptr += (len - 7);
61             // printf("--> %s \n", ptr);
62
63             if ( strcmp(ptr, ".1.node") == 0 ) {
64                 file_path =  root_path + "/" + de->d_name;
65                 cout << "File = " + file_path + "\n";
66
67                 // load the input data files
68                 load_nodes(file_path, node_list);
69
70                 fix_nodes(file_path, dem, node_list);
71             }
72         }
73     }
74 }
75
76
77 // main
78 int main(int argc, char **argv) {
79     fgDEM dem;
80     string demfile, root_path;
81
82     if ( argc != 3 ) {
83         cout << "Usage " << argv[0] << " demfile root_path\n";
84         exit(-1);
85     }
86
87     cout << "Starting fixnode\n";
88
89     demfile = argv[1];
90     root_path = argv[2];
91
92     // load the corresponding dem file so we can interpolate elev values
93     dem.open(demfile);
94     dem.parse();
95     dem.close();
96
97     // process all the *.1.node files in the specified directory
98     process_files(root_path, dem);
99
100     return(0);
101 }
102
103
104 // $Log$
105 // Revision 1.7  1998/09/19 20:43:54  curt
106 // C++-ified and STL-ified the code.  Combined triload.* and fixnode.* into
107 // a single file.
108 //
109 // Revision 1.6  1998/09/19 18:01:27  curt
110 // Support for changes to libDEM.a
111 //
112 // Revision 1.5  1998/07/22 21:46:41  curt
113 // Fixed a bug that was triggering a seg fault.
114 //
115 // Revision 1.4  1998/06/27 16:55:24  curt
116 // Changed include order for <sys/types.h>
117 //
118 // Revision 1.3  1998/04/26 05:02:06  curt
119 // Added #ifdef HAVE_STDLIB_H
120 //
121 // Revision 1.2  1998/04/14 02:26:04  curt
122 // Code reorganizations.  Added a Lib/ directory for more general libraries.
123 //
124 // Revision 1.1  1998/04/08 23:05:57  curt
125 // Adopted Gnu automake/autoconf system.
126 //
127 // Revision 1.6  1998/04/06 21:09:44  curt
128 // Additional win32 support.
129 // Fixed a bad bug in dem file parsing that was causing the output to be
130 // flipped about x = y.
131 //
132 // Revision 1.5  1998/03/19 02:50:20  curt
133 // Updated to support -lDEM class.
134 //
135 // Revision 1.4  1998/03/03 16:00:58  curt
136 // More c++ compile tweaks.
137 //
138 // Revision 1.3  1998/01/09 23:03:08  curt
139 // Restructured to split 1deg x 1deg dem's into 64 subsections.
140 //
141 // Revision 1.2  1997/12/02 13:12:07  curt
142 // Updated to fix every node.
143 //
144 // Revision 1.1  1997/11/27 00:17:34  curt
145 // Initial revision.
146 //