Grdcontour -N with .cpt fails


I tried to (re)-run a script containing this command :

gmt makecpt -Ccork -T0.5/1.5/0.5 -G0/1 -A50 -N > cold.cpt
gmt grdcontour -R -J -W -C+1 -Ncold.cpt -An $NCvar[$i]

For some reason, the -N flag now generates an error :

ERROR: Caught signal number 4 (Illegal instruction: 4) at

Playing around with the flags and everything, the problem seems to come from the .cpt :

> cat cold.cpt
0.5 174.25/207.62/177.25@50 1 174.25/207.62/177.25@50 L
1 63/119.88/46.75@50 1.5 63/119.88/46.75@50 B

Any idea (I suspected a typo somwhere, but couldn’t find any)?

I was unable to reproduce the error that you get:

    cat \<\<EOF > cold.cpt
    0.5 174.25/207.62/177.25@50 1 174.25/207.62/177.25@50 L
    1 63/119.88/46.75@50 1.5 63/119.88/46.75@50 B
    gmt grdmath -R0/360/-90/90 -I1 8 4 YLM 1.1 MUL EXCH 0.4 MUL ADD ABS .88 MUL 0.5 ADD = # something to test
    gmt grdcontour -R0/360/-90/90 -JW15c -W -C+1 -Ncold.cpt -An  >

generated something that appears reasonable:

As far as I could check, GMT changed how it writes the cpt files.

This is very strange. The same kind of lines in a different script works just fine. But no matter how I change the CPT (or assign a single color) it fails in this one.
The problem only appears with the -N flag … :confused:

Here’s the debugging log :

gmt grdcontour -R -J -W -C+1 -Ncold.cpt -An ‘path/file?[63]’ -Vd -O -K

gmt [DEBUG]: Obtained the ppid from parent: 1321
gmt [DEBUG]: Enter: gmtinit_new_GMT_ctrl
gmt [DEBUG]: GMT->session.SHAREDIR = /usr/local/Cellar/gmt/6.1.1/share/gmt
gmt [DEBUG]: GMT->session.HOMEDIR = /Users/Guillaume
gmt [DEBUG]: GMT->session.USERDIR = /Users/Guillaume/.gmt [created]
gmt [DEBUG]: GMT->session.CACHEDIR = /Users/Guillaume/.gmt/cache [created]
gmt [DEBUG]: GMT: 0. Will try to find subdir=postscriptlight stem = PSL_custom_fonts suffix=.txt
gmt [DEBUG]: GMT: 1. gmt_getsharepath trying current dir
gmt [DEBUG]: GMT: 2. gmt_getsharepath trying USERDIR /Users/Guillaume/.gmt
gmt [DEBUG]: GMT: 3. gmt_getsharepath trying USERDIR subdir /Users/Guillaume/.gmt/postscriptlight
gmt [DEBUG]: GMT: 4. gmt_getsharepath trying SHAREDIR subdir /usr/local/Cellar/gmt/6.1.1/share/gmt/postscriptlight
gmt [DEBUG]: GMT: 5. gmt_getsharepath trying SHAREDIR /usr/local/Cellar/gmt/6.1.1/share/gmt
gmt [DEBUG]: GMT: 6. gmt_getsharepath failed
gmt [DEBUG]: Map distance calculation will be Cartesian
gmt [DEBUG]: Exit: gmtinit_new_GMT_ctrl
gmt [DEBUG]: Enter: New_PSL_Ctrl
gmt [DEBUG]: Exit: New_PSL_Ctrl
gmt [DEBUG]: Enter: gmt_manage_workflow
gmt [DEBUG]: Exit : gmt_manage_workflow
gmt [DEBUG]: Enter: PSL_beginsession
gmt [DEBUG]: Exit : PSL_beginsession
gmt [DEBUG]: Enter: PSL_setdefaults
gmt [DEBUG]: Exit : PSL_setdefaults
gmt [DEBUG]: Enter: gmtlib_io_init
gmt [DEBUG]: Exit : gmtlib_io_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit: gmt_hash_init
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit: gmt_hash_init
gmt [DEBUG]: Enter: gmt_reload_settings
gmt [DEBUG]: The PROJ_GEODESIC set to Vincenty
gmt [DEBUG]: Found file gmt.conf
gmt [DEBUG]: Reading GMT Default parameters from file: gmt.conf
gmt [DEBUG]: Exit: gmt_reload_settings
gmt [DEBUG]: Enter: gmtlib_plot_C_format
gmt [DEBUG]: Exit: gmtlib_plot_C_format
gmt [DEBUG]: Enter: gmtinit_get_history
gmt [DEBUG]: Enter: gmt_hash_init
gmt [DEBUG]: Exit: gmt_hash_init
gmt [DEBUG]: Exit: gmtinit_get_history
gmt [DEBUG]: Initialize FFTW with 4 threads.
gmt [DEBUG]: GMT_Create_Session initialized GMT structure
gmt [DEBUG]: Loading core GMT shared library: libgmt.dylib
gmt [DEBUG]: Shared Library # 0 (core). Path = libgmt.dylib
gmt [DEBUG]: Loading GMT plugins from: /usr/local/Cellar/gmt/6.1.1/lib/gmt/plugins
gmt [DEBUG]: Shared Library # 1 (supplements). Path = /usr/local/Cellar/gmt/6.1.1/lib/gmt/plugins/
gmt [DEBUG]: gmt_get_filename: In: cold.cpt Out: cold.cpt
gmt [DEBUG]: Found readable file cold.cpt

