diff --git a/data-access/engine/src/common/src/ast4vl.cpp b/data-access/engine/src/common/src/ast4vl.cpp index 09ddadd4c32fa1bd34917e9e05b6a0736934b835..eb8a0bae28eb6a891c9b01d193e38becb80c5a8b 100644 --- a/data-access/engine/src/common/src/ast4vl.cpp +++ b/data-access/engine/src/common/src/ast4vl.cpp @@ -104,6 +104,8 @@ std::vector<Bounds> calc_bounds(std::string header, std::string skysys, std::str * * FIXME add check : 'Domain ?= GRID' where assumption is made that first data point is centered at (1,1) */ + + std::vector<uint_bounds> calc_overlap(const std::string header, const coordinates coord, int& ov_code) { LOG_trace(__func__); @@ -136,6 +138,7 @@ std::vector<uint_bounds> calc_overlap(const std::string header, const coordinate LOG_STREAM << "pix ranges[uint]:"; + int ix = 0; for(double_xy dbl_range : pix_ranges.pixel_ranges) { if(dbl_range.x < 0) @@ -146,36 +149,46 @@ std::vector<uint_bounds> calc_overlap(const std::string header, const coordinate throw out_of_range(string{__FILE__} + ":" + to_string(__LINE__) + " pixel axis from overlap y is negative " + to_string(dbl_range.y)); - // FIXME review conversion double -> uint: result must be: 1 <= result <= NAXISn + // conversion double -> uint: result must be: 1 <= result <= NAXISn // because NAXISn start with 1 (FITS standard) which corresponds to ASTlib's GRID-domain // FitsChan uses GRID Domain for FITS-pixel coords + // in GRID first element represents a pixel-range: [0.5..1.5) (0.5 in pixel_1 ; 1.5 in pixel_2) + // + // dbl-range is checked to be within 0.5 .. NAXIS+0.5 in ast_frameset::overlap() if(dbl_range.x <= dbl_range.y) { - uint_bounds ui_range{lround(dbl_range.x), lround(dbl_range.y), dbl_range.type}; + long lowb = lround(dbl_range.x); + long upb = lround(dbl_range.y); + long NAXISi = frm_set.get_naxis(ix++); + + if(lowb == (NAXISi + 1)) lowb--; + if(upb == (NAXISi + 1)) upb--; + + uint_bounds ui_range{lowb, upb, dbl_range.type}; uint_bounds_vec.push_back(ui_range); LOG_STREAM << " " << ui_range; } else { - uint_bounds ui_range{lround(dbl_range.y), lround(dbl_range.x), dbl_range.type}; + long lowb = lround(dbl_range.y); + long upb = lround(dbl_range.x); + long NAXISi = frm_set.get_naxis(ix++); + + if(lowb == (NAXISi + 1)) lowb--; + if(upb == (NAXISi + 1)) upb--; + + uint_bounds ui_range{lowb, upb, dbl_range.type}; uint_bounds_vec.push_back(ui_range); - LOG_STREAM << " " << ui_range; + LOG_STREAM << "s" << ui_range; } } LOG_STREAM << endl; - LOG_STREAM << "uint_bounds: " << uint_bounds_vec.size() - << " pix_ranges:: " << pix_ranges.pixel_ranges.size() - << endl; - return uint_bounds_vec; } - - - void write_previous2(string header, string filename) { std::ofstream out(filename); diff --git a/data-access/engine/src/common/src/ast_frameset.cpp b/data-access/engine/src/common/src/ast_frameset.cpp index 77316610db730b5be8680b4196dbf76a9e269909..0c4064d23840a480655f6436163d96513360d326 100644 --- a/data-access/engine/src/common/src/ast_frameset.cpp +++ b/data-access/engine/src/common/src/ast_frameset.cpp @@ -147,6 +147,11 @@ ast::frameset::frameset(string header) } +long ast::frameset::get_naxis(int ix) +{ + return m_NAXISn[ix]; +} + bool is_specdomain(AstFrame * frm) { @@ -1082,17 +1087,37 @@ overlap_ranges ast::frameset::overlap(coordinates coord) if ( !astOK || (pixOverlap == AST__NULL) ) throw runtime_error(failed_with_status(__FILE__,__LINE__,"astCmpRegion( header AND coord )")); + AstFrame * pixFrame = (AstFrame*)astGetRegionFrame( pixOverlap ); + if ( !astOK ) + throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetRegionFrame( pixOverlap )")); + + const char * c_domain = astGetC(pixFrame,"Domain"); + string domain{(c_domain==nullptr) ? "<null>" : c_domain}; + if(domain.compare("GRID") != 0) + throw runtime_error("Expects GRID domain but it is: " + domain); + double lbnd[AXES_CNT]; double ubnd[AXES_CNT]; astGetRegionBounds(pixOverlap, lbnd, ubnd); if ( !astOK ) throw runtime_error(failed_with_status(__FILE__,__LINE__,"astGetRegionBounds( pixOverlap )")); - log_bounds("BOUNDS overlap PIX: ", m_NAXIS, lbnd, ubnd); + LOG_STREAM <<"BOUNDS overlap in domain: " << domain << endl; + log_bounds("BOUNDS overlap PIX: ", m_NAXIS, lbnd, ubnd); int ix; - for(ix=0; ix<m_NAXIS; ix++) + for(ix=0; ix<m_NAXIS; ix++) // FIXME why not Naxis ? which can be Naxis > NAXIS { + if(lbnd[ix] < p1[ix]) + throw runtime_error("lower-bound of overlap on pixel-grid less then " + + to_string(p1[ix]) + ": " + to_string(lbnd[ix]) + + " for NAXIS = " + to_string(ix+1)); + + if(ubnd[ix] > (p2[ix]) ) + throw runtime_error("upper-bound of overlap on pixel-grid more then NAXIS[" + + to_string(ix+1) + "] + 0.5 = " + to_string(p1[ix]) + + ": " + to_string(ubnd[ix])); + pix_ranges.push_back({lbnd[ix],ubnd[ix],m_axis_type[ix]}); } } diff --git a/data-access/engine/src/common/src/ast_frameset.hpp b/data-access/engine/src/common/src/ast_frameset.hpp index 73ec69b1aeb4c3755462a7c27232c6dc178c3997..aa8c1110d6a97aff51888b4af5825c3df0efca62 100644 --- a/data-access/engine/src/common/src/ast_frameset.hpp +++ b/data-access/engine/src/common/src/ast_frameset.hpp @@ -24,6 +24,8 @@ class frameset frameset(std::string header); ~frameset(); + long get_naxis(int ix); + bool has_specframe(void); bool has_timeaxis(void);