Re: help:problem when using "fbindiread" function

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 21 Jun 2007 09:43:22 -0600

I can not replicate your problem.

FYI: you need not preallocate the variable "a" below.
All NCL functions will create the space automatically.
[The script runs correctly regardless if
;;a = new((/2/),float)
is uncommented or not]

What version of NCL and on what system are you running?

Also .... was t.grd created before?
We always recommend that the user remove any pre-existing file.

Regards, ....

begin
;;a = new((/2/),float)
b = ispan(1,10,1)*1.
print (b)
print ("")
fName = "./t.grd"
system ("/bin/rm -f "+fName) ; remove pre-existing file if it exists
fbindirwrite(fName,b) ; one flat binary record of 10 elements

do nrec=0,4 ; read two elements at a time.
a = fbindirread(fName,nrec,2,"float")
print("nrec="+nrec+ " "+a(0)+ " "+a(1))
end do

end

[SNIP]

(0)
(0) nrec=0 1 2
(0) nrec=1 3 4
(0) nrec=2 5 6
(0) nrec=3 7 8
(0) nrec=4 9 10

lxf wrote:
> Hi,
> Taday I have a binary reading problem when using "fbindiread" function .
> So I design a test as following to read a "direct" "unformated" binary data "t.grd".
> I think that when give "dims" to the function "fbindirread(path, nrec, dims, "float")" , the record number is then determined by the as :
> number of record = (data's legth)/dims
> So, I think I can read the data segment which I want without read the whole data. But the following script "t.ncl" and it's result puzzled me:
> &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
> The following is the output of "% ncl -x t.ncl" :
> &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
> Copyright (C) 1995-2007 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 4.3.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> + begin
> + a = new((/2/),float)
> + b = ispan(1,10,1)*1.
> + print (b)
> + print ("")
> + fbindirwrite("./t.grd",b)
> +
> + do nrec=0,4
> + a = fbindirread("./t.grd",nrec,2,"float")
> + print("nrec="+nrec+ " "+a(0)+ " "+a(1))
> + end do
> +
> + end
>
>
> Variable: b
> Type: float
> Total Size: 40 bytes
> 10 values
> Number of Dimensions: 1
> Dimensions and sizes: [10]
> Coordinates:
> (0) 1
> (1) 2
> (2) 3
> (3) 4
> (4) 5
> (5) 6
> (6) 7
> (7) 8
> (8) 9
> (9) 10
> (0)
> (0) nrec=0 1 2
> (0) nrec=1 3 4
> (0) nrec=2 5 6
> (0) nrec=3 1 2 ; Here I had suposed the third record to be "7 8" ,but it was "1 2"
> (0) nrec=4 3 4 ; Here I had suposed the third record to be "9 10" ,but it was "3 4"
> &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
>
>
> Any help is appreciated.
>
> Li
> 2006.6.21
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jun 21 2007 - 09:43:22 MDT

This archive was generated by hypermail 2.2.0 : Fri Jun 22 2007 - 07:01:57 MDT