[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 13fe75cc: library (fits.h): informative error
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 13fe75cc: library (fits.h): informative error when output FITS has parenthesis |
Date: |
Thu, 5 Jun 2025 14:36:09 -0400 (EDT) |
branch: master
commit 13fe75cc44902ef9e23f419d24279a85604af43b
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
library (fits.h): informative error when output FITS has parenthesis
Until now, when an output FITS file had a parenthesis in it, and it didn't
fit CFITSIO's convention for parenthesis, Gnuastro's programs would simply
abort with the cryptic CFITSIO error. This was very hard to understand for
a regular user.
With this commit, when CFITSIO fails to open a FITS file for writing, we
now check for parenthesis in it, and if there is a parenthesis, an
informative text is printed to help the user easily address the problem.
This issue was found with the help of Sepideh Eskandarlou.
---
lib/fits.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/lib/fits.c b/lib/fits.c
index 3d109545..1d3d95b4 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -659,6 +659,7 @@ gal_fits_open_to_write(char *filename)
{
int status=0;
long naxes=0;
+ char *c, *msg;
fitsfile *fptr;
/* When the file exists just open it. Otherwise, create the file. But we
@@ -669,7 +670,28 @@ gal_fits_open_to_write(char *filename)
{
/* Create the file. */
if( fits_create_file(&fptr, filename, &status) )
- gal_fits_io_error(status, NULL);
+ {
+ /* Parse the file name to see if there are parenthesis (for a
+ useful error message to the user). */
+ msg=NULL;
+ for(c=filename; *c!='\0'; ++c)
+ if(*c=='(')
+ {
+ if( asprintf(&msg, "CFITSIO has special meaning for "
+ "a parenthesis in the file name, which "
+ "was not met in the given output file "
+ "name '%s'. Either use a different "
+ "character instead of the parenthesis, "
+ "or make sure it satsfies the usage of "
+ "parenthesis in CFITSIO file name "
+ "convention", filename)<0 )
+ error(EXIT_FAILURE, 0, "%s: could not allocate "
+ "string", __func__);
+ }
+
+ /* Print the standard message. */
+ gal_fits_io_error(status, msg);
+ }
/* Create blank extension. */
if( fits_create_img(fptr, BYTE_IMG, 0, &naxes, &status) )
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 13fe75cc: library (fits.h): informative error when output FITS has parenthesis,
Mohammad Akhlaghi <=