]> git.mxchange.org Git - flightgear.git/blob - FixNode/main.cxx
Code reorganizations. Added a Lib/ directory for more general libraries.
[flightgear.git] / FixNode / main.cxx
1 // main.c -- 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 <dirent.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <sys/types.h>
31
32 #include <DEM/dem.hxx>
33
34 #include "fixnode.hxx"
35 #include "triload.hxx"
36
37
38 // Storage for the original DEM data which is used to interpolate z values
39 static fgDEM dem;
40 static float dem_data[DEM_SIZE_1][DEM_SIZE_1];
41
42 // Node list
43 static double nodes[MAX_NODES][3];
44
45
46 // find all the matching files in the specified directory and fix them
47 void process_files(char *root_path) {
48     DIR *d;
49     struct dirent *de;
50     char file_path[256];
51     char *ptr;
52     int len;
53
54     if ( (d = opendir(root_path)) == NULL ) {
55         printf("cannot open directory '%s'.", root_path);
56         exit(-1);
57     }
58
59     while ( (de = readdir(d)) != NULL ) {
60         len = strlen(de->d_name);
61         if ( len > 7 ) {
62             ptr = de->d_name;
63             ptr += (len - 7);
64             // printf("--> %s \n", ptr);
65
66             if ( strcmp(ptr, ".1.node") == 0 ) {
67                 strcpy(file_path, root_path);
68                 strcat(file_path, "/");
69                 strcat(file_path, de->d_name);
70                 printf("File = %s\n", file_path);
71
72                 // load the input data files
73                 triload(file_path, nodes);
74
75                 fixnodes(file_path, dem, dem_data, nodes);
76             }
77         }
78     }
79 }
80
81
82 // main
83 int main(int argc, char **argv) {
84     char demfile[256], root_path[256];
85
86     if ( argc != 3 ) {
87         printf("Usage %s demfile root_path\n", argv[0]);
88         exit(-1);
89     }
90
91     strcpy(demfile, argv[1]);
92     strcpy(root_path, argv[2]);
93
94     // load the corresponding dem file so we can interpolate elev values
95     dem.open(demfile);
96     dem.parse();
97     dem.close();
98
99     // process all the *.1.node files in the specified directory
100     process_files(root_path);
101
102     return(0);
103 }
104
105
106 // $Log$
107 // Revision 1.2  1998/04/14 02:26:04  curt
108 // Code reorganizations.  Added a Lib/ directory for more general libraries.
109 //
110 // Revision 1.1  1998/04/08 23:05:57  curt
111 // Adopted Gnu automake/autoconf system.
112 //
113 // Revision 1.6  1998/04/06 21:09:44  curt
114 // Additional win32 support.
115 // Fixed a bad bug in dem file parsing that was causing the output to be
116 // flipped about x = y.
117 //
118 // Revision 1.5  1998/03/19 02:50:20  curt
119 // Updated to support -lDEM class.
120 //
121 // Revision 1.4  1998/03/03 16:00:58  curt
122 // More c++ compile tweaks.
123 //
124 // Revision 1.3  1998/01/09 23:03:08  curt
125 // Restructured to split 1deg x 1deg dem's into 64 subsections.
126 //
127 // Revision 1.2  1997/12/02 13:12:07  curt
128 // Updated to fix every node.
129 //
130 // Revision 1.1  1997/11/27 00:17:34  curt
131 // Initial revision.
132 //
133 //