add commas at thousand, million and billion for integer annotations
|Target version:||Candidate for next minor release|
The language C has the ability to print integer with added commas as the thousands separator, like
printf("%'d", 12345) which can got the answer
12,345. This feature is required by some journals, and I always have to modify my figures by hand. So I am hoping the parameter
D_FORMAT in gmtset has the power just as the C dose. (fig1)
Another possible useful feature is the annotations could been aligned vertically like fig2.
Thanks for your work.
#1 Updated by Remko over 5 years ago
- Assignee set to Remko
- Target version set to Candidate for next minor release
In fact, I've always wanted to have an option to have
D_FORMAT use the C-type format specification more generally. Now it can only used for floating point numbers. It should be a rather simple to scan the
D_FORMAT statement and first cast (round) to integers when an integer format (
%i, etc) is used.
I will assign this to myself to be incorporated in 5.2.x.
As far as the right alignment: as far as I know annotations on the left-hand side of the plot are right-aligned already.
#2 Updated by Paul over 5 years ago
- Status changed from New to In Progress
Not sure, put I think he might refer to the MAP_ANNOT_ORTHO effect, already implemented.
I agree the integer stuff should be fairly simple since this is for Cartesian annotations only and those are done in the GMT_xy_axis which sets the format using GMT_get_format. This could be modified to pass back a flag so that one can convert to int before printing.
#3 Updated by Remko over 5 years ago
The thousands separator can in fact easily be accomplished by setting D_FORMAT to
However, this will require some change in the code, because normally C does not recognise any of the language settings. To make this work, all we need to do is to add the following code:
#include <locale.h> setlocal (LC_ALL, "");somewhere during initialisation. Once that's done, GMT will follow the
LC_*settings. This will then also allow users to use a comma as the decimal point.
In principle, we can regard it as a bug that GMT does not follow the
LC_* settings and hence it should be fixed in GMT4, GMT5.1 and GMT5.2.
#5 Updated by Joaquim over 5 years ago
What I still remember is that #ifdef resulted after an update in Cygwin that cost me almost a week of debugging to find out the trouble. But since I don't remember anymore what the problem was and I don't use Cygwin anymore I don't know if
setlocale (LC_ALL, "");
would solve it as well
#6 Updated by Remko over 5 years ago
This solution will be to change the localisation setting
en_US just before plotting a string with the format
FORMAT_FLOAT_MAP that includes
%', and then back to
C right after that. The same can be done when printing strings of the format
FORMAT_FLOAT_OUT in case that includes