Grdinterpolate -E fails for profiles that extend beyond the data domain

Hi, I am having a lot of fun with grdinterpolate/greenspline, but I have run into an issue when extracting vertical data slices for profiles that extend beyond the horizontal domain of the input 3D cube. It would be great if grdinterpolate would return NaN’s in the output grid, similar to the behavior of grdtrack, for portions of the track that fall outside the datacube domain. I took a look at the code but it is over my head.

gmt grdinterpolate -Fa -E122/-11/126/-6+i1k -T0/80/1 -Ve

gmt grdinterpolate -Fa -E121/-11/126/-6+i1k -T0/80/1 -Ve
sample1d [ERROR]: x-values are not monotonically increasing/decreasing (at zero-based record 2)!
sample1d [ERROR]: Failure in gmt_intpol near row 3! (70.4 KB)

gmt grdinfo -Q Title: Command: gmt grdinterpolate -Z0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80 -D"+xlongitude [deg]+ylatitude [deg]+zdepth [km]+dvs+vvs" Remark: Gridline node registration used [Geographic grid] Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7 x_min: 121.5 x_max: 130.5 x_inc: 0.5 (30 min) name: longitude [deg] n_columns: 19 y_min: -13 y_max: -4 y_inc: 0.5 (30 min) name: latitude [deg] n_rows: 19 z_min: 0 z_max: 80 z_inc: 1 name: depth [km] n_levels: 81 v_min: -11.9457054138 v_max: 11.9360837936 name: vs scale_factor: 1 add_offset: 0 format: classic Default CPT:

Thanks for the post. grdinterpolate is a young module and has not had time to mature yet - hence we occasionally run into some simple bugs. In this case, as grdinterpolate wants grdtrack to return systematic equal-sized segments we need to pass -N in the grdtrack call to ensure we get NaNs when sampling outside the grid instead of just skipping those records (which causes the troubles upstream you run into). After passing -N your example works fine for me,

I have opened a PR for this and we will see if Easter slows the approval down or not.

Merged already, so if you can build from master you can test it out.

Hi Paul, I have rebuilt from master and can confirm that it works now. Thanks for the quick update!


Great, thanks for trying it out!