[ncl-talk] read direct binary file

Dennis Shea shea at ucar.edu
Wed Jun 10 11:49:19 MDT 2015


Your use of fbindirread is not correct. The functions reads values on a
file.
The binary file contains fortran *character variables*.
The fortran code you attached  reads *AND* 'decodes' the characters into a
floating point values.
fbindirread reads only ... it does not decode.


Also   **NOTE** you specified fortran dimension ordering (column major).
NCL is row major .... the opposite!

---

  swdir      = "./"
  sfilename  = "amsre_20070601v7"
  dim        = (/2, 7, 720, 1440/)
  amsre_char = fbindirread(swdir + sfilename, 0, dim, "character")

printVarSummary(amsre_char)
; works fine

---

Lilely, you can do the decoding steps in NCL.

or ... create a fortran shared object and call the fortran code.
You must make it a subroutine to call from fortran.






On Wed, Jun 10, 2015 at 10:38 AM, Zhifeng Yang <yangzf01 at gmail.com> wrote:

> Hi
>
> I am trying to read a binary file using the following statements
>
> dim = (/1440, 720, 7, 2/)
> amsre_data = fbindirread(swdir + sfilename, 0, dim, "float")
>
> However, I got the errors as below.
> fatal:fbindirread: The size implied by the dimension array and record
> number is greater that the size of the file, can't continue
>
> This is how FORTRAN read this file.
>       CHARACTER(1) abuf(1440,720,7)
>       real, dimension(1440,720,7,2) ::amsr_data
>
>       OPEN(3,FILE=FILENAME,STATUS='OLD',RECL=7257600,
>      1 ACCESS='DIRECT',FORM='UNFORMATTED')
>       do ia=1,2
>           READ(3,rec=ia) abuf
>           do iv=1,7
>                 amsr_data(:,:,iv,ia)=real(ICHAR(abuf(:,:,iv)))
>                 where(amsr_data(:,:,iv,ia)<=250)
>
> amsr_data(:,:,iv,ia)=amsr_data(:,:,iv,ia)*xscale(iv)+xoffset(iv)
>                 endwhere
>           enddo
>         enddo
>         close(3)
>
> I am not sure why the error happens. Here is the link to download data.
> ftp://ftp.remss.com/amsre/bmaps_v07/y2007/m06/
> The file name is like amsre_20070601v7.gz
> <ftp://ftp.remss.com/amsre/bmaps_v07/y2007/m06/amsre_20070601v7.gz>
>
>
> Thank you
> Bruce
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150610/3aafa9e4/attachment.html 


More information about the ncl-talk mailing list