]> git.mxchange.org Git - flightgear.git/blobdiff - FixNode/main.c
Restructured to split 1deg x 1deg dem's into 64 subsections.
[flightgear.git] / FixNode / main.c
index 7ebd5d7e530fdc36f5ee54f942b6fd8d74aa7318..002c495cfa6190c7a36185324238c8a9436e27c8 100644 (file)
  */
 
 
+#include <dirent.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/types.h>
 
 #include "../Dem2node/demparse.h"
 #include "fixnode.h"
 #include "triload.h"
 
 
+/* Original DEM which is used to interpolate z values */
+struct MESH dem_mesh;
+
+
+/* find all the matching files in the specified directory and fix them */
+void process_files(char *root_path) {
+    DIR *d;
+    struct dirent *de;
+    char file_path[256];
+    char *ptr;
+    int len;
+
+    if ( (d = opendir(root_path)) == NULL ) {
+        printf("cannot open directory '%s'.", root_path);
+       exit(-1);
+    }
+
+    while ( (de = readdir(d)) != NULL ) {
+       len = strlen(de->d_name);
+       if ( len > 7 ) {
+           ptr = de->d_name;
+           ptr += (len - 7);
+           /* printf("--> %s \n", ptr); */
+
+           if ( strcmp(ptr, ".1.node") == 0 ) {
+               strcpy(file_path, root_path);
+               strcat(file_path, "/");
+               strcat(file_path, de->d_name);
+               printf("File = %s\n", file_path);
+
+               /* load the input data files */
+               triload(file_path);
+
+               fixnodes(file_path, &dem_mesh);
+           }
+       }
+    }
+}
+
+
+/* main */
 int main(int argc, char **argv) {
-    char basename[256];
-    struct MESH dem_mesh;
+    char demfile[256], root_path[256];
 
-    strcpy(basename, argv[1]);
+    if ( argc != 3 ) {
+       printf("Usage %s demfile root_path\n", argv[0]);
+       exit(-1);
+    }
 
-    /* load the input data files */
-    triload(basename);
+    strcpy(demfile, argv[1]);
+    strcpy(root_path, argv[2]);
 
     /* load the corresponding dem file so we can interpolate elev values */
-    dem_parse(basename, &dem_mesh);
+    dem_parse(demfile, &dem_mesh);
 
-    fixnodes(basename, &dem_mesh);
+    /* process all the *.1.node files in the specified directory */
+    process_files(root_path);
 
     return(0);
 }
 
 
 /* $Log$
-/* Revision 1.2  1997/12/02 13:12:07  curt
-/* Updated to fix every node.
+/* Revision 1.3  1998/01/09 23:03:08  curt
+/* Restructured to split 1deg x 1deg dem's into 64 subsections.
 /*
+ * Revision 1.2  1997/12/02 13:12:07  curt
+ * Updated to fix every node.
+ *
  * Revision 1.1  1997/11/27 00:17:34  curt
  * Initial revision.
  *