[ncl-talk] help reading binary file

Laura Fowler laura at ucar.edu
Mon Nov 23 17:55:03 MST 2015


Hi Dennis:
Unfortunately, reading the fortran binary file still does not work. I
rewrote the binary files as flat binary files, or
open(unit=21,file='output.oro_usgs.bin',form='unformatted')

so in my ncl script,  I have:
oro_usgs = fbinrecread(file1,0,-1,"float")

since I do not specify the length of the array oro_usgs. Since I had
to use the option -fconvert=big-endian to read some data, I also tried
to use the option:

setfileoption("bin","ReadByteOrder","BigEndian")

but that did not help either. I am really puzzled as what to do next
since I can read that new file with a simple fortran unformatted read.
What else do you suggest?

Thanks,
Laura




On Fri, Nov 20, 2015 at 5:53 PM, Dennis Shea <shea at ucar.edu> wrote:
> fortran binary writes can create 'flat' binary files (access='direct')
> or access='sequential'. The latter is the default.
>
> To read 'flat' files use: fbinread
>
> To read 'sequential' (which you explicitly specified) use: fbinrecread
>
> ===
> Note: fortran precedes *each* sequential record by a  record separator.
>
> Good luck
>
>
> On Fri, Nov 20, 2015 at 5:25 PM, Laura Fowler <laura at ucar.edu> wrote:
>> Hi:
>>
>> I created a binary file using a fortran sourcecode on my iMac. Using
>> gfortran, I used the option -fconvert=big-endian tom compie the
>> sourcecode. I used the open statement:
>>
>> open(unit=21,file='oro_usgs.bin',form='unformatted',access='sequential')
>>
>> to write the data out. I want to open and read the file in an ncl
>> script to later plot the data. My script looks like that:
>>
>> setfileoption("bin","ReadByteOrder","BigEndian")
>> file1    = "oro_usgs.bin"
>> recl     = 43200*21600
>> oro_usgs = fbinread(file1,recl,"float")
>> print(max(oro_usgs))
>> printVarSummary(oro_usgs)
>>
>> I get the error:
>>  See http://www.ncl.ucar.edu/ for more details.
>>  fatal:fbinread: 0 or less than zero fortran control word, FILE NOT
>> SEQUENTIAL ACCESS!
>>  fatal:["Execute.c":8128]:Execute: Error occurred at or near line 17
>> in file plot.ncl
>>
>> without the setfileoption, I get the error:
>>
>> See http://www.ncl.ucar.edu/ for more details.
>> fatal:fbinread: requested variable size exceeds record size
>> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 17 in
>> file plot.ncl
>>
>>
>> I do not know what to do next and help would be greatly appreciated. Thanks,
>>
>> Laura
>>
>>
>> --
>> !-------------------------------------------------------------------------------------------------------------
>> Laura D. Fowler
>> Mesoscale and Microscale Meteorology Division (MMM)
>> National Center for Atmospheric Research
>> P.O. Box 3000, Boulder CO 80307-3000
>>
>> e-mail: laura at ucar.edu
>> phone: 303-497-1628
>>
>> !-------------------------------------------------------------------------------------------------------------
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk



-- 
!-------------------------------------------------------------------------------------------------------------
Laura D. Fowler
Mesoscale and Microscale Meteorology Division (MMM)
National Center for Atmospheric Research
P.O. Box 3000, Boulder CO 80307-3000

e-mail: laura at ucar.edu
phone: 303-497-1628

!-------------------------------------------------------------------------------------------------------------


More information about the ncl-talk mailing list