ERROR: Caught signal number 4 (Illegal instruction: 4) at
0 libsystem_c.dylib 0x00007fff693e9fca __chk_fail_overflow.cold.1 + 16
1 libsystem_c.dylib 0x00007fff693e9fca __chk_fail_overflow.cold.1 + 16
Stack backtrace:
0 libgmt.6.1.1.dylib 0x00000001075dd06b sig_handler + 555
1 libsystem_platform.dylib 0x00007fff695135fd _sigtramp + 29
2 ??? 0x0000000000000080 0x0 + 128
3 libsystem_c.dylib 0x00007fff693e7214 __chk_fail_overlap + 0
4 libsystem_c.dylib 0x00007fff693e7769 __sprintf_object_size_chk + 0
5 libgmt.6.1.1.dylib 0x00000001077a6750 GMT_grdcontour + 5784
6 libgmt.6.1.1.dylib 0x00000001075fb6a7 GMT_Call_Module + 1598
7 gmt 0x00000001075d16eb main + 1370
8 libdyld.dylib 0x00007fff6931acc9 start + 1

could it be from a older version? Sometimes an old gmt.conf make a mess here.

@PlanetGus it would be helpful if you can share your data and full script so that others can reproduce it.

@MarceloBanik : No I generate and move my custom .conf in working directory. I tried your suggestion tho… not that. (I wish it was).

@seisman : the file is a NetCDF4 (several GB) with 0 and 1.

What surprises me is that I have two very similar scripts running the same set of commands, but only this one generates the error with -N flag.

Maybe because of the “type” of the data ? (nc_byte)

ncdump -h $file

netcdf data {
time = UNLIMITED ; // (2920 currently)
lat = 361 ;
lon = 576 ;
byte ar_binary_tag(time, lat, lon) ;
double lat(lat) ;
double lon(lon) ;
double time(time) ;


gmt grdinfo $file

ERROR: Caught signal number 11 (Segmentation fault: 11) at

Maybe the problem is here… but why would it works without the -N flag … ?

It somehow works on linux with gmt 6.0.0 (I just copied the script) … I’ll just stick with linux for now and figure out why later…

My guess would be there’s a problem with grdcontour and my libraries (macOS), between homebrew and other custom libraries from LaTeX, ghostscript (etc), it’s quite a mess.