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
Received on Thu Oct 29 20:19:18 2009
This archive was generated by hypermail 2.1.8 : Mon Nov 02 2009 - 08:49:47 MST