9292 Rate this article:
No rating

Creating a multi-record GRIB file

Mark Piper

I'm a little embarrassed about this, but last week I learned (or maybe "recalled" is more accurate) that you can create multi-record GRIB files using only the UNIX cat command. For example, with files a.grb and b.grb, I can make a new file c.grb with:

$ cat a.grb b.grb > c.grb
      

To perform the equivalent action solely within IDL, read the files as a bytestream, concatenate the data, then write the data back as a bytestream; e.g.:

IDL> a = read_binary('a.grb')
IDL> b = read_binary('b.grb')
IDL> c = [a, b]

IDL> openw, u, 'c.grb', /get_lun
IDL> writeu, u, c
IDL> free_lun, u
      

That's it. What do you think?

Note:

Actually, while writing this, I thought of a pair of feature requests.

  1. To complement the other FILE_* routines (FILE_MOVE, FILE_COPY, etc.), should IDL have a FILE_CAT routine? This would allow Windows users to have a UNIX "cat" equivalent in IDL.
  2. As a complement to READ_BINARY, should we have a WRITE_BINARY? It would bring the three lines of code used above down to one.

SIGN UP AND STAY INFORMED

Sign up to receive the latest news, events, technologies and special offers.

SIGN ME UP