[ncl-talk] binary file

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Fri Oct 9 12:55:21 MDT 2020


That looks like fortran unformatted sequential format, not flat binary.
Confirm by seeing if the first four bytes are 00 00 09 00, the same as the
last four bytes that you showed.  This would be the record size as a
little-endian 4-byte integer, which would be correct for this format.  This
would also explain the 8-byte difference.

Read in NCL with fbinrecread, not cbinread.  Please see the function docs
and follow the prototype.


On Fri, Oct 9, 2020 at 12:34 PM Rick Brownrigg via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Well I don't think you want to read it as double, particularly not if you
> are certain the dimensions are 384x384. I'm wondering if you can safely
> ignore that last 8 bytes (and ignore the warning).  A quick plot would
> reveal whether the data seem reasonable or definitely misaligned.
>
> RB
>
> On Fri, Oct 9, 2020 at 12:14 PM Debasish Hazra <debasish.hazra5 at gmail.com>
> wrote:
>
>> Thanks Rick.Should I read it as double?
>>
>> On Fri, Oct 9, 2020 at 1:39 PM Rick Brownrigg <brownrig at ucar.edu> wrote:
>>
>>> Well, the math works out: 4x384x384=589824.  Further, the last 8 bytes
>>> of that file do not look like valid floating point values. They are:
>>>
>>>  00 00 00 00 00 00 09 00
>>>
>>> Do you have reason to believe the data is not being read correctly, or
>>> are you mostly concerned about the warning message?
>>>
>>> BTW - the data are mostly zeros.
>>>
>>> Rick
>>>
>>>
>>> On Fri, Oct 9, 2020 at 11:09 AM Debasish Hazra via ncl-talk <
>>> ncl-talk at mailman.ucar.edu> wrote:
>>>
>>>> Hi,
>>>> I am trying to read binary file (attached in the email) through NCL and
>>>> file size is 589832 bytes. I am reading it as float but it coming out to be
>>>> 589824. I am not sure what needs to be done to read it.
>>>>
>>>>  setfileoption("bin","readbyteorder","littleendian")
>>>>  d1 = cbinread("./Test/modelout.dat",(/4,384,384/),"float")
>>>>
>>>> warning:cbinread: The size implied by the dimension arrays is less that
>>>> the size of the file.
>>>>  Only the first 589824 contiguous bytes of the file will be read in.
>>>> Note dimensions and values may not be aligned properly
>>>>
>>>> Any help on this is appreciated.
>>>> Thanks
>>>> Debasish
>>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20201009/040dfbed/attachment.html>


More information about the ncl-talk mailing list