1998-03-19 02:50:19 +00:00
|
|
|
// triload.c -- read in a .node file and fix the z values of the interpolated
|
|
|
|
// points
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started November 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)
|
|
|
|
//
|
1997-11-27 00:17:32 +00:00
|
|
|
|
|
|
|
|
1998-01-09 23:03:05 +00:00
|
|
|
#include <dirent.h>
|
1997-11-27 00:17:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1998-01-09 23:03:05 +00:00
|
|
|
#include <sys/types.h>
|
1997-11-27 00:17:32 +00:00
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
#include "../DEM/dem.h"
|
1997-11-27 00:17:32 +00:00
|
|
|
#include "fixnode.h"
|
|
|
|
#include "triload.h"
|
|
|
|
|
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
// Storage for the original DEM data which is used to interpolate z values
|
|
|
|
static fgDEM dem;
|
|
|
|
static float dem_data[DEM_SIZE_1][DEM_SIZE_1];
|
1998-01-09 23:03:05 +00:00
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
// Node list
|
1998-03-03 16:00:52 +00:00
|
|
|
static double nodes[MAX_NODES][3];
|
1998-01-09 23:03:05 +00:00
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
|
|
|
|
// find all the matching files in the specified directory and fix them
|
1998-01-09 23:03:05 +00:00
|
|
|
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);
|
1998-03-19 02:50:19 +00:00
|
|
|
// printf("--> %s \n", ptr);
|
1998-01-09 23:03:05 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
// load the input data files
|
1998-03-03 16:00:52 +00:00
|
|
|
triload(file_path, nodes);
|
1998-01-09 23:03:05 +00:00
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
fixnodes(file_path, dem, dem_data, nodes);
|
1998-01-09 23:03:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
// main
|
1997-11-27 00:17:32 +00:00
|
|
|
int main(int argc, char **argv) {
|
1998-01-09 23:03:05 +00:00
|
|
|
char demfile[256], root_path[256];
|
1997-11-27 00:17:32 +00:00
|
|
|
|
1998-01-09 23:03:05 +00:00
|
|
|
if ( argc != 3 ) {
|
|
|
|
printf("Usage %s demfile root_path\n", argv[0]);
|
|
|
|
exit(-1);
|
|
|
|
}
|
1997-11-27 00:17:32 +00:00
|
|
|
|
1998-01-09 23:03:05 +00:00
|
|
|
strcpy(demfile, argv[1]);
|
|
|
|
strcpy(root_path, argv[2]);
|
1997-11-27 00:17:32 +00:00
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
// load the corresponding dem file so we can interpolate elev values
|
|
|
|
dem.open(demfile);
|
|
|
|
dem.parse(dem_data);
|
|
|
|
dem.close();
|
1997-11-27 00:17:32 +00:00
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
// process all the *.1.node files in the specified directory
|
1998-01-09 23:03:05 +00:00
|
|
|
process_files(root_path);
|
1997-11-27 00:17:32 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-03-19 02:50:19 +00:00
|
|
|
// $Log$
|
|
|
|
// Revision 1.5 1998/03/19 02:50:20 curt
|
|
|
|
// Updated to support -lDEM class.
|
|
|
|
//
|
|
|
|
// Revision 1.4 1998/03/03 16:00:58 curt
|
|
|
|
// More c++ compile tweaks.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//
|