# Gridmath error

**URL:** <https://forum.generic-mapping-tools.org/t/gridmath-error/2903>\
**Category:** Q&A\
**Created:** [May 10, 2022, 7:11pm UTC](https://forum.generic-mapping-tools.org/t/gridmath-error/2903 "2022-05-10T19:11:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmurekezi](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/dmurekezi/32/2241_2.png) [@dmurekezi](https://forum.generic-mapping-tools.org/u/dmurekezi)\
**Post date:** [May 10, 2022, 7:11pm UTC](https://forum.generic-mapping-tools.org/t/gridmath-error/2903/1 "2022-05-10T19:11:42Z")

</div>

quick question; I’m trying to add a mask to a grid using grdmath and I keep getting an error about NX and NY, I tried the grdedit -A suggestion and still doesn’t solve the problem. Anyone has some experience with grdmath?

Here is the run; `gmt grdmath 20210519_20210525.grd KivuMask.grd MUL = 20210519_20210525_masked.grd` and the error message:  
`grdmath [ERROR]: (x_max-x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.`  
`grdmath [ERROR]: (y_max-y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.`  
`grdmath (gmtlib_read_grd_info): Use grdedit -A on your grid file to make region and increments compatible [KivuMask.grd]`

---

<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:** [May 10, 2022, 7:35pm UTC](https://forum.generic-mapping-tools.org/t/gridmath-error/2903/2 "2022-05-10T19:35:34Z")

</div>

GMT is a bit picky that the grids actually are internally consistent. Perhaps you can post the output of grdinfo for the two grids here?

---

<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 10, 2022, 7:56pm UTC](https://forum.generic-mapping-tools.org/t/gridmath-error/2903/3 "2022-05-10T19:56:09Z")

</div>

Please, do no post under a wrong category. There is nothing GMT.jl in your question.

---

<div class="post-metadata">

**Author:** ![dmurekezi](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/dmurekezi/32/2241_2.png) [@dmurekezi](https://forum.generic-mapping-tools.org/u/dmurekezi)\
**Post date:** [May 10, 2022, 8:20pm UTC](https://forum.generic-mapping-tools.org/t/gridmath-error/2903/4 "2022-05-10T20:20:52Z")

</div>

```auto
20210519_20210525.grd: Title: 20210519_20210525.grd
20210519_20210525.grd: Command: File written by MATLAB function grdwrite2.m
20210519_20210525.grd: Remark: Created 09-May-2022 18:11:01
20210519_20210525.grd: Gridline node registration used [Cartesian grid]
20210519_20210525.grd: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
20210519_20210525.grd: x_min: 28.4859761 x_max: 30.28682384 x_inc: 0.00027778 name: x n_columns: 6484
20210519_20210525.grd: y_min: -2.3190463 y_max: -0.8982016 y_inc: 0.00027778 name: y n_rows: 5116
20210519_20210525.grd: v_min: -154.096954346 v_max: 104.191604614 name: z
20210519_20210525.grd: scale_factor: 1 add_offset: 0
20210519_20210525.grd: format: classic

```

```auto
KivuMask.grd: Command: grdlandmask -R28.4859761/30.28682384/-2.3190463/-0.8982016 -A+l -Df -NNaN/1 -GKivuMask.grd -I0.00027778/0.00027778
KivuMask.grd: Remark: Derived from the full resolution shorelines
KivuMask.grd: Gridline node registration used [Geographic grid]
KivuMask.grd: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
KivuMask.grd: x_min: 28.4859761 x_max: 30.28682384 x_inc: 0.00027778 (1 sec) name: longitude n_columns: 6484
KivuMask.grd: y_min: -2.3190463 y_max: -0.8982016 y_inc: 0.00027778 (1 sec) name: latitude n_rows: 5116
KivuMask.grd: v_min: 1 v_max: 1 name: z
KivuMask.grd: scale_factor: 1 add_offset: 0
KivuMask.grd: format: netCDF-4 chunk_size: 130,132 shuffle: on deflation_level: 3

```

---

<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:** [May 10, 2022, 8:41pm UTC](https://forum.generic-mapping-tools.org/t/gridmath-error/2903/5 "2022-05-10T20:41:11Z")

</div>

Very similar-looking, but also very large grids so a tiny offset in the increment could cause this. I note one is written from matlab and says it is Cartesian while the other is geographic. Could you please do the two commands again but add **–FORMAT\_FLOAT\_OUT=%.16lg** to them?
