From: curt Date: Mon, 6 Apr 1998 21:09:37 +0000 (+0000) Subject: Additional win32 support. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e9ffabdc8eb9888b2de2545facbc719a516648fd;p=flightgear.git Additional win32 support. Fixed a bad bug in dem file parsing that was causing the output to be flipped about x = y. --- diff --git a/DEM/dem.c b/DEM/dem.c index ae46f8689..0dc3aa5e8 100644 --- a/DEM/dem.c +++ b/DEM/dem.c @@ -28,6 +28,7 @@ #include // rint() #include #include // atoi() +#include #include // stat() #include // stat() @@ -37,11 +38,61 @@ #include +#ifdef WIN32 +# define MKDIR(a) mkdir(a,S_IRWXU) // I am just guessing at this flag (NHV) +#endif // WIN32 + + fgDEM::fgDEM( void ) { // 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 int fgDEM::open ( char *file ) { // open input file (or read from stdin) @@ -93,7 +144,7 @@ static int next_int(FILE *fd) { // return next double from input stream -double next_double(FILE *fd) { +static double next_double(FILE *fd) { char token[80]; next_token(fd, token); @@ -102,7 +153,7 @@ double next_double(FILE *fd) { // return next exponential num from input stream -int next_exp(FILE *fd) { +static int next_exp(FILE *fd) { double mantissa; int exp, acc; int i; @@ -258,7 +309,7 @@ void fgDEM::read_a_record( void ) { next_token(fd, token); // 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); } @@ -270,14 +321,14 @@ void fgDEM::read_b_record(float dem_data[DEM_SIZE_1][DEM_SIZE_1]) int i; // row / column id of this profile - prof_col = 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); // Number of columns and rows (elevations) in this profile - prof_num_cols = cols = next_int(fd); - prof_num_rows = next_int(fd); - // printf(" profile num rows = %d\n", prof_num_cols); + prof_num_rows = rows = next_int(fd); + prof_num_cols = next_int(fd); + // printf(" profile num rows = %d\n", prof_num_rows); // Ground planimetric coordinates (arc-seconds) of the first // 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); // 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); - 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++ ) { read_b_record( dem_data ); - cur_row++; + cur_col++; - if ( cur_row % 100 == 0 ) { - printf(" loaded %d profiles of data\n", cur_row); + if ( cur_col % 100 == 0 ) { + 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 void fgDEM::outputmesh_init( float output_data[DEM_SIZE_1][DEM_SIZE_1] ) { 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; } } @@ -613,6 +664,9 @@ void fgDEM::outputmesh_output_nodes( float output_data[DEM_SIZE_1][DEM_SIZE_1], { struct stat stat_buf; char base_path[256], dir[256], file[256]; +#ifdef WIN32 + char tmp_path[256]; +#endif char command[256]; FILE *fd; 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); if ( result != 0 ) { printf("Stat error need to create directory\n"); + +#ifndef WIN32 + sprintf(command, "mkdir -p %s\n", dir); 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 { // assume directory exists } @@ -687,6 +763,11 @@ fgDEM::~fgDEM( void ) { // $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 // Updated to use FG_EPSILON // diff --git a/DemRaw2ascii/rawdem.c b/DemRaw2ascii/rawdem.c index 88727d73d..ae6679f09 100644 --- a/DemRaw2ascii/rawdem.c +++ b/DemRaw2ascii/rawdem.c @@ -416,7 +416,7 @@ void rawProcessStrip( fgRAWDEM *raw, int lat_degrees, char *path ) { * row/col are reversed here. raw->strip is backwards * for convenience. I am converting to [x,y] now. */ raw->center[col-xstart][row] = raw->strip[row][col]; - + if ( raw->strip[row][col] < min) { min = raw->strip[row][col]; } @@ -440,9 +440,14 @@ void rawProcessStrip( fgRAWDEM *raw, int lat_degrees, char *path ) { /* $Log$ -/* Revision 1.3 1998/03/03 13:10:29 curt -/* Close to a working version. +/* Revision 1.4 1998/04/06 21:09:43 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/03 13:10:29 curt + * Close to a working version. + * * Revision 1.2 1998/03/03 02:04:01 curt * Starting DEM Ascii format output routine. * diff --git a/FixNode/Makefile b/FixNode/Makefile index b259c623d..d5a138928 100644 --- a/FixNode/Makefile +++ b/FixNode/Makefile @@ -37,7 +37,7 @@ include $(FG_ROOT_SRC)/commondefs # Rule for TARGET #--------------------------------------------------------------------------- -$(TARGET): $(OBJECTS) +$(TARGET): $(OBJECTS) $(FG_ROOT_LIB)/stamp_libs $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(LDLIBS) @@ -46,6 +46,11 @@ include $(COMMONRULES) #--------------------------------------------------------------------------- # $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 # Updated to support -lDEM class. # diff --git a/FixNode/main.c b/FixNode/main.c index e903df613..b43c1d174 100644 --- a/FixNode/main.c +++ b/FixNode/main.c @@ -1,5 +1,5 @@ -// triload.c -- read in a .node file and fix the z values of the interpolated -// points +// main.c -- read in a .node file and fix the z values of the interpolated +// points // // Written by Curtis Olson, started November 1997. // @@ -103,6 +103,11 @@ int main(int argc, char **argv) { // $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 // Updated to support -lDEM class. // diff --git a/Tools/Makefile b/Tools/Makefile index 370d4ef55..8c1a7750b 100644 --- a/Tools/Makefile +++ b/Tools/Makefile @@ -63,15 +63,17 @@ source-tar: clean (cd ..; \ tar cvzf demtools-$(FG_VERSION).tar.gz Tools/Makefile Tools/README \ Tools/Todo Tools/make.inc Tools/process-dem.pl Tools/AssemTris \ - Tools/Dem2node Tools/DemRaw2Ascii Tools/FixNode Tools/FixObj \ - Tools/SplitTris Tools/Stripe_u Tools/Tri2obj Tools/Triangle) + Tools/DEM Tools/gpc2.01 Tools/Dem2node Tools/DemRaw2Ascii \ + Tools/FixNode Tools/FixObj Tools/SplitTris Tools/Stripe_u \ + Tools/Tri2obj Tools/Triangle) source-zip: clean (cd ..; \ zip -r demtools-$(FG_VERSION).zip Tools/Makefile Tools/README \ Tools/Todo Tools/make.inc Tools/process-dem.pl Tools/AssemTris \ - Tools/Dem2node Tools/DemRaw2Ascii Tools/FixNode Tools/FixObj \ - Tools/SplitTris Tools/Stripe_u Tools/Tri2obj Tools/Triangle) + Tools/DEM Tools/gpc2.01 Tools/Dem2node Tools/DemRaw2Ascii \ + Tools/FixNode Tools/FixObj Tools/SplitTris Tools/Stripe_u \ + Tools/Tri2obj Tools/Triangle) bin-tar: all echo "need to fix this" @@ -91,6 +93,11 @@ bin-zip: #--------------------------------------------------------------------------- # $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 # Updated to reflect some minor tool reorganization and the creation of class # to handle DEM processing needs. diff --git a/Tools/Todo b/Tools/Todo index 96d0bd539..d056dfc03 100644 --- a/Tools/Todo +++ b/Tools/Todo @@ -2,6 +2,10 @@ | 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/14/98 - Don't create shared corners or edges if one already exists. diff --git a/Tools/process-dem.pl b/Tools/process-dem.pl index a9c0ba05e..d82b9b5ce 100755 --- a/Tools/process-dem.pl +++ b/Tools/process-dem.pl @@ -91,6 +91,21 @@ while ( $dem_file = shift(@ARGV) ) { 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 ".") sub file_root { my($file) = @_; @@ -110,11 +125,11 @@ sub file_root { sub demfit { 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 { - $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"; open(OUT, "$command |"); @@ -141,7 +156,8 @@ sub triangle_1 { print $file; chop($file); 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"; open(OUT, "$command |"); while ( ) { @@ -164,10 +180,11 @@ sub triangle_1 { sub fixnode { if ( $dem_file =~ m/.gz$/ ) { - $command = "gzip -dc $dem_file | ./FixNode/fixnode - $subdir"; + $command = "gzip -dc $dem_file | FixNode/fixnode - $subdir"; } else { - $command = "./FixNode/fixnode $dem_file $subdir"; + $command = "FixNode/fixnode $dem_file $subdir"; } + $command = fix_command($command); print "Running '$command'\n"; open(OUT, "$command |"); while ( ) { @@ -199,7 +216,8 @@ sub splittris { if ( $file =~ m/\.1\.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"; open(OUT, "$command |"); while ( ) { @@ -226,7 +244,8 @@ sub assemtris { if ( $file =~ m/\.1\.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"; open(OUT, "$command |"); while ( ) { @@ -248,7 +267,8 @@ sub triangle_2 { print $file; chop($file); 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"; open(OUT, "$command |"); while ( ) { @@ -280,7 +300,8 @@ sub tri2obj { if ( $file =~ m/\.1\.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"; open(OUT, "$command |"); while ( ) { @@ -310,7 +331,8 @@ sub strips { foreach $file ( @FILES ) { chop($file); 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"; open(OUT, "$command |"); while ( ) { @@ -348,7 +370,8 @@ sub fixobj { $newfile = $file; $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"; open(OUT, "$command |"); while ( ) { @@ -364,6 +387,11 @@ sub fixobj { #--------------------------------------------------------------------------- # $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 # Updated to reflect some minor tool reorganization and the creation of class # to handle DEM processing needs.