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.

Succeeds:
gmt grdinterpolate randcube.nc?vs -Fa -E122/-11/126/-6+i1k -T0/80/1 -Gvs_1.nc -Ve

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

randcube.nc.zip (70.4 KB)

gmt grdinfo -Q randcube.nc

randcube.nc: Title:
randcube.nc: Command: gmt grdinterpolate data_0.nc data_1.nc data_2.nc data_3.nc data_4.nc data_5.nc data_6.nc data_7.nc data_8.nc data_9.nc data_10.nc data_11.nc data_12.nc data_13.nc data_14.nc data_15.nc data_16.nc data_17.nc data_18.nc data_19.nc data_20.nc data_21.nc data_22.nc data_23.nc data_24.nc data_25.nc data_26.nc data_27.nc data_28.nc data_29.nc data_30.nc data_31.nc data_32.nc data_33.nc data_34.nc data_35.nc data_36.nc data_37.nc data_38.nc data_39.nc data_40.nc data_41.nc data_42.nc data_43.nc data_44.nc data_45.nc data_46.nc data_47.nc data_48.nc data_49.nc data_50.nc data_51.nc data_52.nc data_53.nc data_54.nc data_55.nc data_56.nc data_57.nc data_58.nc data_59.nc data_60.nc data_61.nc data_62.nc data_63.nc data_64.nc data_65.nc data_66.nc data_67.nc data_68.nc data_69.nc data_70.nc data_71.nc data_72.nc data_73.nc data_74.nc data_75.nc data_76.nc data_77.nc data_78.nc data_79.nc data_80.nc -Rdata_0.nc -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" -Grandcube.nc
randcube.nc: Remark:
randcube.nc: Gridline node registration used [Geographic grid]
randcube.nc: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
randcube.nc: x_min: 121.5 x_max: 130.5 x_inc: 0.5 (30 min) name: longitude [deg] n_columns: 19
randcube.nc: y_min: -13 y_max: -4 y_inc: 0.5 (30 min) name: latitude [deg] n_rows: 19
randcube.nc: z_min: 0 z_max: 80 z_inc: 1 name: depth [km] n_levels: 81
randcube.nc: v_min: -11.9457054138 v_max: 11.9360837936 name: vs
randcube.nc: scale_factor: 1 add_offset: 0
randcube.nc: format: classic
randcube.nc: 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!

Kyle

Great, thanks for trying it out!