Skip to content

Commit c5feba5

Browse files
committed
Merge pull request #143 from confluence/develop
Temporarily set numeric locale to C before using AST to parse a FITS …
2 parents dd73c62 + 133ee65 commit c5feba5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

carta/cpp/plugins/WcsPlotter/AstGridPlotter.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "grfdriver.h"
44

55
#include <string.h>
6+
#include <locale.h>
67
extern "C" {
78
#include <ast.h>
89
};
@@ -433,6 +434,14 @@ AstGridPlotter::plot()
433434
grfGlobals()-> vgComposer = m_vgc;
434435
// pre-cache some things
435436
grfGlobals()-> prepare();
437+
438+
// Temporarily override numeric locale, otherwise AST will fail to
439+
// parse floating point numbers in the FITS header if the user's
440+
// locale uses a comma as a decimal separator. Back up the old
441+
// locale so that we can switch back afterwards and minimise impact
442+
// on the rest of the application.
443+
444+
std::string oldLocale = setlocale(LC_NUMERIC, "C");
436445

437446
// get rid of any ast errors from previous calls, just in case
438447
astClearStatus;
@@ -572,6 +581,10 @@ AstGridPlotter::plot()
572581
plot = (AstPlot *) astAnnul( plot );
573582
wcsinfo = (AstFrameSet *) astAnnul( wcsinfo );
574583
fitschan = (AstFitsChan *) astAnnul( fitschan );
584+
585+
// Restore previous numeric locale
586+
587+
setlocale(LC_NUMERIC, oldLocale.c_str());
575588

576589
return true;
577590
} // plot

0 commit comments

Comments
 (0)