Axis formatting w/ polar coordinates (-JP) + grd2cpt malloc problem (w/ -G)

Added by Luca almost 2 years ago

Hello forum,

I'm creating a polar surface in (theta, r) where the actual coordinates are azimuth angle (0, 180 degrees, CCW), zenith angle (0, ±80 degrees, radially outward) and z is the intensity field. The following script is used:

FILE=test; NC="$"; COL="$FILE.cpt"; PLOT="$" 
rm $PLOT

min=0; max=0.11

# Create the surface from discretised angles
gmt surface $FILE -G$NC -R0/180/0/80 -Ll$min -Lu$max -I1/0.5 -V -Ti1 -Tb1

## gmt grd2cpt $NC -Cjet -G$min/$max > $COL
## With my GMT Version 5.2.1 (r15220) [64-bit] [8 cores], the above line crashes with:
## gmt(29119,0x7fff772a9000) malloc: *** error for object 0x7fe89980ca00: pointer being freed was not allocated
## *** set a breakpoint in malloc_error_break to debug
## ./ line 31: 29119 Abort trap: 6  gmt grd2cpt $NC -Cjet -G$min/$max > $COL

# No big deal, I resort on makecpt for the time being 
gmt makecpt -Cjet -T$min/$max/30+ > $COL

# Plot the surface
OFF="-Xa2c -Ya4c" 
gmt grdimage $NC -JP6i $OFF -C$COL -K > $PLOT

ANNOT="-By30 -Bx30" 

# Add some contours
gmt grdcontour $NC -JP6i $OFF $ANNOT -C$COL -A- -W1p,black $FORMAT -O -K >> $PLOT

cat > sun_zenith.d << END
0    45    1
gmt psxy $OFF -R -J sun_zenith.d -Sc -Gred -Wthickest -O -K >> $PLOT

OFF2="-Xa8.5c -Ya2.75c" 
echo "@~l@~ = $1 nm" | gmt pstext $OFF2 -R1/10/1/10 -JX10 -F+cTR -O -K >> $PLOT

gmt psscale $REF -C$COL -Baf -By+l'[-]' --MAP_ANNOT_OFFSET_PRIMARY=7.5p -R -J -O >> $PLOT 

Beside the grd2cpt issue, I can't find my way to the labelling of the y-axis at the bottom of the plot.
The angles in range ±80 degrees should have a degree symbol and the tickmark '00' at the origin be shifted outward (justified) with some offset I can't set.

Any help is really appreciated. Plot and data are attached.

test.png (153 KB)

test (44 KB)

Replies (1)

RE: Axis formatting w/ polar coordinates (-JP) + grd2cpt malloc problem (w/ -G) - Added by Luca almost 2 years ago

I played with the projection and following the documentation I realized that what is very likely needed, in order to label the y-axis (or as in the polar plot, the elevation 'r') as degrees, is the option


such that the command line reads

gmt grdcontour brdf_14/ -JP6ir -Xa2c -Ya4c -By30 -Bx30  -Cbrdf_14/ -A- -W+1p -V -K -O >> brdf_14/

However, it fails with:

grdcontour: Processing input grid
grdcontour: Allocate memory and read data file
gmt(48322,0x7fff772a9000) malloc: *** error for object 0x7ff831059608: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
./ line 62: 48322 Abort trap: 6           gmt grdcontour $NC ${PROJ} $OFF $AXy $AXx $FORMAT -C$COL -A- $CONT -V -K -O >> $PLOT
ERROR: Caught signal number 11 (Segmentation fault) at
0   libsystem_malloc.dylib              0x00007fff9158beec small_malloc_from_free_list + 584
1   ???                                 0x0000000000000000 0x0 + 0
Stack backtrace:
0   libgmt.5.dylib                      0x000000010c6eecd2 sig_handler + 338
1   libsystem_platform.dylib            0x00007fff987a252a _sigtramp + 26
2   ???                                 0x00007fff5351ca20 0x0 + 140734591257120
3   libsystem_malloc.dylib              0x00007fff91588b64 szone_malloc_should_clear + 1411
4   libsystem_malloc.dylib              0x00007fff9158b9a6 malloc_zone_calloc + 78
5   libsystem_malloc.dylib              0x00007fff9158c462 calloc + 49
6   libpostscriptlight.5.dylib          0x0000000110e6a2f2 PSL_plotline + 66
7   libpostscriptlight.5.dylib          0x0000000110e6a212 PSL_beginclipping + 98
8   libgmt.5.dylib                      0x000000010c810b2c GMT_map_clip_on + 172
9   libgmt.5.dylib                      0x000000010c93da55 GMT_grdcontour + 9013
10  libgmt.5.dylib                      0x000000010c70346c GMT_Call_Module + 284
11  gmt                                 0x000000010c6e6307 main + 1159
12  libdyld.dylib                       0x00007fff911765ad start + 1
13  ???                                 0x000000000000000c 0x0 + 12

I suspect I have to reinstall gmt?