Re: read binary data for integer and float types

From: Li, Yongzuo <yongzuo.li_at_nyahnyahspammersnyahnyah>
Date: Wed Jan 20 2010 - 10:14:23 MST

The ending script is following with correct output and error warning.

 two = new(2,"integer")
         two = fbindirread(data+".bin",0,2,"integer")

     numRays = two(0)
     numBins = two(1)
         print("num="+numRays+"bin"+numBins)

         lat = new((/numRays,numBins/),"float")
         lon = new((/numRays,numBins/),"float")
         ht = new((/numRays,numBins/),"float")
         rv = new((/numRays,numBins/),"float")

      rec = fbindirread(data+".bin",0,4*numRays*numBins+2,"float")
      lat = onedtond(rec(2:), (/numRays,numBins/) )
      lon = onedtond(rec((2+1*numRays*numBins):), (/numRays,numBins/) )
      ht = onedtond(rec((2+2*numRays*numBins):), (/numRays,numBins/) )
      rv = onedtond(rec((2+3*numRays*numBins):), (/numRays,numBins/) )

      print("lat="+max(lat))
      print("lat="+min(lat))
      print("lon="+max(lon))
      print("lon="+min(lon))
      print("rv="+max(rv))
      print("rv="+min(rv))

(0) num=360bin1192
warning:onedtond : output dimension sizes have fewer elements than input, some data not copied
warning:onedtond : output dimension sizes have fewer elements than input, some data not copied
warning:onedtond : output dimension sizes have fewer elements than input, some data not copied
(0) lat=32.1673
(0) lat=26.7766
(0) lon=-91.9828
(0) lon=-98.1755
(0) rv=50.72
(0) rv=-63.22

________________________________________
From: shea@ucar.edu [shea@ucar.edu]
Sent: Tuesday, January 19, 2010 8:03 PM
To: Li, Yongzuo
Cc: ncl-talk@ucar.edu
Subject: Re: read binary data for integer and float types

This is not clear.

Are you sure the file was created with "direct" writing?

Or, was it created with a fortran sequential write

    integer i1, i2
    real x(ii,jj)

    write(iunit) i1, i2, x

If the latter, then use fbinrecread

    irec = fbinrecread("data.bin",0, ii*jj+2,"integer")
    i1 = irec(0)
    i2 = irec(1)

    rec = fbinrecread("data.bin",0, ii*jj+2,"float")
    data = onedtond( rec(2:), (/jj,ii/) )

> Hi,
>
> I have following script to read binary data in integer/float type.
>
> two = new(2,"integer")
> ;two = fbindirread("data.bin",0,2,"integer")
> jj = 67
> ii = 43
> rf = new((/jj,ii/),"float")
> rf = fbindirread("data.bin",0,(/jj,ii/),"float")
>
> Question (1),
>
> Can fbindirread work without "(/jj,ii/)"? I tried and failed without it.
>
> Question (2),
>
> How can jj and ii be read from data.bin and then used to define jj and ii
> for rf = new(xxx) ?
>
> Either
> two = fbindirread("data.bin",0,2,"integer")
> or
> rf = fbindirread("data.bin",0,(/jj,ii/),"float")
> works well separately.
>
> But they do not work together (change 0 to 1 in rf line when both
> applied).
>
> Thanks
>
> Yongzuo
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jan 20 10:17:19 2010

This archive was generated by hypermail 2.1.8 : Thu Jan 21 2010 - 13:54:45 MST