Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'F' formatting option to savefits.c #26

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
45 changes: 37 additions & 8 deletions src/COREMOD_iofits/savefits.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,14 @@ errno_t saveFITS_opt_trunc(
}

char tmpkwvalstr[81];
COREMOD_iofits_data.FITSIO_status = 0;
switch(imgin.im->kw[kw].type)
{
case 'L':
DEBUG_TRACEPOINT("writing keyword [L] %-8s= %20ld / %s\n",
imgin.im->kw[kw].name,
imgin.im->kw[kw].value.numl,
imgin.im->kw[kw].comment);
COREMOD_iofits_data.FITSIO_status = 0;
fits_update_key(fptr,
TLONG,
imgin.im->kw[kw].name,
Expand All @@ -401,7 +401,6 @@ errno_t saveFITS_opt_trunc(
imgin.im->kw[kw].name,
imgin.im->kw[kw].value.numf,
imgin.im->kw[kw].comment);
COREMOD_iofits_data.FITSIO_status = 0;
fits_update_key(fptr,
TDOUBLE,
imgin.im->kw[kw].name,
Expand All @@ -417,7 +416,6 @@ errno_t saveFITS_opt_trunc(
imgin.im->kw[kw].name,
tmpkwvalstr,
imgin.im->kw[kw].comment);
COREMOD_iofits_data.FITSIO_status = 0;
// MIND THAT WE ADDED SINGLE QUOTES JUST ABOVE IN snprintf!!
if((strncmp("'#TRUE#'", tmpkwvalstr, 8) == 0) ||
(strncmp("'#FALSE#'", tmpkwvalstr, 9) == 0))
Expand All @@ -444,6 +442,23 @@ errno_t saveFITS_opt_trunc(
}
kwcnt++;
break;
case 'F':
snprintf(tmpkwfmtstr, 21, "%%-8s= %s / %%s", kwarray[kwi].format)
snprintf(tmpkwvalstr, 81, tmpkwfmtstr,
kwarray[kwi].name,
kwarray[kwi].value.numf,
kwarray[kwi].comment);

DEBUG_TRACEPOINT("writing keyword [F] %-8s= %s %20g / %s\n",
kwarray[kwi].name,
kwarray[kwi].format,
kwarray[kwi].value.numf,
kwarray[kwi].comment);

fits_update_card(fptr,
kwarray[kwi].name,
tmpkwvalstr,
&COREMOD_iofits_data.FITSIO_status);

default:
break;
Expand All @@ -467,10 +482,11 @@ errno_t saveFITS_opt_trunc(
for(int kwi = 0; kwi < kwarraysize; kwi++)
{
char tmpkwvalstr[81];
char tmpkwfmtstr[21];
COREMOD_iofits_data.FITSIO_status = 0;
switch(kwarray[kwi].type)
{
case 'L':
COREMOD_iofits_data.FITSIO_status = 0;
fits_update_key(fptr,
TLONG,
kwarray[kwi].name,
Expand All @@ -480,7 +496,6 @@ errno_t saveFITS_opt_trunc(
break;

case 'D':
COREMOD_iofits_data.FITSIO_status = 0;
DEBUG_TRACEPOINT("writing keyword [D] %-8s= %20g / %s\n",
kwarray[kwi].name,
kwarray[kwi].value.numf,
Expand All @@ -492,22 +507,36 @@ errno_t saveFITS_opt_trunc(
kwarray[kwi].comment,
&COREMOD_iofits_data.FITSIO_status);
break;

case 'F':
snprintf(tmpkwfmtstr, 21, "%%-8s= %s / %%s", kwarray[kwi].format)
snprintf(tmpkwvalstr, 81, tmpkwfmtstr,
kwarray[kwi].name,
kwarray[kwi].value.numf,
kwarray[kwi].comment);

DEBUG_TRACEPOINT("writing keyword [F] %-8s= %s %20g / %s\n",
kwarray[kwi].name,
kwarray[kwi].format,
kwarray[kwi].value.numf,
kwarray[kwi].comment);

fits_update_card(fptr,
kwarray[kwi].name,
tmpkwvalstr,
&COREMOD_iofits_data.FITSIO_status);
case 'S':
snprintf(tmpkwvalstr, 81, "'%s'", kwarray[kwi].value.valstr);
DEBUG_TRACEPOINT("writing keyword [S] %-8s= %20s / %s\n",
kwarray[kwi].name,
tmpkwvalstr,
kwarray[kwi].comment);
COREMOD_iofits_data.FITSIO_status = 0;
fits_update_key(fptr,
TSTRING,
kwarray[kwi].name,
kwarray[kwi].value.valstr,
kwarray[kwi].comment,
&COREMOD_iofits_data.FITSIO_status);
break;

default:
break;
}
Expand Down