1
0
Fork 0

- Make the bucket/dem coverage check slightly fuzzy in case of slight

numerical rounding errors.
- Convert several usages of int = 0 or 1 to bool = false or true
This commit is contained in:
curt 2003-06-12 20:01:34 +00:00
parent f7a4a8bfa0
commit 05c765b397
2 changed files with 29 additions and 27 deletions

View file

@ -80,7 +80,7 @@ TGDem::TGDem( const string &file ) {
// open a DEM file // open a DEM file
int bool
TGDem::open ( const string& file ) { TGDem::open ( const string& file ) {
// open input file (or read from stdin) // open input file (or read from stdin)
if ( file == "-" ) { if ( file == "-" ) {
@ -88,28 +88,28 @@ TGDem::open ( const string& file ) {
// fd = stdin; // fd = stdin;
// fd = gzdopen(STDIN_FILENO, "r"); // fd = gzdopen(STDIN_FILENO, "r");
printf("Not yet ported ...\n"); printf("Not yet ported ...\n");
return 0; return false;
} else { } else {
in = new sg_gzifstream( file ); in = new sg_gzifstream( file );
if ( !(*in) ) { if ( !(*in) ) {
cout << "Cannot open " << file << endl; cout << "Cannot open " << file << endl;
return 0; return false;
} }
cout << "Loading DEM data file: " << file << endl; cout << "Loading DEM data file: " << file << endl;
} }
return 1; return true;
} }
// close a DEM file // close a DEM file
int bool
TGDem::close () { TGDem::close () {
// the sg_gzifstream doesn't seem to have a close() // the sg_gzifstream doesn't seem to have a close()
delete in; delete in;
return 1; return true;
} }
@ -172,7 +172,7 @@ TGDem::next_exp() {
// read and parse DEM "A" record // read and parse DEM "A" record
int bool
TGDem::read_a_record() { TGDem::read_a_record() {
int i, inum; int i, inum;
double dnum; double dnum;
@ -194,7 +194,7 @@ TGDem::read_a_record() {
cout << " DEM level code = " << inum << "\n"; cout << " DEM level code = " << inum << "\n";
if ( inum > 3 ) { if ( inum > 3 ) {
return 0; return false;
} }
// Pattern code, 1 indicates a regular elevation pattern // Pattern code, 1 indicates a regular elevation pattern
@ -325,12 +325,12 @@ TGDem::read_a_record() {
in->get(c); in->get(c);
} }
return 1; return true;
} }
// read and parse DEM "B" record // read and parse DEM "B" record
void bool
TGDem::read_b_record( ) { TGDem::read_b_record( ) {
string token; string token;
int i; int i;
@ -377,18 +377,20 @@ TGDem::read_b_record( ) {
dem_data[cur_col][i] = (float)prof_data; dem_data[cur_col][i] = (float)prof_data;
last = prof_data; last = prof_data;
} }
return true;
} }
// parse dem file // parse dem file
int bool
TGDem::parse( ) { TGDem::parse( ) {
int i; int i;
cur_col = 0; cur_col = 0;
if ( !read_a_record() ) { if ( !read_a_record() ) {
return(0); return false;
} }
for ( i = 0; i < dem_num_profiles; i++ ) { for ( i = 0; i < dem_num_profiles; i++ ) {
@ -403,14 +405,14 @@ TGDem::parse( ) {
cout << " Done parsing\n"; cout << " Done parsing\n";
return 1; return true;
} }
// write out the area of data covered by the specified bucket. Data // write out the area of data covered by the specified bucket. Data
// is written out column by column starting at the lower left hand // is written out column by column starting at the lower left hand
// corner. // corner.
int bool
TGDem::write_area( const string& root, SGBucket& b, bool compress ) { TGDem::write_area( const string& root, SGBucket& b, bool compress ) {
// calculate some boundaries // calculate some boundaries
double min_x = ( b.get_center_lon() - 0.5 * b.get_width() ) * 3600.0; double min_x = ( b.get_center_lon() - 0.5 * b.get_width() ) * 3600.0;
@ -436,19 +438,19 @@ TGDem::write_area( const string& root, SGBucket& b, bool compress ) {
// this write_area() routine and feed it buckets that coincide // this write_area() routine and feed it buckets that coincide
// well with the underlying grid structure and spacing. // well with the underlying grid structure and spacing.
if ( ( min_x < originx ) if ( ( min_x < (originx - 0.001) )
|| ( max_x > originx + cols * col_step ) || ( max_x > (originx + cols * col_step + 0.001) )
|| ( min_y < originy ) || ( min_y < (originy - 0.001) )
|| ( max_y > originy + rows * row_step ) ) { || ( max_y > (originy + rows * row_step + 0.001) ) ) {
cout << " ERROR: bucket at least partially outside DEM data range!" << cout << " ERROR: bucket at least partially outside DEM data range!" <<
endl; endl;
return 0; return false;
} }
// If the area is all ocean, skip it. // If the area is all ocean, skip it.
if (!has_non_zero_elev(start_x, span_x, start_y, span_y)) { if (!has_non_zero_elev(start_x, span_x, start_y, span_y)) {
cout << "Tile is all zero elevation: skipping" << endl; cout << "Tile is all zero elevation: skipping" << endl;
return 0; return false;
} }
// generate output file name // generate output file name
@ -487,7 +489,7 @@ TGDem::write_area( const string& root, SGBucket& b, bool compress ) {
system( command.c_str() ); system( command.c_str() );
} }
return 1; return true;
} }

View file

@ -103,24 +103,24 @@ public:
~TGDem(); ~TGDem();
// open a DEM file (use "-" if input is coming from stdin) // open a DEM file (use "-" if input is coming from stdin)
int open ( const string& file ); bool open ( const string& file );
// close a DEM file // close a DEM file
int close(); bool close();
// parse a DEM file // parse a DEM file
int parse(); bool parse();
// read and parse DEM "A" record // read and parse DEM "A" record
int read_a_record(); bool read_a_record();
// read and parse DEM "B" record // read and parse DEM "B" record
void read_b_record(); bool read_b_record();
// write out the area of data covered by the specified bucket. // write out the area of data covered by the specified bucket.
// Data is written out column by column starting at the lower left // Data is written out column by column starting at the lower left
// hand corner. // hand corner.
int write_area( const string& root, SGBucket& b, bool compress ); bool write_area( const string& root, SGBucket& b, bool compress );
// Informational methods // Informational methods
inline double get_originx() const { return originx; } inline double get_originx() const { return originx; }