Re: Is there a bug with fbinrecwrite or fbinrecread

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 02 2009 - 10:47:31 MST

Hi all,

The problem turned out to be that the binary file was not being
removed before it was being created. Hence, the "good" data was being
appended to the file, which contained "bad" data from an old run.
When the file was read back in, then, it was reading the same "bad"
data again and again.

The solution was to simply add a "system" call to remove the binary
files before they were created.

--Mary

On Oct 30, 2009, at 11:39 AM, guangshan chen wrote:

> Hi Mary,
>
> I only run on My Mac OS 10.4.11. NCL version 5.1.1. I will try on
> another Machine.
>
> The only I can not understand is that If I only output one variable
> to binary file, it is right. But for two variables, it is wrong.
> I have checked they are quite different.
>
> Thanks.
>
> Guangshan
>
> On Oct 30, 2009, at 10:25 AM, Mary Haley wrote:
>
>> Guangshan,
>>
>> I was also unable to reproduce this problem, and I ran it on 32-
>> bit and 64-bit systems (Mac, LINUX, AIX).
>>
>> What version of NCL do you have? Did you try running the program
>> more than once to see if the problem was still there?
>>
>> --Mary
>>
>> On Oct 30, 2009, at 5:53 AM, Rick Brownrigg wrote:
>>
>>> Hi Guangshan,
>>>
>>> Curiously, I get the following output, which appears to be correct:
>>>
>>> (0)
>>> (0) Monthly Longterm Mean of U-Wind: min=-37.2069 max=95.8738
>>> (0)
>>> (0) Monthly Longterm Mean of V-Wind: min=-33.7934 max=32.8907
>>> (0) u-wind Min and Max values read from ./wind.mon.ltm.bin
>>> (0)
>>> (0) min=-37.2069 max=95.8738
>>> (0) v-wind Min and Max values read from ./wind.mon.ltm.bin
>>> (0)
>>> (0) min=-33.7934 max=32.8907
>>> (0) u-wind Min and Max values read from ./uwind.mon.ltm.bin
>>> (0)
>>> (0) min=-37.2069 max=95.8738
>>>
>>> I hate to think there might be platform differences, but not sure
>>> what
>>> to suggest here.
>>> This was running NCL 5.1.1 under MacOS 10.5.8.
>>>
>>> Rick
>>>
>>> On Thu, 29 Oct 2009 21:19:20 -0500
>>> guangshan chen <gchen9@gmail.com> wrote:
>>>> Dear all:
>>>>
>>>> It seems there is bug in fbinrecwrite or fbinrecread.
>>>>
>>>> Here is the test main idea:
>>>> step 1: read netcdf file and get two variables data
>>>> step 2: printMinMax values of variables
>>>> step 3: using fbinrecwrite to write binary file
>>>> step 4: using fbinrecread to read binary file
>>>> step 5: printMinMax values of the new two variables
>>>>
>>>> But I compared the Min and Max values between the original data and
>>>>
>>>> new data read from binary file are different.
>>>>
>>>> Original Min and Max values:
>>>> Monthly Longterm Mean of U-Wind: min=-37.2069 max=95.8738
>>>> Monthly Longterm Mean of V-Wind: min=-33.7934 max=32.8907
>>>>
>>>> New Min and Max values read from binary file
>>>> u-wind Min and Max values read from ./wind.mon.ltm.bin are
>>>> min=-37.2069 max=81.1241
>>>> v-wind Min and Max values read from ./wind.mon.ltm.bin are
>>>> min=-36.9928 max=95.8738
>>>>
>>>> Also in my script I output only variable to binary file and read
>>>> it,
>>>>
>>>> there is no problem.
>>>> u-wind Min and Max values read from ./uwind.mon.ltm.bin are
>>>> min=-37.2069 max=95.8738
>>>>
>>>> So Could anyone check what is going when outputting two variables?
>>>>
>>>> Thanks
>>>>
>>>> Guangshan
>>>>
>>>>
>>>> ;================================================;
>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
>>>> ;================================================;
>>>> ;load external functions should be included path;
>>>> ;external function_name "./function_name.so"
>>>> ;================================================;
>>>> begin
>>>> ;================================================;
>>>> ;The binary file will be the same as a one open via fortran's open
>>>> statement:
>>>> ;
>>>> ; open(..., form="unformatted", [,access="sequential"] ) ;
>>>> sequential is default
>>>>
>>>> uwind_file = addfile("uwnd.mon.ltm.nc","r")
>>>> vwind_file = addfile("vwnd.mon.ltm.nc","r")
>>>>
>>>> ; data can be download from
>>>> ;http://www.esrl.noaa.gov/psd/cgi-bin/db_search/DBSearch.pl?
>>>> Variable=U-
>>>> ; Wind&Dataset=CDC+Derived+NCEP+Reanalysis+Products+Pressure+Level
>>>> ;
>>>> http://www.esrl.noaa.gov/psd/cgi-bin/db_search/DBSearch.pl?
>>>> Variable=V-
>>>> ; Wind&Dataset=CDC+Derived+NCEP+Reanalysis+Products+Pressure+Level
>>>>
>>>> lat = uwind_file->lat(::-1)
>>>> print(lat)
>>>> lon = uwind_file->lon
>>>> lev = uwind_file->level
>>>> time = uwind_file->time
>>>>
>>>> nlat = dimsizes(lat)
>>>> nlon = dimsizes(lon)
>>>> nlev = dimsizes(lev)
>>>> ntime = dimsizes(time)
>>>>
>>>> ; make sure lat from -90. 90.
>>>> uwind = uwind_file->uwnd(:,:,::-1,:)
>>>> vwind = vwind_file->vwnd(:,:,::-1,:)
>>>>
>>>> printMinMax(uwind,True)
>>>> printMinMax(vwind,True)
>>>>
>>>>
>>>> setfileoption("bin","WriteByteOrder","BigEndian")
>>>>
>>>> path = "./wind.mon.ltm.bin"
>>>>
>>>> do itime=0,ntime-1
>>>>
>>>> do ilev=0,nlev-1
>>>> fbinrecwrite(path,-1,(/uwind(itime,ilev,:,:)/))
>>>> end do
>>>>
>>>> do ilev=0,nlev-1
>>>> fbinrecwrite(path,-1,(/vwind(itime,ilev,:,:)/))
>>>> end do
>>>>
>>>> end do
>>>>
>>>> ;************************************************************
>>>> ; note the -1 indicates to just add on to the end of the file
>>>> ; the (/.../) syntax means output the values only with no meta
>>>> ; data
>>>> ;************************************************************
>>>>
>>>> path1 = "./uwind.mon.ltm.bin"
>>>>
>>>> do itime=0,ntime-1
>>>> do ilev=0,nlev-1
>>>> fbinrecwrite(path1,-1,(/uwind(itime,ilev,:,:)/))
>>>> end do
>>>> end do
>>>>
>>>> ; read uwind and vwind binary file
>>>>
>>>> setfileoption("bin","ReadByteOrder","BigEndian")
>>>>
>>>> rec_dims=(/nlat,nlon/)
>>>> rec_type="float"
>>>>
>>>> uwnd=new( (/ntime,nlev,nlat,nlon/), rec_type )
>>>> vwnd=new( (/ntime,nlev,nlat,nlon/), rec_type )
>>>> rec_num = 0
>>>> do it=0,ntime-1
>>>> do il=0,nlev-1
>>>> uwnd(it,il,:,:)=fbinrecread(path,rec_num,rec_dims,rec_type )
>>>> rec_num=rec_num+1
>>>> end do
>>>>
>>>> do il=0,nlev-1
>>>> vwnd(it,il,:,:)=fbinrecread(path,rec_num,rec_dims,rec_type )
>>>> rec_num=rec_num+1
>>>> end do
>>>>
>>>> end do
>>>>
>>>> print("u-wind Min and Max values read from "+ path)
>>>> printMinMax(uwnd,True)
>>>> print("v-wind Min and Max values read from "+ path)
>>>> printMinMax(vwnd,True)
>>>>
>>>> ; read uwind only binary file
>>>> uwnd_o=new( (/ntime,nlev,nlat,nlon/), rec_type )
>>>> rec_num = 0
>>>> do it=0,ntime-1
>>>>
>>>> do il=0,nlev-1
>>>> uwnd_o(it,il,:,:)=fbinrecread(path1,rec_num,rec_dims,rec_type
>>>> )
>>>> rec_num=rec_num+1
>>>> end do
>>>>
>>>> end do
>>>>
>>>> print("u-wind Min and Max values read from "+ path1)
>>>> printMinMax(uwnd_o,True)
>>>> ;================================================;
>>>> ;================================================;
>>>> end
>>>>
>>>> _______________________________________________
>>>> 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
>>
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Nov 2 10:47:16 2009

This archive was generated by hypermail 2.1.8 : Fri Nov 06 2009 - 09:15:29 MST