#include <math.h> // rint()
#include <stdio.h>
#include <stdlib.h> // atoi()
+#include <string.h>
#include <sys/stat.h> // stat()
#include <unistd.h> // stat()
#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 ) {
// 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)
// return next double from input stream
-double next_double(FILE *fd) {
+static double next_double(FILE *fd) {
char token[80];
next_token(fd, token);
// 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;
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);
}
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
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;
}
}
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);
}
}
// 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;
}
}
{
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;
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
}
// $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
//
* 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];
}
/* $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.
*
# Rule for TARGET
#---------------------------------------------------------------------------
-$(TARGET): $(OBJECTS)
+$(TARGET): $(OBJECTS) $(FG_ROOT_LIB)/stamp_libs
$(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(LDLIBS)
#---------------------------------------------------------------------------
# $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.
#
-// 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.
//
// $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.
//
(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"
#---------------------------------------------------------------------------
# $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.
| 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.
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) = @_;
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 |");
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 ( <OUT> ) {
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 ( <OUT> ) {
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 ( <OUT> ) {
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 ( <OUT> ) {
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 ( <OUT> ) {
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 ( <OUT> ) {
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 ( <OUT> ) {
$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 ( <OUT> ) {
#---------------------------------------------------------------------------
# $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.