From binary to grd files

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,

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.

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.

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

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

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

ans =


1 Like

and 3/3600 is not 8.3333333e-04.

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.