# From binary to grd files

**URL:** https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896
**Category:** Q&A
**Created:** [May 8, 2022, 9:24pm UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896 "2022-05-08T21:24:24Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![erik17](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@erik17](https://forum.generic-mapping-tools.org/u/erik17)
#### Post date: [May 8, 2022, 9:24pm UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896/1 "2022-05-08T21:24:24Z")

</div>

Dear GMT developers,

I’m trying to read GACOS data and convert them to grd files.  
the files are:  
20160125-20160206.phs (binary file)  
20160125-20160206.phs.rsc (header file)

I used the following command, with the exact same values as the header:  
`xyz2grd 20160125-20160206.phs -G20160125-20160206.phs.grd -RLT-2.5700000/52.9066667/4940/2111 -I8.3333333e-04/8.3333333e-04 -ZTLf -di0 -r`

The output file doesn’t have the exact same values in “x\_min” (I got the warning of aliasing), there is a very slight difference.

here the output of “gmt grdinfo 20160125-20160206.phs”

> ```
> 20160125-20160206.phs.grd: Title: z
> 20160125-20160206.phs.grd: Command: xyz2grd 20160125-20160206.phs -G20160125-20160206.phs.grd -RLT-2.5700000/52.9066667/4940/2111 -I8.3333333e-04/8.3333333e-04 -ZTLf -di0 -r
> 20160125-20160206.phs.grd: Remark:
> 20160125-20160206.phs.grd: Pixel node registration used [Cartesian grid]
> 20160125-20160206.phs.grd: Grid file format: nf = GMT netCDF format (32-bit float), CF-1.7
> 20160125-20160206.phs.grd: x_min: -2.56999998972 x_max: 1.54666666048 x_inc: 0.00083333333 name: x n_columns: 4940
> 20160125-20160206.phs.grd: y_min: 51.1475000404 y_max: 52.9066667 y_inc: 0.00083333333 name: y n_rows: 2111
> 20160125-20160206.phs.grd: z_min: -28.7051029205 z_max: 4.50304317474 name: z
> 20160125-20160206.phs.grd: scale_factor: 1 add_offset: 0
> 20160125-20160206.phs.grd: format: netCDF-4 chunk_size: 130,132 shuffle: on deflation_level: 3
> 
> ```

Is it possible to get the exact same value in y\_max and x\_min as the header file?

Thanks in advance,  
Erik

---

<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 8, 2022, 11:22pm UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896/2 "2022-05-08T23:22:29Z")

</div>

Hmm, the `y_max` you got is what you entered. Don’t know why `x_min` was so slightly changed but floating point numbers are tricky beasts. “-2.57” seams to be representable as such but maybe I’m failing in plotting it in all of its bits.

You can try to reset `x_min` with `grdedit` to see what it does.

---

<div class="post-metadata">

### Author: ![erik17](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@erik17](https://forum.generic-mapping-tools.org/u/erik17)
#### Post date: [May 9, 2022, 9:34am UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896/3 "2022-05-09T09:34:08Z")

</div>

Hi Joaquim,

I tried and unfortunately I didn’t change the xmin value. When I tried different numbers, the values are changed successfully. Apparently 2.57 and 2.5699999 are equivalent for GMT.

What I’m trying to do is a subtraction between two grids one produced with Matlab and one with GMT but the _grdmath_ command doesn’t allow operations if they are not exactly the same.

---

<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 9, 2022, 11:09am UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896/4 "2022-05-09T11:09:58Z")

</div>

Perhaps you could try to use the exact 3s instead of the truncated 8.3333333e-04 ?

---

<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 9, 2022, 11:22am UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896/5 "2022-05-09T11:22:55Z")

</div>

> [@erik17](#):
>
> Apparently 2.57 and 2.5699999 are equivalent for GMT.

It’s not GMT, it’s computers in general. Try this in Matlab

```auto
>> sprintf('%.16f', 2.57)

ans =

    '2.5699999999999998'

```

[https://docs.oracle.com/cd/E19957-01/806-3568/ncg\_goldberg.html](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)

---

<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 9, 2022, 11:24am UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896/6 "2022-05-09T11:24:04Z")

</div>

and 3/3600 is not 8.3333333e-04.

---

<div class="post-metadata">

### Author: ![erik17](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@erik17](https://forum.generic-mapping-tools.org/u/erik17)
#### Post date: [May 9, 2022, 12:01pm UTC](https://forum.generic-mapping-tools.org/t/from-binary-to-grd-files/2896/7 "2022-05-09T12:01:42Z")

</div>

Ok, I thought I was doing something wrong during the process. I guess it’s just the way floats are handled by computers.  
Very interesting. Thank you dear developers.  
Have a nice day.
