1
0
Fork 0

Additional win32 support.

Fixed a bad bug in dem file parsing that was causing the output to be
flipped about x = y.
This commit is contained in:
curt 1998-04-06 21:09:37 +00:00
parent f3fed05fc9
commit e9ffabdc8e
7 changed files with 172 additions and 37 deletions

111
DEM/dem.c
View file

@ -28,6 +28,7 @@
#include <math.h> // rint() #include <math.h> // rint()
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> // atoi() #include <stdlib.h> // atoi()
#include <string.h>
#include <sys/stat.h> // stat() #include <sys/stat.h> // stat()
#include <unistd.h> // stat() #include <unistd.h> // stat()
@ -37,11 +38,61 @@
#include <Include/fg_constants.h> #include <Include/fg_constants.h>
#ifdef WIN32
# define MKDIR(a) mkdir(a,S_IRWXU) // I am just guessing at this flag (NHV)
#endif // WIN32
fgDEM::fgDEM( void ) { fgDEM::fgDEM( void ) {
// printf("class fgDEM CONstructor called.\n"); // printf("class fgDEM CONstructor called.\n");
} }
#ifdef WIN32
// return the file path name ( foo/bar/file.ext = foo/bar )
void extract_path (char *in, char *base) {
int len, i;
len = strlen (in);
strcpy (base, in);
i = len - 1;
while ( (i >= 0) && (in[i] != '/') ) {
i--;
}
base[i] = '\0';
}
// Make a subdirectory
int my_mkdir (char *dir) {
struct stat stat_buf;
int result;
printf ("mk_dir() ");
result = stat (dir, &stat_buf);
if (result != 0) {
MKDIR (dir);
result = stat (dir, &stat_buf);
if (result != 0) {
printf ("problem creating %s\n", dir);
} else {
printf ("%s created\n", dir);
}
} else {
printf ("%s already exists\n", dir);
}
return (result);
}
#endif // WIN32
// open a DEM file // open a DEM file
int fgDEM::open ( char *file ) { int fgDEM::open ( char *file ) {
// open input file (or read from stdin) // open input file (or read from stdin)
@ -93,7 +144,7 @@ static int next_int(FILE *fd) {
// return next double from input stream // return next double from input stream
double next_double(FILE *fd) { static double next_double(FILE *fd) {
char token[80]; char token[80];
next_token(fd, token); next_token(fd, token);
@ -102,7 +153,7 @@ double next_double(FILE *fd) {
// return next exponential num from input stream // return next exponential num from input stream
int next_exp(FILE *fd) { static int next_exp(FILE *fd) {
double mantissa; double mantissa;
int exp, acc; int exp, acc;
int i; int i;
@ -258,7 +309,7 @@ void fgDEM::read_a_record( void ) {
next_token(fd, token); next_token(fd, token);
// number of profiles // number of profiles
dem_num_profiles = rows = next_int(fd); dem_num_profiles = cols = next_int(fd);
printf(" Expecting %d profiles\n", dem_num_profiles); printf(" Expecting %d profiles\n", dem_num_profiles);
} }
@ -270,14 +321,14 @@ void fgDEM::read_b_record(float dem_data[DEM_SIZE_1][DEM_SIZE_1])
int i; int i;
// row / column id of this profile // row / column id of this profile
prof_col = next_int(fd);
prof_row = next_int(fd); prof_row = next_int(fd);
prof_col = next_int(fd);
// printf("col id = %d row id = %d\n", prof_col, prof_row); // printf("col id = %d row id = %d\n", prof_col, prof_row);
// Number of columns and rows (elevations) in this profile // Number of columns and rows (elevations) in this profile
prof_num_cols = cols = next_int(fd); prof_num_rows = rows = next_int(fd);
prof_num_rows = next_int(fd); prof_num_cols = next_int(fd);
// printf(" profile num rows = %d\n", prof_num_cols); // printf(" profile num rows = %d\n", prof_num_rows);
// Ground planimetric coordinates (arc-seconds) of the first // Ground planimetric coordinates (arc-seconds) of the first
// elevation in the profile // elevation in the profile
@ -294,9 +345,9 @@ void fgDEM::read_b_record(float dem_data[DEM_SIZE_1][DEM_SIZE_1])
next_token(fd, token); next_token(fd, token);
// One (usually) dimensional array (prof_num_cols,1) of elevations // One (usually) dimensional array (prof_num_cols,1) of elevations
for ( i = 0; i < prof_num_cols; i++ ) { for ( i = 0; i < prof_num_rows; i++ ) {
prof_data = next_int(fd); prof_data = next_int(fd);
dem_data[i][cur_row] = (float)prof_data; dem_data[cur_col][i] = (float)prof_data;
} }
} }
@ -311,10 +362,10 @@ int fgDEM::parse( float dem_data[DEM_SIZE_1][DEM_SIZE_1] ) {
for ( i = 0; i < dem_num_profiles; i++ ) { for ( i = 0; i < dem_num_profiles; i++ ) {
read_b_record( dem_data ); read_b_record( dem_data );
cur_row++; cur_col++;
if ( cur_row % 100 == 0 ) { if ( cur_col % 100 == 0 ) {
printf(" loaded %d profiles of data\n", cur_row); printf(" loaded %d profiles of data\n", cur_col);
} }
} }
@ -581,9 +632,9 @@ void fgDEM::fit( float dem_data[DEM_SIZE_1][DEM_SIZE_1],
// Initialize output mesh structure // Initialize output mesh structure
void fgDEM::outputmesh_init( float output_data[DEM_SIZE_1][DEM_SIZE_1] ) { void fgDEM::outputmesh_init( float output_data[DEM_SIZE_1][DEM_SIZE_1] ) {
int i, j; int i, j;
for ( i = 0; i < DEM_SIZE_1; i++ ) { for ( j = 0; j < DEM_SIZE_1; j++ ) {
for ( j = 0; j < DEM_SIZE_1; j++ ) { for ( i = 0; i < DEM_SIZE_1; i++ ) {
output_data[i][j] = -9999.0; output_data[i][j] = -9999.0;
} }
} }
@ -613,6 +664,9 @@ void fgDEM::outputmesh_output_nodes( float output_data[DEM_SIZE_1][DEM_SIZE_1],
{ {
struct stat stat_buf; struct stat stat_buf;
char base_path[256], dir[256], file[256]; char base_path[256], dir[256], file[256];
#ifdef WIN32
char tmp_path[256];
#endif
char command[256]; char command[256];
FILE *fd; FILE *fd;
long int index; long int index;
@ -637,8 +691,30 @@ void fgDEM::outputmesh_output_nodes( float output_data[DEM_SIZE_1][DEM_SIZE_1],
result = stat(dir, &stat_buf); result = stat(dir, &stat_buf);
if ( result != 0 ) { if ( result != 0 ) {
printf("Stat error need to create directory\n"); printf("Stat error need to create directory\n");
#ifndef WIN32
sprintf(command, "mkdir -p %s\n", dir); sprintf(command, "mkdir -p %s\n", dir);
system(command); system(command);
#else // WIN32
// Cygwin crashes when trying to output to node file
// explicitly making directory structure seems OK on Win95
extract_path (base_path, tmp_path);
sprintf (dir, "%s/Scenery", fg_root);
if (my_mkdir (dir)) { exit (-1); }
sprintf (dir, "%s/Scenery/%s", fg_root, tmp_path);
if (my_mkdir (dir)) { exit (-1); }
sprintf (dir, "%s/Scenery/%s", fg_root, base_path);
if (my_mkdir (dir)) { exit (-1); }
#endif // WIN32
} else { } else {
// assume directory exists // assume directory exists
} }
@ -687,6 +763,11 @@ fgDEM::~fgDEM( void ) {
// $Log$ // $Log$
// Revision 1.3 1998/04/06 21:09:41 curt
// Additional win32 support.
// Fixed a bad bug in dem file parsing that was causing the output to be
// flipped about x = y.
//
// Revision 1.2 1998/03/23 20:35:41 curt // Revision 1.2 1998/03/23 20:35:41 curt
// Updated to use FG_EPSILON // Updated to use FG_EPSILON
// //

View file

@ -416,7 +416,7 @@ void rawProcessStrip( fgRAWDEM *raw, int lat_degrees, char *path ) {
* row/col are reversed here. raw->strip is backwards * row/col are reversed here. raw->strip is backwards
* for convenience. I am converting to [x,y] now. */ * for convenience. I am converting to [x,y] now. */
raw->center[col-xstart][row] = raw->strip[row][col]; raw->center[col-xstart][row] = raw->strip[row][col];
if ( raw->strip[row][col] < min) { if ( raw->strip[row][col] < min) {
min = raw->strip[row][col]; min = raw->strip[row][col];
} }
@ -440,9 +440,14 @@ void rawProcessStrip( fgRAWDEM *raw, int lat_degrees, char *path ) {
/* $Log$ /* $Log$
/* Revision 1.3 1998/03/03 13:10:29 curt /* Revision 1.4 1998/04/06 21:09:43 curt
/* Close to a working version. /* Additional win32 support.
/* Fixed a bad bug in dem file parsing that was causing the output to be
/* flipped about x = y.
/* /*
* Revision 1.3 1998/03/03 13:10:29 curt
* Close to a working version.
*
* Revision 1.2 1998/03/03 02:04:01 curt * Revision 1.2 1998/03/03 02:04:01 curt
* Starting DEM Ascii format output routine. * Starting DEM Ascii format output routine.
* *

View file

@ -37,7 +37,7 @@ include $(FG_ROOT_SRC)/commondefs
# Rule for TARGET # Rule for TARGET
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
$(TARGET): $(OBJECTS) $(TARGET): $(OBJECTS) $(FG_ROOT_LIB)/stamp_libs
$(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(LDLIBS) $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(LDLIBS)
@ -46,6 +46,11 @@ include $(COMMONRULES)
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $Log$
# Revision 1.4 1998/04/06 21:09:44 curt
# Additional win32 support.
# Fixed a bad bug in dem file parsing that was causing the output to be
# flipped about x = y.
#
# Revision 1.3 1998/03/19 02:50:19 curt # Revision 1.3 1998/03/19 02:50:19 curt
# Updated to support -lDEM class. # Updated to support -lDEM class.
# #

View file

@ -1,5 +1,5 @@
// triload.c -- read in a .node file and fix the z values of the interpolated // main.c -- read in a .node file and fix the z values of the interpolated
// points // points
// //
// Written by Curtis Olson, started November 1997. // Written by Curtis Olson, started November 1997.
// //
@ -103,6 +103,11 @@ int main(int argc, char **argv) {
// $Log$ // $Log$
// Revision 1.6 1998/04/06 21:09:44 curt
// Additional win32 support.
// Fixed a bad bug in dem file parsing that was causing the output to be
// flipped about x = y.
//
// Revision 1.5 1998/03/19 02:50:20 curt // Revision 1.5 1998/03/19 02:50:20 curt
// Updated to support -lDEM class. // Updated to support -lDEM class.
// //

View file

@ -63,15 +63,17 @@ source-tar: clean
(cd ..; \ (cd ..; \
tar cvzf demtools-$(FG_VERSION).tar.gz Tools/Makefile Tools/README \ tar cvzf demtools-$(FG_VERSION).tar.gz Tools/Makefile Tools/README \
Tools/Todo Tools/make.inc Tools/process-dem.pl Tools/AssemTris \ Tools/Todo Tools/make.inc Tools/process-dem.pl Tools/AssemTris \
Tools/Dem2node Tools/DemRaw2Ascii Tools/FixNode Tools/FixObj \ Tools/DEM Tools/gpc2.01 Tools/Dem2node Tools/DemRaw2Ascii \
Tools/SplitTris Tools/Stripe_u Tools/Tri2obj Tools/Triangle) Tools/FixNode Tools/FixObj Tools/SplitTris Tools/Stripe_u \
Tools/Tri2obj Tools/Triangle)
source-zip: clean source-zip: clean
(cd ..; \ (cd ..; \
zip -r demtools-$(FG_VERSION).zip Tools/Makefile Tools/README \ zip -r demtools-$(FG_VERSION).zip Tools/Makefile Tools/README \
Tools/Todo Tools/make.inc Tools/process-dem.pl Tools/AssemTris \ Tools/Todo Tools/make.inc Tools/process-dem.pl Tools/AssemTris \
Tools/Dem2node Tools/DemRaw2Ascii Tools/FixNode Tools/FixObj \ Tools/DEM Tools/gpc2.01 Tools/Dem2node Tools/DemRaw2Ascii \
Tools/SplitTris Tools/Stripe_u Tools/Tri2obj Tools/Triangle) Tools/FixNode Tools/FixObj Tools/SplitTris Tools/Stripe_u \
Tools/Tri2obj Tools/Triangle)
bin-tar: all bin-tar: all
echo "need to fix this" echo "need to fix this"
@ -91,6 +93,11 @@ bin-zip:
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $Log$
# Revision 1.14 1998/04/06 21:09:37 curt
# Additional win32 support.
# Fixed a bad bug in dem file parsing that was causing the output to be
# flipped about x = y.
#
# Revision 1.13 1998/03/19 02:52:51 curt # Revision 1.13 1998/03/19 02:52:51 curt
# Updated to reflect some minor tool reorganization and the creation of class # Updated to reflect some minor tool reorganization and the creation of class
# to handle DEM processing needs. # to handle DEM processing needs.

View file

@ -2,6 +2,10 @@
| Done | Done
-------------------------------------------------------------------------- --------------------------------------------------------------------------
4/6/98 - fix 30 arcsec dem file processing
4/6/98 - incorporate autoconf/automake build system
1/10/98 - Split areas into smaller tiles 1/10/98 - Split areas into smaller tiles
1/14/98 - Don't create shared corners or edges if one already exists. 1/14/98 - Don't create shared corners or edges if one already exists.

View file

@ -91,6 +91,21 @@ while ( $dem_file = shift(@ARGV) ) {
exit(0); exit(0);
# fix command to work with windoze, replaces first "/" with "\\"
sub fix_command {
my($in) = @_;
$system = `uname -s`;
chop($system);
if ( $system =~ m/CYGWIN32/ ) {
$in =~ s/\//\\\\/;
}
return($in);
}
# return the file name root (ending at last ".") # return the file name root (ending at last ".")
sub file_root { sub file_root {
my($file) = @_; my($file) = @_;
@ -110,11 +125,11 @@ sub file_root {
sub demfit { sub demfit {
if ( $dem_file =~ m/.gz$/ ) { if ( $dem_file =~ m/.gz$/ ) {
$command = "gzip -dc $dem_file | ./Dem2node/dem2node $ENV{FG_ROOT} - $error"; $command = "gzip -dc $dem_file | Dem2node/dem2node $ENV{FG_ROOT} - $error";
} else { } else {
$command = "./Dem2node/dem2node $ENV{FG_ROOT} $dem_file $error"; $command = "Dem2node/dem2node $ENV{FG_ROOT} $dem_file $error";
} }
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
@ -141,7 +156,8 @@ sub triangle_1 {
print $file; print $file;
chop($file); chop($file);
if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) { if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
$command = "./Triangle/triangle -q $subdir/$file"; $command = "Triangle/triangle -q $subdir/$file";
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -164,10 +180,11 @@ sub triangle_1 {
sub fixnode { sub fixnode {
if ( $dem_file =~ m/.gz$/ ) { if ( $dem_file =~ m/.gz$/ ) {
$command = "gzip -dc $dem_file | ./FixNode/fixnode - $subdir"; $command = "gzip -dc $dem_file | FixNode/fixnode - $subdir";
} else { } else {
$command = "./FixNode/fixnode $dem_file $subdir"; $command = "FixNode/fixnode $dem_file $subdir";
} }
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -199,7 +216,8 @@ sub splittris {
if ( $file =~ m/\.1\.node$/ ) { if ( $file =~ m/\.1\.node$/ ) {
$file =~ s/\.node$//; # strip off the ".node" $file =~ s/\.node$//; # strip off the ".node"
$command = "./SplitTris/splittris $subdir/$file"; $command = "SplitTris/splittris $subdir/$file";
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -226,7 +244,8 @@ sub assemtris {
if ( $file =~ m/\.1\.body$/ ) { if ( $file =~ m/\.1\.body$/ ) {
$file =~ s/\.body$//; # strip off the ".body" $file =~ s/\.body$//; # strip off the ".body"
$command = "./AssemTris/assemtris $subdir/$file"; $command = "AssemTris/assemtris $subdir/$file";
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -248,7 +267,8 @@ sub triangle_2 {
print $file; print $file;
chop($file); chop($file);
if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) { if ( ($file =~ m/\.node$/) && ($file !~ m/\.\d\.node$/) ) {
$command = "./Triangle/triangle $subdir/$file"; $command = "Triangle/triangle $subdir/$file";
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -280,7 +300,8 @@ sub tri2obj {
if ( $file =~ m/\.1\.node$/ ) { if ( $file =~ m/\.1\.node$/ ) {
$file =~ s/\.node$//; # strip off the ".node" $file =~ s/\.node$//; # strip off the ".node"
$command = "./Tri2obj/tri2obj $subdir/$file"; $command = "Tri2obj/tri2obj $subdir/$file";
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -310,7 +331,8 @@ sub strips {
foreach $file ( @FILES ) { foreach $file ( @FILES ) {
chop($file); chop($file);
if ( $file =~ m/\.1\.obj$/ ) { if ( $file =~ m/\.1\.obj$/ ) {
$command = "./Stripe_u/strips $subdir/$file"; $command = "Stripe_u/strips $subdir/$file";
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -348,7 +370,8 @@ sub fixobj {
$newfile = $file; $newfile = $file;
$newfile =~ s/\.2\.obj$/.obj/; $newfile =~ s/\.2\.obj$/.obj/;
$command = "./FixObj/fixobj $subdir/$file $subdir/$newfile"; $command = "FixObj/fixobj $subdir/$file $subdir/$newfile";
$command = fix_command($command);
print "Running '$command'\n"; print "Running '$command'\n";
open(OUT, "$command |"); open(OUT, "$command |");
while ( <OUT> ) { while ( <OUT> ) {
@ -364,6 +387,11 @@ sub fixobj {
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
# $Log$ # $Log$
# Revision 1.14 1998/04/06 21:09:38 curt
# Additional win32 support.
# Fixed a bad bug in dem file parsing that was causing the output to be
# flipped about x = y.
#
# Revision 1.13 1998/03/19 02:52:52 curt # Revision 1.13 1998/03/19 02:52:52 curt
# Updated to reflect some minor tool reorganization and the creation of class # Updated to reflect some minor tool reorganization and the creation of class
# to handle DEM processing needs. # to handle DEM processing needs.