]> git.mxchange.org Git - flightgear.git/blobdiff - DEM/dem.cxx
Tweaks to use newbucket.hxx
[flightgear.git] / DEM / dem.cxx
index 27497f2d862065ff9d15abfeaed5f8cc9aabb43a..02d6ea16ed9dd3492617651b9de371b288e6902b 100644 (file)
 #  include <config.h>
 #endif
 
+#include <Include/compiler.h>
+
 #include <ctype.h>    // isspace()
 #include <stdlib.h>   // atoi()
 #include <math.h>     // rint()
 #include <stdio.h>
 #include <string.h>
-#include <sys/stat.h> // stat()
-#include <errno.h>
+#ifdef HAVE_SYS_STAT_H
+#  include <sys/stat.h> // stat()
+#endif
+#ifdef FG_HAVE_STD_INCLUDES
+#  include <cerrno>
+#else
+#  include <errno.h>
+#endif
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>   // stat()
 #endif
 #include <string>
 
+#include STL_IOSTREAM
+
 // #include <zlib/zlib.h>
 #include <Misc/fgstream.hxx>
 #include <Misc/strutils.hxx>
@@ -54,6 +64,7 @@ FG_USING_NAMESPACE(std);
 
 #define MAX_EX_NODES 10000
 
+#if 0
 #ifdef WIN32
 # ifdef __BORLANDC__
 #  include <dir.h>
@@ -62,59 +73,24 @@ FG_USING_NAMESPACE(std);
 #  define MKDIR(a) mkdir(a,S_IRWXU)  // I am just guessing at this flag (NHV)
 # endif // __BORLANDC__
 #endif // WIN32
+#endif //0
 
 
 fgDEM::fgDEM( void ) {
-    // printf("class fgDEM CONstructor called.\n");
+    // cout << "class fgDEM CONstructor called." << endl;
     dem_data = new float[DEM_SIZE_1][DEM_SIZE_1];
     output_data = new float[DEM_SIZE_1][DEM_SIZE_1];
 }
 
 
-#ifdef WIN32
-
-// return the file path name ( foo/bar/file.ext = foo/bar )
-static void extract_path ( const 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
-static int my_mkdir (const 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);
-    }
+fgDEM::fgDEM( const string &file ) {
+    // cout << "class fgDEM CONstructor called." << endl;
+    dem_data = new float[DEM_SIZE_1][DEM_SIZE_1];
+    output_data = new float[DEM_SIZE_1][DEM_SIZE_1];
 
-    return (result);
+    fgDEM::open(file);
 }
 
