# Grdinterpolate with a "variable" z\_inc

**URL:** <https://forum.generic-mapping-tools.org/t/grdinterpolate-with-a-variable-z-inc/5242>\
**Category:** Q&A\
**Created:** [August 27, 2024, 8:51pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-with-a-variable-z-inc/5242 "2024-08-27T20:51:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gery](https://avatars.discourse-cdn.com/v4/letter/g/c5a1d2/32.png) [@gery](https://forum.generic-mapping-tools.org/u/gery)\
**Post date:** [August 27, 2024, 8:51pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-with-a-variable-z-inc/5242/1 "2024-08-27T20:51:49Z")

</div>

After reading several posts about `grdinterpolate` (maybe all of them), I am still confused about how to extract a vertical slice from a multidimensional netcdf file (long, lat, time, depth + SeveralVariables). Using [this nc file](https://easyupload.io/778dlt) as example and using the attached file [p34.txt](https://forum.generic-mapping-tools.org/uploads/short-url/iobZ5RjRBPkczD6RTuDBIaIHw4o.txt) (4.8 KB) as a profile, I do the following:

```
grdinterpolate mync.nc?water_temp -Ep34.txt -Go.nc

```

This creates a new file with all levels (40 levels, depth ranging between 0-5000 m). The problem is that its `z_inc` is variable:

```
mync.nc: z_min: 0 z_max: 5000 z_inc: (variable) name: Depth [m] n_levels: 40

```

So, adding the `-Z` flag to use a specific range of levels seems to not be possible (from 0 m to 200 m):

```
grdinterpolate mync.nc?water_temp -Ep34.txt -Go.nc -Z0/200
grdinterpolate [ERROR]: Option -Z: Number of input 2-D grids does not match number of levels given via -Z

```

I was thinking that I should use depth labels instead of depth values (so, `z_inc=1`, or as a comma-separated list) but it does not work either:

```
grdinterpolate mync.nc?water_temp -Ep34.txt -Go.nc -Z1/23/1
grdinterpolate [ERROR]: Option -Z: Number of input 2-D grids does not match number of levels given via -Z

```

If a variable `z_inc` cannot be used with this type of netcdf files, is it still possible to extract a vertical slice with `grdinterpolate`?

Any support is appreciated,

All the best,

Gery

**PS:**

Just to notice that if I do:

```
grdinterpolate mync.nc?water_temp -Sp34.txt

```

A constant variable value of `20` appears below the first depth level (variable value of about 16.xxxx, see attached file [constantvalue.txt](https://forum.generic-mapping-tools.org/uploads/short-url/qEIFy39JWIqNISuAyQAtOi4MlFc.txt) (238.5 KB) with the following warning:

```
grdinterpolate [WARNING]: No 3-D array in file mync.nc. Selecting first 3-D slice in the 4-D array water_temp

```

I would expect that temperature values decrease with increasing depth instead of showing a constant value with depth, is this the normal behavior?

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [August 30, 2024, 4:32pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-with-a-variable-z-inc/5242/2 "2024-08-30T16:32:36Z")

</div>

I think the problem is that your grid is 4D, not 3D and GMT is having troubles recognizing that the first dimension is singleton.

```auto
grdinterpolate [WARNING]: No 3-D array in file mync.nc. Selecting first 3-D slice in the 4-D array water_temp

```

gdalinfo …

```auto
Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"mync.nc":water_temp
  SUBDATASET_1_DESC=[1x40x501x376] sea_water_temperature (16-bit integer)
  SUBDATASET_2_NAME=NETCDF:"mync.nc":salinity
  SUBDATASET_2_DESC=[1x40x501x376] sea_water_salinity (16-bit integer)
  SUBDATASET_3_NAME=NETCDF:"mync.nc":water_u
  SUBDATASET_3_DESC=[1x40x501x376] eastward_sea_water_velocity (16-bit integer)
  SUBDATASET_4_NAME=NETCDF:"mync.nc":water_v
  SUBDATASET_4_DESC=[1x40x501x376] northward_sea_water_velocity (16-bit integer)

```
