From dde5a64a7548baaedeb7c64b9ea4303948d834ef Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 10 Nov 2005 16:26:59 +0000 Subject: [PATCH] A couple updates to the FGArray API. --- src/Lib/Array/array.cxx | 45 +++++++++++++++++++++++++++++++++++++++-- src/Lib/Array/array.hxx | 17 +++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/Lib/Array/array.cxx b/src/Lib/Array/array.cxx index 6d1cab8b..c024ece8 100644 --- a/src/Lib/Array/array.cxx +++ b/src/Lib/Array/array.cxx @@ -45,14 +45,20 @@ SG_USING_STD(cout); SG_USING_STD(endl); -TGArray::TGArray( void ) { +TGArray::TGArray( void ): + array_in(NULL), + fitted_in(NULL) +{ // cout << "class TGArray CONstructor called." << endl; in_data = new int[ARRAY_SIZE_1][ARRAY_SIZE_1]; // out_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1]; } -TGArray::TGArray( const string &file ) { +TGArray::TGArray( const string &file ): + array_in(NULL), + fitted_in(NULL) +{ // cout << "class TGArray CONstructor called." << endl; in_data = new int[ARRAY_SIZE_1][ARRAY_SIZE_1]; // out_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1]; @@ -171,6 +177,41 @@ TGArray::parse( SGBucket& b ) { } +// write an Array file +bool TGArray::write( const string root_dir, SGBucket& b ) { + // generate output file name + string base = b.gen_base_path(); + string path = root_dir + "/" + base; +#ifdef _MSC_VER + fg_mkdir( path.c_str() ); +#else + string command = "mkdir -p " + path; + system( command.c_str() ); +#endif + + string array_file = path + "/" + b.gen_index_str() + ".arr.new.gz"; + cout << "array_file = " << array_file << endl; + + // write the file + gzFile fp; + if ( (fp = gzopen( array_file.c_str(), "wb9" )) == NULL ) { + cout << "ERROR: cannot open " << array_file << " for writing!" << endl; + return false; + } + + cout << "origin = " << originx << ", " << originy << endl; + gzprintf( fp, "%d %d\n", (int)originx, (int)originy ); + gzprintf( fp, "%d %d %d %d\n", cols, (int)col_step, rows, (int)row_step ); + for ( int i = 0; i < cols; ++i ) { + for ( int j = 0; j < rows; ++j ) { + gzprintf( fp, "%d ", (int)in_data[i][j] ); + } + gzprintf( fp, "\n" ); + } + gzclose(fp); + + return true; +} // do our best to remove voids by picking data from the nearest neighbor. diff --git a/src/Lib/Array/array.hxx b/src/Lib/Array/array.hxx index f8541686..5a3f0936 100644 --- a/src/Lib/Array/array.hxx +++ b/src/Lib/Array/array.hxx @@ -86,7 +86,16 @@ public: ~TGArray( void ); // open an Array file (use "-" if input is coming from stdin) - bool open ( const string& file_based ); + bool open ( const string& file_base ); + + // return if array was successfully opened or not + inline bool is_open() { + if ( array_in != NULL ) { + return array_in->is_open(); + } else { + return false; + } + } // close a Array file bool close(); @@ -94,6 +103,9 @@ public: // parse a Array file bool parse( SGBucket& b ); + // write an Array file + bool write( const string root_dir, SGBucket& b ); + // do our best to remove voids by picking data from the nearest // neighbor. void remove_voids(); @@ -126,6 +138,9 @@ public: inline int get_array_elev( int col, int row ) { return in_data[col][row]; } + inline void set_array_elev( int col, int row, int val ) { + in_data[col][row] = val; + } inline Point3D get_fitted_pt( int i ) { return fitted_list[i]; }