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: Michael Droetboom, Space Telescope Science Institute,
21      and: Mark Calabretta, Australia Telescope National Facility, CSIRO.
22   http://www.atnf.csiro.au/people/Mark.Calabretta
23   $Id: twcs_locale.c,v 7.7 2021/07/12 06:36:49 mcalabre Exp $
24 *=============================================================================
25 *
26 * twcs_locale tests wcslib's handling of locales, such as fr_FR, that use a
27 * comma as the decimal separator in floating point numbers.  Not part of the
28 * official test suite.
29 *
30 *---------------------------------------------------------------------------*/
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <locale.h>
35 
36 #include "wcs.h"
37 #include "wcserr.h"
38 #include "wcshdr.h"
39 #include "wcsprintf.h"
40 #include "wcsutil.h"
41 
42 #define HEADER_SIZE 36000
43 
main()44 int main()
45 
46 {
47   struct wcsprm *wcs, *wcsp;
48   char header[HEADER_SIZE];
49   size_t real_size;
50   FILE *fd;
51   int nreject, nwcs;
52   int nkeyrec;
53   char *gen_header;
54 
55   wcserr_enable(1);
56   wcsprintf_set(stderr);
57 
58   if ((fd = fopen("pih.fits", "r")) == 0x0) {
59     wcsprintf("\nFailed to open pih.fits, abort.\n");
60     return 1;
61   }
62 
63   setlocale(LC_NUMERIC, "fr_FR");
64   wcsprintf("Parsing pih.fits with locale set to fr_FR.\n");
65 
66   real_size = fread(header, 1, HEADER_SIZE, fd);
67   fclose(fd);
68 
69   if (wcspih(header, real_size / 80, WCSHDR_all, 0, &nreject, &nwcs, &wcs)) {
70     wcsperr(wcs, 0x0);
71     return 1;
72   }
73 
74   // Choose one of the three WCS in this header.
75   wcsp = wcs + 1;
76 
77   if (wcsset(wcsp)) {
78     wcsperr(wcsp, 0x0);
79     return 1;
80   }
81 
82   wcsprintf("\nOutput from wcsprt() with this locale\n"
83               "-------------------------------------\n");
84   wcsprt(wcsp);
85   wcsprintf("\n");
86 
87   wcsprintf("Output from wcshdo() with the same locale\n"
88             "-----------------------------------------\n");
89   wcshdo(1, wcsp, &nkeyrec, &gen_header);
90   printf("%s", gen_header);
91 
92   wcsdealloc(gen_header);
93   wcsvfree(&nwcs, &wcs);
94 
95   return 0;
96 }
97