Feature #622

add commas at thousand, million and billion for integer annotations

Added by chuan about 3 years ago. Updated about 3 years ago.

Status:ClosedStart date:2014-09-11
Priority:NormalDue date:
Assignee:Remko% Done:

100%

Category:-
Target version:Candidate for next minor release
Platform:

Description

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.

fig1.png (4.28 KB) chuan, 2014-09-11 16:36

fig2.png (1.49 KB) chuan, 2014-09-11 16:37

Associated revisions

Revision 13552
Added by Remko about 3 years ago

Make it possible to use a format like %'g to create separators for thousands.
This can be used for plotting axes on plots and in psscale.
This fixes issue #622.

Revision 13553
Added by Remko about 3 years ago

Merge from trunk; fixed issue #622

History

#1 Updated by Remko about 3 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 (%d or %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 about 3 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 about 3 years ago

The thousands separator can in fact easily be accomplished by setting D_FORMAT to %'g.

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.

#4 Updated by Remko about 3 years ago

I see that in GMT4 we have

#ifdef CYGWIN_LOCALE_TROUBLE
    setlocale (LC_CTYPE, "C.ASCII");
#endif
But nothing like that in GMT5.

Would the CYGWIN issue also be helped with a simple

setlocale (LC_ALL, "");
?

#5 Updated by Joaquim about 3 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 about 3 years ago

This solution will be to change the localisation setting LC_NUMERIC to 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 %'.

#7 Updated by Remko about 3 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100

The use of FORMAT_FLOAT_MAP = %'g is now supported in the SVN versions of GMT 5.1.x (r13552) and GMT 5.2.x (r13553).

#8 Updated by Remko about 3 years ago

Additional note: Example 39 now uses this format in the psscale at the bottom as an example.

#9 Updated by Paul about 3 years ago

  • Status changed from Resolved to Closed

Closing this as implemented for now.

Also available in: Atom PDF