1 /*============================================================================
2   WCSLIB 7.7 - an implementation of the FITS WCS standard.
3   Copyright (C) 1995-2021, Mark Calabretta
4 
5   This file is part of WCSLIB.
6 
7   WCSLIB is free software: you can redistribute it and/or modify it under the
8   terms of the GNU Lesser General Public License as published by the Free
9   Software Foundation, either version 3 of the License, or (at your option)
10   any later version.
11 
12   WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
13   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
15   more details.
16 
17   You should have received a copy of the GNU Lesser General Public License
18   along with WCSLIB.  If not, see http://www.gnu.org/licenses.
19 
20   Author: Mark Calabretta, Australia Telescope National Facility, CSIRO,
21      and: Michael Droetboom, Space Telescope Science Institute
22   http://www.atnf.csiro.au/people/Mark.Calabretta
23   $Id: twcscompare.c,v 7.7 2021/07/12 06:36:49 mcalabre Exp $
24 *=============================================================================
25 *
26 * Test wcscompare().
27 *
28 *---------------------------------------------------------------------------*/
29 
30 #include <stdio.h>
31 #include <string.h>
32 
33 #include <wcs.h>
34 
35 
main()36 int main()
37 
38 {
39   int    cmp, equal, status;
40   struct wcsprm a, b;
41 
42   printf(
43     "Testing WCSLIB comparison routine (twcscompare.c)\n"
44     "-------------------------------------------------\n");
45 
46   a.flag = -1;
47   b.flag = -1;
48   wcsini(1, 2, &a);
49   wcsini(1, 2, &b);
50 
51   if ((status = wcscompare(0, 0.0, &a, &b, &equal))) {
52     printf("wcscompare ERROR %d: %s.\n", status, wcs_errmsg[status]);
53     return 1;
54   } else if (!equal) {
55     printf("FAIL: Equal wcsprms tested unequal.\n");
56     return 1;
57   }
58 
59   strncpy(b.dateobs, "2014-01-01T00:00:00", 72);
60 
61   if ((status = wcscompare(0, 0.0, &a, &b, &equal))) {
62     printf("wcscompare ERROR %d: %s.\n", status, wcs_errmsg[status]);
63     return 1;
64   } else if (equal) {
65     printf("FAIL: Unequal wcsprms tested equal.\n");
66     return 1;
67   }
68 
69   if ((status = wcscompare(WCSCOMPARE_ANCILLARY, 0.0, &a, &b, &equal))) {
70     printf("wcscompare ERROR %d: %s.\n", status, wcs_errmsg[status]);
71     return 1;
72   } else if (!equal) {
73     printf("FAIL: Ancillary keyword not ignored.\n");
74     return 1;
75   }
76 
77   b.crpix[0] = 12.5;
78   b.crpix[1] = 12.5;
79 
80   if ((status = wcscompare(WCSCOMPARE_ANCILLARY, 0.0, &a, &b, &equal))) {
81     printf("wcscompare ERROR %d: %s.\n", status, wcs_errmsg[status]);
82     return 1;
83   } else if (equal) {
84     printf("FAIL: Unequal wcsprms tested equal.\n");
85     return 1;
86   }
87 
88   cmp = WCSCOMPARE_ANCILLARY | WCSCOMPARE_TILING;
89   if ((status = wcscompare(cmp, 0.0, &a, &b, &equal))) {
90     printf("wcscompare ERROR %d: %s.\n", status, wcs_errmsg[status]);
91     return 1;
92   } else if (equal) {
93     printf("FAIL: Non-integral translation equates as a tiling.\n");
94     return 1;
95   }
96 
97   cmp = WCSCOMPARE_ANCILLARY | WCSCOMPARE_CRPIX;
98   if ((status = wcscompare(cmp, 0.0, &a, &b, &equal))) {
99     printf("wcscompare ERROR %d: %s.\n", status, wcs_errmsg[status]);
100     return 1;
101   } else if (!equal) {
102     printf("FAIL: Translation not ignored.\n");
103     return 1;
104   }
105 
106   printf("\nPASS: All comparisons returned as expected.\n");
107 
108   wcsfree(&a);
109   wcsfree(&b);
110 
111   return 0;
112 }
113