[GRASSLIST:892] Re: Problems importing a GMT grd file (SOLUTION)

This is a wrap-up to a problem I had importing GMT grd files into GRASS using r.in.bin on Cygwin/XP.

Apparently, GMT 3.4.X type=1 grids are platform dependent. The header line in type=1 grids created on Windows (Cygwin or precompiled binaries) contains 4 extra bytes that are not found in a type=1 grid created on Linux. (for more information search the GMT-HELP archives for [GMT-HELP:11231] Problems with grdreformat on Cygwin and Windows )

r.in.bin assumes that the header in type=1 GMT grids conforms to the Linux convention, hence, any type=1 grids created on the Windows platform will fail to import properly.

The solution provided here is a small program that can strip the extra 4 bytes out of the Windows type=1 grids and convert them to the Linux convention (or vis-à-vis). Thanks to Marta E. Ghidella for this program.

How to proceed:

1) Create the GMT grid in Cygwin or DOS version of GMT as usual (Note the default grid type is type=0)

2) Use GMT's grdreformat to convert the grid to type=1:

> grdreformat ingrid=0 outgrid.win=1

3) Run convert6432.exe or convert6432.py as follows:

> ./convert6432.exe outgrid.win outgrid.lin -4

or alternatively

> python convert6432.py outgrid.win outgrid.lin -4

4) Start grass and use r.in.bin to import the linux-style GMT grid:

GRASS:~> r.in.bin -hf in=outgrid.lin out=grid

That, at lest, works for me on Windows XP with Cygwin

NOTE: To compile the C version of convert6432.exe in Cygwin, download convert6432.c to any cygwin directory and type:

$ gcc -mno-cygwin convert6432.exe -o convert6432.c

There is a fixed memory size in the C version that is adjusted by making the variable NMAX=4000000 larger and recompiling. This is unnecessary in the Python version so long as you don't run out of swap space.

--
David Finlayson
School of Oceanography
Box 357940
University of Washington
Seattle, WA 98195-7940
USA

Office: Marine Sciences Building, Room 112
Phone: (206) 616-9407
Web: http://students.washington.edu/dfinlays

(attachments)

convert6432.c (4.05 KB)
convert6432.py (2.74 KB)