Grdinterpolate with a "variable" z_inc

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 as example and using the attached file p34.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 (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?

1 Like

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

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

gdalinfo …

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)