# GRDMATH and RPN

**URL:** <https://forum.generic-mapping-tools.org/t/grdmath-and-rpn/481>\
**Category:** Q&A\
**Created:** [May 22, 2020, 5:48am UTC](https://forum.generic-mapping-tools.org/t/grdmath-and-rpn/481 "2020-05-22T05:48:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [May 22, 2020, 5:48am UTC](https://forum.generic-mapping-tools.org/t/grdmath-and-rpn/481/1 "2020-05-22T05:48:21Z")

</div>

Hi,

I have two big netCDF files on which I’d like to perform a calculation to return a third one.

The operation is : 1.25 \* 1e-3 \* sqrt(u^2 + v^2) \* u ;

I tried the following syntax and only computed the 1st day (or so it seems).  
gmt grdmath 1.25 0.0013 MUL $u $u MUL $v $v MUL ADD SQRT MUL $u MUL = w.nc

(u and v are 3D data with longitude[1440], latitude[721] and time[14610]).

Thanks,  
Guillaume

---

<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:** [May 22, 2020, 9:14am UTC](https://forum.generic-mapping-tools.org/t/grdmath-and-rpn/481/2 "2020-05-22T09:14:28Z")

</div>

Well the operation would be

```auto
gmr grdmath $u $u MUL $v $v MUL ADD SQRT $u MUL 0.00125 MUL = w.nc

```

but GMT won’t be able to compute over 3D grids, only 2D layers and then it has no way to reconstruct back 3D stack.

---

<div class="post-metadata">

**Author:** ![timhume](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/timhume/32/296_2.png) [@timhume](https://forum.generic-mapping-tools.org/u/timhume)\
**Post date:** [May 22, 2020, 11:30am UTC](https://forum.generic-mapping-tools.org/t/grdmath-and-rpn/481/3 "2020-05-22T11:30:14Z")

</div>

Hi Guillaume,

If you’re using Linux or UNIX, one get of jail as painlessly as possible way would be to install the NetCDF Operators ([https://github.com/nco/nco](https://github.com/nco/nco)) and then use the ncap2 operator to do your calculation.

Cheers,

Tim

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [May 22, 2020, 6:43pm UTC](https://forum.generic-mapping-tools.org/t/grdmath-and-rpn/481/4 "2020-05-22T18:43:52Z")

</div>

Hi,

Thanks for the both of you. I’ll give a shot to ncap2…

edit : I ended up using Matlab and saving A LOT of memory with this command :

> ```
> var_ID = netcdf.defVar(ncid,paramID,'NC_SHORT',[dimlon dimlat dimtime]);
> 
> ```

Best,  
Guillaume
