[ncl-talk] Skip Over Header in Binary File
Dave Allured - NOAA Affiliate
dave.allured at noaa.gov
Mon Jun 26 17:49:43 MDT 2017
Greg,
Read the entire file as flat binary. Set the second argument to -1 to
indicate unknown dimensions; this will read the whole file. Set the third
argument to "byte" or "ubyte" to match the intended signedness of the data.
x = cbinread ("file.bin", -1 ,"byte")
Then remove the header bytes using a subscript range expression. Remember,
NCL subscripting is zero-based:
x2 = x(300:)
I would use dimsizes to confirm that the result has the expected number of
bytes. Then use function onedtond to reshape the x2 array from 1-D to 2-D.
--Dave
On Mon, Jun 26, 2017 at 5:33 PM, Greg Deemer <greg.deemer at nsidc.org> wrote:
> Hello, and thank you for addressing my question.
>
> I’m wanting to read some data stored in an unsigned flat binary one-byte
> integer format. As such, the endianness is thankfully irrelevant. I know
> the data array will have a shape (/448, 304/), but it is stored after a
> header that is 300 bytes long. After reading through the binary guidance
> and hints (https://www.ncl.ucar.edu/Applications/r-binary.shtml), I’ve
> been unsuccessful in getting started. For some other languages I’ve used,
> there is a ‘skip bytes’ flag that can be added to read functions to make
> this process a bit simpler. I thought that was where the “rec_num” came in
> for fbindirread, fbinrecread, and craybinrecread. I.e. rec_num = 299 would
> then allow the function to start reading at location 300, byte 301?
>
> The data file I’m trying to read is attached to this message. If the
> attachment is blocked, you can download direct from this HTTPS site (but
> will need a public NASA Earthdata Login Profile setup to do so):
> https://daacdata.apps.nsidc.org/pub/DATASETS/nsidc0051_gsfc_
> nasateam_seaice/final-gsfc/north/daily/2006/nt_20060101_f13_v1.1_n.bin
>
> Any help in learning how to skip over some bytes would be great!
>
> Thanks,
>
> Greg Deemer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170626/5a7b5347/attachment.html
More information about the ncl-talk
mailing list