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

**URL:** <https://forum.generic-mapping-tools.org/t/grdinterpolate-e-fails-for-profiles-that-extend-beyond-the-data-domain/2821>\
**Category:** Q&A\
**Created:** [April 15, 2022, 7:56am UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-fails-for-profiles-that-extend-beyond-the-data-domain/2821 "2022-04-15T07:56:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyleedwardbradley](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kyleedwardbradley/32/1407_2.png) [@kyleedwardbradley](https://forum.generic-mapping-tools.org/u/kyleedwardbradley)\
**Post date:** [April 15, 2022, 7:56am UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-fails-for-profiles-that-extend-beyond-the-data-domain/2821/1 "2022-04-15T07:56:01Z")

</div>

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](https://forum.generic-mapping-tools.org/uploads/short-url/atYAoQYJfK07njEx3QsnHW1IOX0.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:

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [April 15, 2022, 10:04am UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-fails-for-profiles-that-extend-beyond-the-data-domain/2821/2 "2022-04-15T10:04:57Z")

</div>

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](https://github.com/GenericMappingTools/gmt/pull/6560) for this and we will see if Easter slows the approval down or not.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [April 15, 2022, 10:18am UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-fails-for-profiles-that-extend-beyond-the-data-domain/2821/3 "2022-04-15T10:18:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kyleedwardbradley](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kyleedwardbradley/32/1407_2.png) [@kyleedwardbradley](https://forum.generic-mapping-tools.org/u/kyleedwardbradley)\
**Post date:** [April 15, 2022, 12:47pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-fails-for-profiles-that-extend-beyond-the-data-domain/2821/4 "2022-04-15T12:47:25Z")

</div>

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

Kyle

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [April 15, 2022, 1:00pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-fails-for-profiles-that-extend-beyond-the-data-domain/2821/5 "2022-04-15T13:00:41Z")

</div>

Great, thanks for trying it out!
