gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 7ac0c80a: Library (ds9.c): account for DS9 opt


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 7ac0c80a: Library (ds9.c): account for DS9 options after polygon definition
Date: Mon, 7 Feb 2022 07:55:24 -0500 (EST)

branch: master
commit 7ac0c80a1378ad004e5385f65801def1aed61bb5
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Library (ds9.c): account for DS9 options after polygon definition
    
    Until now, when the 'ds9.c' library was reading for the definition of a
    polygon in the respective line, it expected that it ends with a
    ')'. Otherwise, it would abort the program, and complain about the
    formatting.
    
    This raised problems when the region file contained any user-specified
    non-default metadata (like colors or text) following the line starting with
    'polygon(...)' in the same line (for example '# color=red').
    
    With this commit, instead of simply checking the last character of the line
    (and aborting if its not a ')'), we actually parse the line and stop on the
    first ')'. If we confront a '#' before that, a status variable will be set
    and the parsing will stopt.
---
 NEWS      |  3 +++
 lib/ds9.c | 26 +++++++++++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/NEWS b/NEWS
index 8a61905a..bf46ea6e 100644
--- a/NEWS
+++ b/NEWS
@@ -156,6 +156,9 @@ See the end of the file for license conditions.
               in Julian dates for example) incorrectly read as float32
               (thus loosing precision); reported by Zohreh Ghaffari, fixed
               with help of Pedram Ashofteh Ardakani.
+  bug #61967: DS9 polygon region files not read when they have width and
+              color; reported by Zohreh Ghaffari, fixed by Pedram Ashofteh
+              Ardakani.
 
 
 
diff --git a/lib/ds9.c b/lib/ds9.c
index e90bd7b7..9f855786 100644
--- a/lib/ds9.c
+++ b/lib/ds9.c
@@ -5,6 +5,7 @@ This is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <mohammad@akhlaghi.org>
 Contributing author(s):
+     Pedram Ashofteh Ardakani <pedramardakani@pm.me>
 Copyright (C) 2015-2022 Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
@@ -45,7 +46,8 @@ gal_ds9_reg_read_polygon(char *filename)
   FILE *fp;
   char *polygonstr;
   gal_data_t *out=NULL;
-  size_t commacounter=0;
+  size_t i, commacounter=0;
+  int good_polygon_format=1;
   size_t plinelen, linesize=10, lineno=0;
   int coordmode=GAL_DS9_COORD_MODE_INVALID;
   char *c, *line, *ds9regstart="# Region file format: DS9";
@@ -109,14 +111,24 @@ gal_ds9_reg_read_polygon(char *filename)
       if( !strncmp(line, "polygon(", 8) )
         {
           /* Get the line length and check if it is indeed in the proper
-             format. If so, remove the last parenthesis. */
+             format. The format is corrupt if we do not find the matching
+             paranthesis before '#' or the final character. If successful,
+             set status to '1' and ignore the rest.  Here we skip the first
+             8 characters that contain 'polygon('. */
           plinelen=strlen(line);
-          if(line[plinelen-2]==')')
-            line[plinelen-2]='\0';
-          else
+          for(i=8; i<plinelen; ++i)
+            {
+              if(line[i]=='#') { good_polygon_format=0; break; }
+              if(line[i]==')') { line[i]='\0';          break; }
+            }
+
+          /* Check if we have the proper formatting. */
+          if(good_polygon_format==0)
             error_at_line(EXIT_FAILURE, 0, filename, lineno,
-                          "line with polygon vertices doesn't end "
-                          "with ')'. %s", polygonformaterr);
+                          "line with polygon vertices couldn't be "
+                          "parsed: no closing parenthesis could be"
+                          "found at the end, or before a '#'. %s",
+                          polygonformaterr);
 
           /* Convert the string to the expected format (with ':' separating
              each vertice). Note how we are ignoring the first 8 characters



reply via email to

[Prev in Thread] Current Thread [Next in Thread]