Skip to content

Commit

Permalink
Handle commas in meca if -A and CSV (#7599)
Browse files Browse the repository at this point in the history
* Handle commas in meca if -A and CSV

WIth -A we examine the trailing text, but if those items are comma-separated then the scanning will fail since the format assumes white-space.  This PR counts commas in trailing text and if 2 we change the scanning.

* Update psmeca.c

* Avoid read-only string changes

* same treatment in pscoupe
  • Loading branch information
PaulWessel authored Jul 3, 2023
1 parent f614331 commit 392dfcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/seis/pscoupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,12 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) {
/* Must examine the trailing text for optional columns: newX, newY and title */
/* newX and newY are not used in pscoupe, but we promised psmeca and pscoupe can use the same input file */
if (has_text) {
n_scanned = sscanf (S->text[row], "%s %s %[^\n]s\n", Xstring, Ystring, event_title);
unsigned int n_comma = gmt_count_char (GMT, S->text[row], ',');
char tmp_buffer[GMT_LEN256] = {""}; /* Local buffer in case S->text is read-only */
strncpy (tmp_buffer, S->text[row], GMT_LEN256);
if (n_comma == 2) /* CSV file so we must handle that */
gmt_strrepc (tmp_buffer, ',', ' ');
n_scanned = sscanf (tmp_buffer, "%s %s %[^\n]s\n", Xstring, Ystring, event_title);
if (n_scanned >= 2) { /* Got new x,y coordinates and possibly event title */
unsigned int type;
if (GMT->current.setting.io_lonlat_toggle[GMT_IN]) { /* Expect lat lon but watch for junk */
Expand Down
7 changes: 6 additions & 1 deletion src/seis/psmeca.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,12 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {

/* Must examine the trailing text for optional columns: newX, newY and title */
if (S->text && S->text[row]) {
n_scanned = sscanf (S->text[row], "%s %s %[^\n]s\n", Xstring, Ystring, event_title);
unsigned int n_comma = gmt_count_char (GMT, S->text[row], ',');
char tmp_buffer[GMT_LEN256] = {""}; /* Local buffer in case S->text is read-only */
strncpy (tmp_buffer, S->text[row], GMT_LEN256);
if (n_comma == 2) /* CSV file so we must handle that */
gmt_strrepc (tmp_buffer, ',', ' ');
n_scanned = sscanf (tmp_buffer, "%s %s %[^\n]s\n", Xstring, Ystring, event_title);
if (n_scanned >= 2) { /* Got new x,y coordinates and possibly event title */
unsigned int type;
if (GMT->current.setting.io_lonlat_toggle[GMT_IN]) { /* Expect lat lon but watch for junk */
Expand Down

0 comments on commit 392dfcc

Please sign in to comment.