# Grdinterpolate -E output units in m?

**URL:** <https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056>\
**Category:** Q&A\
**Created:** [June 21, 2023, 11:58am UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056 "2023-06-21T11:58:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bru](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@bru](https://forum.generic-mapping-tools.org/u/bru)\
**Post date:** [June 21, 2023, 11:58am UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/1 "2023-06-21T11:58:47Z")

</div>

Hi all!

I’m using grdinterpolate to find values over a vertical cross section, however it seems like the X axis output units are being given in m? Is there a way to set it to be given in km?

The command line I’m using:

gmt grdinterpolate $ingrid -G$outgrid -E-80/-15/-5/-15+i100k" -T0/800/1

which gives me: x\_min: 0 x\_max: 8012484.78674 x\_inc: 100.034767678

however, I know I’m measuring a range of 75 degrees ~ 8330 km, so it seems the output is in meters? Or am I doing something wrong?

I highly appreciate any help!

Thanks, Bruna.

\*should I attach the input 3D grid?

---

<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:** [June 21, 2023, 12:17pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/2 "2023-06-21T12:17:27Z")

</div>

No documentation taht says +i100k will be processed as km so it remains meter. Use grdedit to switch by 100 if you prefer that.

---

<div class="post-metadata">

**Author:** ![bru](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@bru](https://forum.generic-mapping-tools.org/u/bru)\
**Post date:** [June 21, 2023, 2:18pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/3 "2023-06-21T14:18:59Z")

</div>

Thank you! I guess I got confused with the part:  
If no units are specified we default to great circle distances in km (if geographic).  
from the documentation and was trying to find a way to get to it.

Your solution unfortunately is leading me to another error. My GMT is not allowing me to call variables from netCDF files. If I use $mygrid?var for anything it gives me “Named variable does not exist in file”.

Ex: the grid I’m working on, from grdinfo  
x\_min: 0 x\_max: 8012484.78674 x\_inc: 111284.510927 name: longitude n\_columns: 73

and if I try  
gmt grdedit$mygrid?longitude it gives  
grdinfo (gmtapi\_import\_grid): Named variable does not exist in file [v.-80.-15.-5.-15.grd?longitude]  
[Session gmt (0)]: Error returned from GMT API: GMT\_GRID\_READ\_ERROR (18)  
[Session gmt (0)]: Error returned from GMT API: GMT\_GRID\_READ\_ERROR (18)

I tested with other netCDF grids and still get the same error…

Thanks for the support!

Bruna.

---

<div class="post-metadata">

**Author:** ![bru](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@bru](https://forum.generic-mapping-tools.org/u/bru)\
**Post date:** [June 21, 2023, 3:52pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/4 "2023-06-21T15:52:22Z")

</div>

?var actually only recognizes the named variables in z…

if anyone has any clue please help, I’ve tried everything!!

---

<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:** [June 21, 2023, 4:00pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/5 "2023-06-21T16:00:57Z")

</div>

Yes. GMT has never let anyone access a coordinate array since most of the time there is none, just the scalars min, inc, max. Only grids or cube layers can be accessed.

---

<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:** [June 21, 2023, 4:30pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/6 "2023-06-21T16:30:20Z")

</div>

`grdedit -R...` should be the way to go.

---

<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:** [June 22, 2023, 11:12am UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/7 "2023-06-22T11:12:31Z")

</div>

> [@bru](#):
>
> If no units are specified we default to great circle distances in km (if geographic).

You are right about that. Shall see what we are doing with units here.

---

<div class="post-metadata">

**Author:** ![bru](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@bru](https://forum.generic-mapping-tools.org/u/bru)\
**Post date:** [June 22, 2023, 12:51pm UTC](https://forum.generic-mapping-tools.org/t/grdinterpolate-e-output-units-in-m/4056/8 "2023-06-22T12:51:16Z")

</div>

Perfect, this does the trick for now! Thanks a lot!!

For anyone with a similar problem, here is how I’m getting around:

```
#run your interpolate options for a cross-section
gmt grdinterpolate $ingrid -G$outgrid -E$lon1/$lat1/$lon2/$lat2 -T$zmin/$zmax/$zinc -fg
#calculate the max crossing distance and convert to kilometers
dmax=$(gmt grdinfo -C -Q $outgrid | awk '{print $3/1000}')
#reset the values in kilometers
gmt grdedit -R0/$dmax/$zmin/$zmax $ingrid
```
