<div dir="ltr">Laura,<div><br></div><div>1. Please notice that your array size 43200 * 21600 * 4-byte floats exceeds the conventional 2 Gbyte limit for normal fortran unformatted sequential record size. This may be the cause of "0 or less than zero fortran control word". Some compilers have schemes for larger record size, but they are not standardized and can be troublesome.</div><div><br></div><div>2. There are several solutions. I recommend keeping the ordinary fortran unformatted sequential format because it seems you are most familiar with it. But loop over Y, and write your array in pieces sequentially, one Y subscript at a time. This will write 21600 records with reasonable record size.</div><div><br></div><div>3. Check your output file before attempting to read with NCL. The size of this new file should be exactly 21600 * (43200 + 1 + 1) * 4 bytes in size, including two standard fortran control words for each record.</div><div><br></div>4. In NCL, pre-dimension your input array. Then read this new binary sequential file one record at a time, looping over Y, the same as it was written. Be sure to use the fbinrecread function for reading binary sequential format, multiple records. Untested:<br><br>nx = 43200<br>ny = 21600<div>oro_usgs = new ( (/ nx, ny /), float)<br>do y = 0, ny-1<br> oro_usgs(:,y) = fbinrecread (fili, y, nx, "float")<div>end do</div><div><br></div><div>5. If you are still having trouble, try writing and reading only a single record (one Y subscript). This will make a small test file and simplify debugging.</div><div><br></div><div>6. Unless you are constrained in some way by other issues in your fortran program, please avoid reading and writing this file as big endian. Modern Macs are little endian machines, and they do well with their native formats. Reverse endian may be adding confusion needlessly.</div><div><br></div><div>7. Consider using "od" or another binary viewing program to inspect the contents of your file. See this write-up for more details on investigating binary formats:</div><div><br></div><div> <a href="http://www.ncl.ucar.edu/Applications/r-binary.shtml">http://www.ncl.ucar.edu/Applications/r-binary.shtml</a><br></div><div><br></div><div>--Dave</div></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 23, 2015 at 5:55 PM, Laura Fowler <span dir="ltr"><<a href="mailto:laura@ucar.edu" target="_blank">laura@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi Dennis:<br>
Unfortunately, reading the fortran binary file still does not work. I<br>
rewrote the binary files as flat binary files, or<br>
open(unit=21,file='output.oro_usgs.bin',form='unformatted')<br>
<br>
so in my ncl script, I have:<br>
oro_usgs = fbinrecread(file1,0,-1,"float")<br>
<br>
since I do not specify the length of the array oro_usgs. Since I had<br>
to use the option -fconvert=big-endian to read some data, I also tried<br>
to use the option:<br>
<br>
setfileoption("bin","ReadByteOrder","BigEndian")<br>
<br>
but that did not help either. I am really puzzled as what to do next<br>
since I can read that new file with a simple fortran unformatted read.<br>
What else do you suggest?<br>
<br>
Thanks,<br>
Laura<br><br>
<br>
On Fri, Nov 20, 2015 at 5:53 PM, Dennis Shea <<a href="mailto:shea@ucar.edu">shea@ucar.edu</a>> wrote:<br>
> fortran binary writes can create 'flat' binary files (access='direct')<br>
> or access='sequential'. The latter is the default.<br>
><br>
> To read 'flat' files use: fbinread<br>
><br>
> To read 'sequential' (which you explicitly specified) use: fbinrecread<br>
><br>
> ===<br>
> Note: fortran precedes *each* sequential record by a record separator.<br>
><br>
> Good luck<br>
><br>
><br>
> On Fri, Nov 20, 2015 at 5:25 PM, Laura Fowler <<a href="mailto:laura@ucar.edu">laura@ucar.edu</a>> wrote:<br>
>> Hi:<br>
>><br>
>> I created a binary file using a fortran sourcecode on my iMac. Using<br>
>> gfortran, I used the option -fconvert=big-endian tom compie the<br>
>> sourcecode. I used the open statement:<br>
>><br>
>> open(unit=21,file='oro_usgs.bin',form='unformatted',access='sequential')<br>
>><br>
>> to write the data out. I want to open and read the file in an ncl<br>
>> script to later plot the data. My script looks like that:<br>
>><br>
>> setfileoption("bin","ReadByteOrder","BigEndian")<br>
>> file1 = "oro_usgs.bin"<br>
>> recl = 43200*21600<br>
>> oro_usgs = fbinread(file1,recl,"float")<br>
>> print(max(oro_usgs))<br>
>> printVarSummary(oro_usgs)<br>
>><br>
>> I get the error:<br>
>> See <a href="http://www.ncl.ucar.edu/" rel="noreferrer" target="_blank">http://www.ncl.ucar.edu/</a> for more details.<br>
>> fatal:fbinread: 0 or less than zero fortran control word, FILE NOT<br>
>> SEQUENTIAL ACCESS!<br>
>> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 17<br>
>> in file plot.ncl<br>
>><br>
>> without the setfileoption, I get the error:<br>
>><br>
>> See <a href="http://www.ncl.ucar.edu/" rel="noreferrer" target="_blank">http://www.ncl.ucar.edu/</a> for more details.<br>
>> fatal:fbinread: requested variable size exceeds record size<br>
>> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 17 in<br>
>> file plot.ncl<br>
>><br>
>> I do not know what to do next and help would be greatly appreciated. Thanks,<br>
>><br>
>> Laura<br></blockquote></div></div></div>