-#endif // WIN32
-
 
 // open a DEM file
 int fgDEM::open ( const string& file ) {
@@ -152,7 +128,7 @@ int fgDEM::close () {
 string fgDEM::next_token() {
     string token;
 
-    in->stream() >> token;
+    *in >> token;
 
     // cout << "    returning " + token + "\n";
 
@@ -163,8 +139,8 @@ string fgDEM::next_token() {
 // return next integer from input stream
 int fgDEM::next_int() {
     int result;
-
-    in->stream() >> result;
+    
+    *in >> result;
 
     return result;
 }
@@ -174,7 +150,7 @@ int fgDEM::next_int() {
 double fgDEM::next_double() {
     double result;
 
-    in->stream() >> result;
+    *in >> result;
 
     return result;
 }
@@ -239,7 +215,7 @@ int fgDEM::read_a_record() {
     }
   
     // clean off the trailing whitespace
-    name = trim(name, " ");
+    name = trim(name);
     cout << "    Quad name field: " << name << endl;
 
     // DEM level code, 3 reflects processing by DMA
@@ -265,7 +241,7 @@ int fgDEM::read_a_record() {
 
     // Map projection parameters (ignored)
     for ( i = 0; i < 15; i++ ) {
-       dnum = next_double();
+       dnum = next_exp();
        // printf("%d: %f\n",i,dnum);
     }
 
@@ -331,9 +307,9 @@ int fgDEM::read_a_record() {
     cout << "    length = " << i << "\n";
 
 #if 1
-    inum = atoi( token.substr( 0, 1 ) );
-    row_step = atof( token.substr( 1, 12 ) );
-    col_step = atof( token.substr( 13, 12 ) );
+    inum = atoi( token.substr( 0, i - 36 ) );
+    row_step = atof( token.substr( i - 36, 12 ) );
+    col_step = atof( token.substr( i - 24, 12 ) );
     //token.substr( 25, 12 )
 #else
     ptr = token.c_str() + i - 12;
@@ -548,7 +524,7 @@ double fgDEM::interpolate_altitude( double lon, double lat ) {
 
 
 // Use least squares to fit a simpler data set to dem data
-void fgDEM::fit( double error, fgBUCKET *p ) {
+void fgDEM::fit( double error, const FGBucket& p ) {
     double x[DEM_SIZE_1], y[DEM_SIZE_1];
     double m, b, ave_error, max_error;
     double cury, lasty;
@@ -712,7 +688,8 @@ void fgDEM::outputmesh_set_pt( int i, int j, double value ) {
 // Check for an optional "index.node.ex" file in case there is a .poly
 // file to go along with this node file.  Include these nodes first
 // since they are referenced by position from the .poly file.
-void fgDEM::outputmesh_output_nodes( const string& fg_root, fgBUCKET *p ) {
+void fgDEM::outputmesh_output_nodes( const string& fg_root, const FGBucket& p )
+{
     double exnodes[MAX_EX_NODES][3];
     struct stat stat_buf;
     string dir;
@@ -746,12 +723,13 @@ void fgDEM::outputmesh_output_nodes( const string& fg_root, fgBUCKET *p ) {
     if ( result != 0 && errno == ENOENT ) {
        cout << "Creating directory\n";
 
-#ifndef WIN32
+// #ifndef WIN32
 
        command = "mkdir -p " + dir + "\n";
        system( command.c_str() );
 
-#else // WIN32
+#if 0
+// #else // WIN32
 
        // Cygwin crashes when trying to output to node file
        // explicitly making directory structure seems OK on Win95
@@ -767,7 +745,8 @@ void fgDEM::outputmesh_output_nodes( const string& fg_root, fgBUCKET *p ) {
        dir = fg_root + "/Scenery/" + base_path;
        if (my_mkdir ( dir.c_str() )) { exit (-1); }
 
-#endif // WIN32
+// #endif // WIN32
+#endif //0
 
     } else {
        // assume directory exists
@@ -852,6 +831,31 @@ fgDEM::~fgDEM( void ) {
 
 
 // $Log$
+// Revision 1.24  1999/03/11 23:31:56  curt
+// Tweaks to use newbucket.hxx
+//
+// Revision 1.23  1999/03/10 01:09:12  curt
+// Tweaks to go along with scenery tools overhaul.
+// Added a new constructor that accepts the file name.
+//
+// Revision 1.22  1999/01/19 20:56:56  curt
+// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
+//
+// Revision 1.21  1998/11/06 14:04:32  curt
+// Changes due to updates in fgstream.
+//
+// Revision 1.20  1998/10/28 19:38:20  curt
+// Elliminate some unnecessary win32 specific stuff (by Norman Vine)
+//
+// Revision 1.19  1998/10/22 21:59:19  curt
+// Fixed a couple subtle bugs that resulted from some of my c++ conversions.
+// One bug could cause a segfault on certain input, and the other bug could
+// cause the whole procedure to go balistic and generate huge files (also only
+// on rare input combinations.)
+//
+// Revision 1.18  1998/10/18 01:17:09  curt
+// Point3D tweaks.
+//
 // Revision 1.17  1998/10/16 19:08:12  curt
 // Portability updates from Bernie Bright.
 //