[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 55a59bf8: Fits: --copykeys finds exact match w
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 55a59bf8: Fits: --copykeys finds exact match when given a name |
Date: |
Wed, 30 Aug 2023 07:50:43 -0400 (EDT) |
branch: master
commit 55a59bf8a7dc95a49dc6bb29af5c4ba436f7fb03
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Fits: --copykeys finds exact match when given a name
Until now, when two keywords had the same first characters (for example
'SBLMAGPX' and 'SBLMAG' of MakeCatalog's outputs), and the longer one was
first, if the user gave '--copykeys=SBLMAG', the longer one would be
copied, not the exact match! This happened because we were just checking
the first set of characters.
With this commit, when the first set of characters match, we also check the
next character and only consider it a match when the next one is a SPACE
character or an '=' (showing that the keyword name has finished according
to the FITS standard).
This fixes bug #64610.
---
NEWS | 2 ++
bin/fits/keywords.c | 18 +++++++++++-------
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/NEWS b/NEWS
index 9ef26157..9c95b923 100644
--- a/NEWS
+++ b/NEWS
@@ -193,6 +193,8 @@ See the end of the file for license conditions.
directory.
bug #64545: Accounting for CFITSIO silently appending '.gz' when file
doesn't exist. Reported by Sepideh Eskandarlou.
+ bug #64610: --copykeys of Fits program finds wrong key when the first
+ characters of the keyword names match.
diff --git a/bin/fits/keywords.c b/bin/fits/keywords.c
index 359a55d5..7900249e 100644
--- a/bin/fits/keywords.c
+++ b/bin/fits/keywords.c
@@ -391,7 +391,7 @@ keywords_copykeys_name(struct fitsparams *p, fitsfile *fptr,
char *inkeys, size_t numinkeys,
int *updatechecksum)
{
- size_t i, j;
+ size_t i, j, len;
int status=0, found;
char **strarr=p->copykeysname->array;
@@ -404,18 +404,22 @@ keywords_copykeys_name(struct fitsparams *p, fitsfile
*fptr,
case (and write upper-case), so we'll also ignore case when
comparing.*/
found=0;
+ len=strlen(strarr[i]);
for(j=0;j<numinkeys-1;++j) /* numkeys-1: it includes 'END'. */
{
- /* First check the first few characters, if they don't match, see
- if it stars with 'HIERARCH' (which is placed before long
- keyword names). */
- if( !strncasecmp(strarr[i], &inkeys[j*80], strlen(strarr[i])) )
+ /* Check the first few characters, if they don't match, see if it
+ stars with 'HIERARCH' (which is placed before long keyword
+ names). Note that we want an exact match, so the next
+ character after the keyword name should either be a space
+ character or an equal sign. */
+ if( !strncasecmp(strarr[i], &inkeys[j*80], len)
+ && (inkeys[j*80+len]==' ' || inkeys[j*80+len]=='=') )
found=1;
else
{
if( !strncasecmp("HIERARCH", &inkeys[j*80], 8)
- && !strncasecmp(strarr[i], &inkeys[j*80+9],
- strlen(strarr[i])) )
+ && !strncasecmp(strarr[i], &inkeys[j*80+9], len)
+ && (inkeys[j*80+9+len]==' ' || inkeys[j*80+9+len]=='='))
found=1;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 55a59bf8: Fits: --copykeys finds exact match when given a name,
Mohammad Akhlaghi <=