Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions docs/c-library-bugs.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/c-library-bugs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Each program here reproduces one or more entries of [`../c-library-bugs.md`](../
| `selectormap_merge` | none | Two equal 1-D SelectorMaps in series simplify to a UnitMap |
| `tab_missing_table` | none, or `first` | Reading a `-TAB` header whose table is missing annuls a UnitMap twice |
| `switchmap_selector` | none | SwitchMap converts selector values outside the `int` range to `int` |
| `unitnormmap_bad_centre` | none | A UnitNormMap with a bad centre writes outside its output |
| `xphmap_off_grid` | none | An XphMap accepts positions up to a facet left of or below its grid |
| `chebymap_polymap_cancel` | none | A ChebyMap cancels with a PolyMap of the same coefficients |
| `chebymap_inverted_domain` | none | `astChebyDomain` of an inverted ChebyMap with different numbers of inputs and outputs |
| `chebymap_sip` | none | A ChebyMap is written as SIP coefficients of powers |
| `merge_invert` | none | Simplifying a CmpMap changes the Invert attribute of a component it holds |
| `cmpmap_equal_shared` | none | Comparing two CmpMaps that share a component gives a wrong answer and changes the component |

`resample_rebin` reads the cases of a file, one per line; its header comment describes the fields.

Expand Down
51 changes: 51 additions & 0 deletions docs/c-library-bugs/chebymap_inverted_domain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* chebymap_inverted_domain: astChebyDomain of an inverted ChebyMap with
different numbers of inputs and outputs. ChebyDomain chooses the box
of the ChebyMap as created that the requested direction of the inverted
ChebyMap uses, but takes its number of axes from the inverted ChebyMap
(astGetNin for one branch and astGetNout for the other) where it should
take that of the box. For ChebyMap(1, 2) with both boxes, inverted,
forward gives one bound where the box and the caller's arrays have two,
and inverse reads two values of the one-axis forward box, beyond its
end. For a forward-only ChebyMap(2, 1), inverted, forward asks
astMapBox for output 2 of a Mapping with one, and fails with
AST__BADCI. The arrays are filled with -77 first, so an unwritten
bound shows as -77. */
#include <stdio.h>
#include "ast.h"

static void domain( AstChebyMap *c, int forward ) {
double lb[ 2 ] = { -77, -77 }, ub[ 2 ] = { -77, -77 };
int n = astGetI( c, forward ? "Nin" : "Nout" );
astChebyDomain( c, forward, lb, ub );
printf( "forward %d axes %d: %g %g : %g %g status %d\n", forward, n, lb[ 0 ], lb[ 1 ],
ub[ 0 ], ub[ 1 ], astStatus );
astClearStatus;
}

int main( void ) {
int status = 0;
double fc[] = { 1.0, 1, 1, 2.0, 2, 1 };
double ic[] = { 1.0, 1, 1, 0 };
double flb[] = { 0 }, fub[] = { 10 }, ilb[] = { -1, -2 }, iub[] = { 1, 2 };
double fc2[] = { 1.0, 1, 1, 0, 1.0, 1, 0, 1 };
double lb2[] = { 0, 0 }, ub2[] = { 1, 1 };
astWatch( &status );
setvbuf( stdout, NULL, _IONBF, 0 );
AstChebyMap *c = astChebyMap( 1, 2, 2, fc, 1, ic, flb, fub, ilb, iub, " " );
printf( "ChebyMap(1, 2), both boxes\n" );
domain( c, 1 );
domain( c, 0 );
astInvert( c );
printf( "inverted\n" );
domain( c, 1 );
domain( c, 0 );
AstChebyMap *d = astChebyMap( 2, 1, 2, fc2, 0, NULL, lb2, ub2, NULL, NULL, " " );
printf( "ChebyMap(2, 1), forward box only\n" );
domain( d, 1 );
domain( d, 0 );
astInvert( d );
printf( "inverted\n" );
domain( d, 1 );
domain( d, 0 );
return 0;
}
38 changes: 38 additions & 0 deletions docs/c-library-bugs/chebymap_polymap_cancel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* chebymap_polymap_cancel: a ChebyMap followed by an inverted PolyMap with
the same coefficients simplifies to a UnitMap. PolyMap's MapMerge
cancels a PolyMap with a neighbouring PolyMap applied the other way when
astEqual finds them equal, and a ChebyMap is a PolyMap. ChebyMap's Equal
calls PolyMap's, which compares only the coefficients, and compares the
bounding boxes only when the second Object is a ChebyMap too, so the
ChebyMap 1 + T1(x') + 0.5 T2(x') over [0, 10] and the PolyMap
1 + x + 0.5 x^2 are equal, and the pair, which maps 0 to -0.96875, is
replaced by a UnitMap, which maps 0 to 0. The other order, the PolyMap
nominated first, is replaced too. */
#include <stdio.h>
#include "ast.h"

int main( void ) {
int status = 0;
double c[] = { 1.0, 1, 0, 1.0, 1, 1, 0.5, 1, 2 };
double lb = 0.0, ub = 10.0;
double x[ 3 ] = { 0.0, 5.0, 10.0 }, y[ 3 ], z[ 3 ];
astWatch( &status );
AstChebyMap *cm = astChebyMap( 1, 1, 3, c, 0, NULL, &lb, &ub, NULL, NULL, " " );
AstPolyMap *pm = astPolyMap( 1, 1, 3, c, 0, NULL, " " );
printf( "equal %d %d\n", astEqual( cm, pm ), astEqual( pm, cm ) );
astInvert( pm );
AstMapping *pair = (AstMapping *) astCmpMap( cm, pm, 1, " " );
AstMapping *simp = astSimplify( pair );
printf( "simplified class %s\n", astGetC( simp, "Class" ) );
astTran1( pair, 3, x, 1, y );
astTran1( simp, 3, x, 1, z );
for( int i = 0; i < 3; i++ ) {
printf( "x %.17g: pair %.17g simplified %.17g\n", x[ i ], y[ i ], z[ i ] );
}
astInvert( pm );
astInvert( cm );
simp = astSimplify( astCmpMap( pm, cm, 1, " " ) );
printf( "reversed simplified class %s\n", astGetC( simp, "Class" ) );
printf( "status %d\n", status );
return 0;
}
68 changes: 68 additions & 0 deletions docs/c-library-bugs/chebymap_sip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* chebymap_sip: a FrameSet whose pixel to sky Mapping holds a ChebyMap is
written as a FITS-WCS SIP header that does not describe it. SIPIntWorld
takes the first Mapping for which astIsAPolyMap holds, and a ChebyMap is
a PolyMap; AnalysePoly, which needs an iterative inverse, gives up, but
SIPIntWorld goes on and stores the coefficients astPolyCoeffs gives, so
the Chebyshev coefficients of the ChebyMap, which apply to the inputs
normalised to its bounding box, are written as SIP's coefficients of
powers of the pixel offsets. The ChebyMap here is
u = 50 T1(x/50) + 5 T2(x/50), v = 50 T1(y/50) + 3 T2(y/50) over
[-50, 50], that is u = x + 5 (2 (x/50)^2 - 1); the header has
A_1_0 = 49 and A_2_0 = 5 where u - x = 0.004 x^2 - 5. Reading the
header back gives sky positions far from the FrameSet's. The same
FrameSet with a MathMap of the same transformation in place of the
ChebyMap is not written at all (the last line, "MathMap written 0"). */
#include <stdio.h>
#include "ast.h"

int main( void ) {
int status = 0;
double fc[] = { 50.0, 1, 1, 0, 5.0, 1, 2, 0, 50.0, 2, 0, 1, 3.0, 2, 0, 2 };
double ic[] = { 50.0, 1, 1, 0, -5.0, 1, 2, 0, 50.0, 2, 0, 1, -3.0, 2, 0, 2 };
double flb[] = { -50, -50 }, fub[] = { 50, 50 }, ilb[] = { -60, -60 }, iub[] = { 60, 60 };
double sh[] = { -50, -50 };
double x[ 2 ] = { 1.0, 90.0 }, y[ 2 ] = { 1.0, 30.0 }, a[ 2 ], b[ 2 ], c[ 2 ], d[ 2 ];
char card[ 81 ];
astWatch( &status );
AstChebyMap *cm = astChebyMap( 2, 2, 4, fc, 4, ic, flb, fub, ilb, iub, " " );
AstMapping *shift = (AstMapping *) astShiftMap( 2, sh, " " );
AstMapping *zoom = (AstMapping *) astZoomMap( 2, 1.0/3600*AST__DD2R, " " );
AstWcsMap *tan = astWcsMap( 2, AST__TAN, 1, 2, " " );
astInvert( tan );
AstMapping *m = (AstMapping *) astCmpMap( astCmpMap( astCmpMap( shift, cm, 1, " " ), zoom, 1, " " ),
tan, 1, " " );
AstFrameSet *fs = astFrameSet( astFrame( 2, " " ), " " );
astAddFrame( fs, AST__BASE, m, astSkyFrame( " " ) );
AstFitsChan *fch = astFitsChan( NULL, NULL, " " );
astPutFits( fch, "NAXIS1 = 100", 0 );
astPutFits( fch, "NAXIS2 = 100", 0 );
astSet( fch, "Encoding=FITS-WCS" );
printf( "written %d\n", astWrite( fch, fs ) );
astClear( fch, "Card" );
while( astFindFits( fch, "%f", card, 1 ) ) {
if( card[ 0 ] == 'A' || card[ 0 ] == 'B' || card[ 0 ] == 'C' ) printf( "%.30s\n", card );
}
astClear( fch, "Card" );
AstFrameSet *back = astRead( fch );
astTran2( fs, 2, x, y, 1, a, b );
astTran2( back, 2, x, y, 1, c, d );
for( int i = 0; i < 2; i++ ) {
printf( "pixel %g %g: FrameSet %.10g %.10g header %.10g %.10g\n", x[ i ], y[ i ], a[ i ], b[ i ],
c[ i ], d[ i ] );
}
printf( "status %d\n", status );

const char *fwd[] = { "u = x + 5*(2*(x/50)*(x/50) - 1)", "v = y + 3*(2*(y/50)*(y/50) - 1)" };
const char *inv[] = { "x = u", "y = v" };
AstMapping *mm = (AstMapping *) astMathMap( 2, 2, 2, fwd, 2, inv, " " );
m = (AstMapping *) astCmpMap( astCmpMap( astCmpMap( shift, mm, 1, " " ), zoom, 1, " " ), tan, 1, " " );
fs = astFrameSet( astFrame( 2, " " ), " " );
astAddFrame( fs, AST__BASE, m, astSkyFrame( " " ) );
fch = astFitsChan( NULL, NULL, " " );
astPutFits( fch, "NAXIS1 = 100", 0 );
astPutFits( fch, "NAXIS2 = 100", 0 );
astSet( fch, "Encoding=FITS-WCS" );
int written = astWrite( fch, fs );
printf( "MathMap written %d ncard %d status %d\n", written, astGetI( fch, "Ncard" ), status );
return 0;
}
45 changes: 45 additions & 0 deletions docs/c-library-bugs/cmpmap_equal_shared.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* cmpmap_equal_shared: comparing two CmpMaps that hold the same component
object gives a wrong answer and changes that object. CmpMap's Equal
(cmpmap.c), without its expanded lists, sets each component's Invert
attribute to the value its list gives, calls astEqual, and sets the
attributes back in the same order. When the two components are one
object, astEqual (object.c) returns 1 at once, whatever Invert values
the two lists apply it with, and the object is left with the first
list's value, set where it may have been unset.

c1 is the series CmpMap of a ZoomMap a (factor 2) and a UnitMap; c2 is
the same with a inverted when c2 was made, so c1 doubles and c2 halves.
a is inverted back before the comparison. */
#include <stdio.h>
#include "ast.h"

int main( void ) {
AstZoomMap *a;
AstUnitMap *u;
AstCmpMap *c1, *c2;
double in = 1.0, out1, out2;
int equal;

astBegin;
a = astZoomMap( 1, 2.0, " " );
u = astUnitMap( 1, " " );
c1 = astCmpMap( a, u, 1, " " );
astInvert( a );
c2 = astCmpMap( a, u, 1, " " );
astInvert( a );
astClear( a, "Invert" );

astTran1( c1, 1, &in, 1, &out1 );
astTran1( c2, 1, &in, 1, &out2 );
printf( "before: c1(1) = %g, c2(1) = %g, a Invert %d, set %d\n", out1, out2,
astGetI( a, "Invert" ), astTest( a, "Invert" ) );

equal = astEqual( c1, c2 );
printf( "astEqual(c1, c2) = %d\n", equal );
printf( "after: a Invert %d, set %d\n", astGetI( a, "Invert" ),
astTest( a, "Invert" ) );

astEnd;
printf( "status %d\n", astOK ? 0 : astStatus );
return 0;
}
116 changes: 116 additions & 0 deletions docs/c-library-bugs/merge_invert.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/* merge_invert: simplifying a CmpMap changes the Invert attribute of a
component Mapping the caller holds. The merge list of an inverted
CmpMap applies each component with the opposite of its own Invert
value. SplineMap's MapMerge (splinemap.c) sets the nominated
SplineMap's Invert attribute to the list's value and annuls its pointer
without setting it back when the SplineMap cancels with its inverse;
DssMap's MapMerge (dssmap.c) does the same to a WinMap it absorbs. The
list holds clones, so the caller's Mapping itself is changed.

SplineMap: the inverse of the series CmpMap of a SplineMap and the
inverse of an equal SplineMap b, simplified, leaves b with Invert 0.
The SplineMap is u = 2x, v = 3y over the unit square
(testsplinemap_c.c).

DssMap: the inverse of the series CmpMap of an inverted DssMap and an
inverted WinMap w, simplified, leaves w with Invert 0. The DssMap is
the plate solution of ast_tester's serialisation/c_dssmap.ast, with
whole pixel offsets so that the WinMap can be absorbed. */
#include <stdio.h>
#include "ast.h"

static void show( const char *when, const char *name, AstMapping *m, double x, double y ) {
double u, v;
astTran2( m, 1, &x, &y, 1, &u, &v );
printf( "%s: %s Invert %d, %s forward (%g, %g) -> (%g, %g)\n", when, name,
astGetI( m, "Invert" ), name, x, y, u, v );
}

static const char *dssmap =
" Begin DssMap\n"
" Nin = 2\n"
" IsA Mapping\n"
" PltRA = 2.8272374655684112\n"
" PltDec = -1.0518122540502668\n"
" PltScl = 67.200000000000003\n"
" CNPix1 = 4200\n"
" CNPix2 = 4200\n"
" XPixSz = 25.263000000000002\n"
" YPixSz = 25.263000000000002\n"
" PPO1 = 0\n"
" PPO2 = 0\n"
" PPO3 = 105990.5119\n"
" PPO4 = 0\n"
" PPO5 = 0\n"
" PPO6 = 105990.5119\n"
" AMDX1 = 67.152600000000007\n"
" AMDX2 = 0.0051200000000000004\n"
" AMDX3 = -288.40899999999999\n"
" AMDX4 = -8.8400000000000001e-06\n"
" AMDX5 = -2.9300000000000001e-05\n"
" AMDX6 = 3.9099999999999998e-06\n"
" AMDX7 = -4.16e-06\n"
" AMDX8 = -9.7500000000000005e-10\n"
" AMDX9 = 3.2600000000000001e-10\n"
" AMDX10 = 7.78e-10\n"
" AMDX11 = 2.0700000000000001e-10\n"
" AMDX12 = 5.5500000000000001e-09\n"
" AMDX13 = 1.4899999999999999e-12\n"
" AMDX14 = 0\n"
" AMDX15 = 0\n"
" AMDX16 = 0\n"
" AMDX17 = 0\n"
" AMDX18 = 0\n"
" AMDX19 = 0\n"
" AMDY1 = 67.154200000000003\n"
" AMDY2 = -0.0038300000000000001\n"
" AMDY3 = 191.56200000000001\n"
" AMDY4 = -2.12e-05\n"
" AMDY5 = -2.9200000000000002e-05\n"
" AMDY6 = -9.4399999999999994e-06\n"
" AMDY7 = -4.1400000000000002e-06\n"
" AMDY8 = 6.6699999999999997e-10\n"
" AMDY9 = 6.9399999999999998e-10\n"
" AMDY10 = -2.0800000000000001e-10\n"
" AMDY11 = -1.2e-09\n"
" AMDY12 = 5.5599999999999998e-09\n"
" AMDY13 = 1.5000000000000001e-12\n"
" AMDY14 = 0\n"
" AMDY15 = 0\n"
" AMDY16 = 0\n"
" AMDY17 = 0\n"
" AMDY18 = 0\n"
" AMDY19 = 0\n"
" End DssMap\n";

int main( void ) {
int status = 0;
double tk[ 4 ] = { 0.0, 0.0, 1.0, 1.0 };
double cu[ 4 ] = { 0.0, 0.0, 2.0, 2.0 };
double cv[ 4 ] = { 0.0, 3.0, 0.0, 3.0 };
double ina[ 2 ] = { 0.0, 0.0 }, inb[ 2 ] = { 1.0, 1.0 };
double outa[ 2 ] = { -0.5, -0.5 }, outb[ 2 ] = { 1.5, 1.5 };
astWatch( &status );
setvbuf( stdout, NULL, _IONBF, 0 );

AstSplineMap *a = astSplineMap( 2, 2, 2, 2, tk, tk, cu, cv, " " );
AstSplineMap *b = astSplineMap( 2, 2, 2, 2, tk, tk, cu, cv, " " );
astInvert( b );
AstCmpMap *cmp = astCmpMap( a, b, 1, " " );
astInvert( cmp );
show( "before", "b", (AstMapping *) b, 0.5, 0.6 );
printf( "simplified class %s\n", astGetC( astSimplify( cmp ), "Class" ) );
show( "after", "b", (AstMapping *) b, 0.5, 0.6 );

AstMapping *d = (AstMapping *) astFromString( dssmap );
AstWinMap *w = astWinMap( 2, ina, inb, outa, outb, " " );
astInvert( d );
astInvert( w );
cmp = astCmpMap( d, w, 1, " " );
astInvert( cmp );
show( "before", "w", (AstMapping *) w, 1.0, 1.0 );
printf( "simplified class %s\n", astGetC( astSimplify( cmp ), "Class" ) );
show( "after", "w", (AstMapping *) w, 1.0, 1.0 );
printf( "status %d\n", status );
return 0;
}
24 changes: 24 additions & 0 deletions docs/c-library-bugs/unitnormmap_bad_centre.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* unitnormmap_bad_centre: a 1-D UnitNormMap whose centre is AST__BAD,
transforming three points forward. Transform's bad-centre branch
sets ptr_out[ point ][ coord_out ], the indices exchanged, so for the
third point it reads ptr_out[ 2 ], past the end of the array of two
output coordinate pointers (AddressSanitizer: a READ of size 8), and
it would write past the end of a coordinate's values were there more
output coordinates than points. */
#include <stdio.h>
#include "ast.h"

int main( void ) {
int status = 0;
astWatch( &status );
double centre[ 1 ] = { AST__BAD };
AstUnitNormMap *m = astUnitNormMap( 1, centre, " " );
double in[ 3 ] = { 1.0, 2.0, 3.0 };
double out[ 2 ][ 3 ] = { { 7.0, 7.0, 7.0 }, { 7.0, 7.0, 7.0 } };
astTranN( m, 3, 1, 3, in, 1, 2, 3, &out[ 0 ][ 0 ] );
for( int k = 0; k < 3; k++ ) {
printf( "%.17g -> %.17g %.17g\n", in[ k ], out[ 0 ][ k ], out[ 1 ][ k ] );
}
printf( "status %d\n", status );
return 0;
}
34 changes: 34 additions & 0 deletions docs/c-library-bugs/xphmap_off_grid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* xphmap_off_grid: positions left of or below the HEALPix grid that an
XphMap accepts as positions in its bottom-left facets. Transform finds
a position's facet indices by dividing its zero-based cell indices by
the facet size, nppf, in integer arithmetic, which rounds towards zero,
so cell indices from -(nppf - 1) to -1 give facet index 0 and the
position passes the test on the facet indices. At order 1 (nppf 2),
(0, 4) is in cell (-1, 3), which is outside the grid, yet HPX12 forward
copies it and HPX0 forward moves it to (4, 8); at order 2 (nppf 4),
(-2, 8.5), three cells left of the grid, is copied too. A position one
more cell to the left, (-3, 8.5), is bad. */
#include <stdio.h>
#include "ast.h"

static void show( int order, const char *type, double x, double y ) {
char dump[ 256 ];
double u, v;
snprintf( dump, sizeof dump, " Begin XphMap\n Nin = 2\n IsA Mapping\n"
" Order = %d\n Type = \"%s\"\n End XphMap\n", order, type );
AstMapping *m = astFromString( dump );
astTran2( m, 1, &x, &y, 1, &u, &v );
printf( "order %d %s forward %.17g %.17g -> %.17g %.17g\n", order, type, x, y, u, v );
m = astAnnul( m );
}

int main( void ) {
int status = 0;
astWatch( &status );
show( 1, "HPX12", 0.0, 4.0 );
show( 1, "HPX0", 0.0, 4.0 );
show( 2, "HPX12", -2.0, 8.5 );
show( 2, "HPX12", -3.0, 8.5 );
printf( "status %d\n", status );
return 0;
}
Loading