Skip to content

Commit

Permalink
Handle single array item (#34)
Browse files Browse the repository at this point in the history
* Handle single array item

In order to give an array list with a single value we must end with a comma, otherwise it is seen as a fixed increment.

* Made debug easier

Breaking up some lines
  • Loading branch information
PaulWessel authored and joa-quim committed Aug 25, 2018
1 parent c56a7ee commit 5f12027
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc_classic/rst/source/explain_array.rst_
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ array where *inc* can be 1 (every magnitude), 2, (1, 2, 5 times magnitude) or 3
(1-9 times magnitude). For less than every magnitude, use a negative integer *inc*.
Append **+n** if *inc* is meant to indicate the number of equidistant coordinates
instead. Alternatively, give a *file* with output coordinates in the first column,
or provide a comma-separated *list* of coordinates.
or provide a comma-separated *list* of coordinates. If you only want a *single* value
then you must append a comma to distinguish the list from the setting of *inc*.

If the module allows you to set up an absolute time series, append a valid time unit from the list
**y**\ ear, m\ **o**\ nth, **w**\ eek, **d**\ ay, **h**\ our, **m**\ inute, and **s**\ econd
Expand Down
3 changes: 2 additions & 1 deletion doc_modern/rst/source/explain_array.rst_
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ array where *inc* can be 1 (every magnitude), 2, (1, 2, 5 times magnitude) or 3
(1-9 times magnitude). For less than every magnitude, use a negative integer *inc*.
Append **+n** if *inc* is meant to indicate the number of equidistant coordinates
instead. Alternatively, give a *file* with output coordinates in the first column,
or provide a comma-separated *list* of coordinates.
or provide a comma-separated *list* of coordinates. If you only want a *single* value
then you must append a comma to distinguish the list from the setting of *inc*.

If the module allows you to set up an absolute time series, append a valid time unit from the list
**y**\ ear, m\ **o**\ nth, **w**\ eek, **d**\ ay, **h**\ our, **m**\ inute, and **s**\ econd
Expand Down
5 changes: 4 additions & 1 deletion src/gmt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -15615,7 +15615,10 @@ unsigned int gmt_create_array (struct GMT_CTRL *GMT, char option, struct GMT_ARR
uint64_t k;
unsigned int pos = 0;
char p[GMT_LEN64] = {""};
for (k = 0, T->n = 1; k < strlen (T->list); k++) if (T->list[k] == ',') T->n++; /* Count the commas */
for (k = 0, T->n = 1; k < strlen (T->list); k++) {
if (T->list[k] == ',' && T->list[k+1])
T->n++; /* Count the commas */
}
T->array = gmt_M_memory (GMT, NULL, T->n, double);
k = 0;
while ((gmt_strtok (T->list, ",", &pos, p))) {
Expand Down

0 comments on commit 5f12027

Please sign in to comment.