[ncl-talk] problem with dim_avg_n and userdefined function (numeric and float)
陶玮
1201111616 at pku.edu.cn
Mon Oct 27 22:53:25 MDT 2014
Hi, everyone.
Q1:
I was using NCL V6.2.0 to extract data from WRF results, however, it seemed that there was a bug in function of dim_avg_n.To simplify matters, I used dummy data, the script is as follows:
QUESTION 1:-----------------------------------------------------------------
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/wrf/WRFUserARW.ncl"
begin
nyears=5
ncases=4
nspec=4
ntimes_real=680
nvlevs=2
colspectmp=new((/nyears,ncases,nspec,ntimes_real,100,100/), float)
colspec=new((/nyears,ncases,nspec,100,100/), float)
colspectmp=1.
specdntmp=new((/nyears,ncases,nspec,ntimes_real,nvlevs,100,100/), float)
specdn=new( (/nyears,ncases,nspec,nvlevs,100,100/), float)
specdntmp=1.
;abnormal !!!! It seemed that no values were passed to colspec !!!!
colsepc=dim_avg_n((/colspectmp/), 3)
print(avg(colspec))
;normal !!!!
specdn=dim_avg_n((/specdntmp/), 3)
print(avg(specdn))
end
--------------------------------------------------------------------------------------
Q2:What's the difference between numeric and float when using userdefined function. though max((/a,b/)) would do the same thing, I am
eager to know the answer.
QUESTION2---------------------------------------------------------------------------------
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/wrf/WRFUserARW.ncl"
undef( "fmax2v")
function fmax2v(x:float, y:float)
begin
if (x .ge. y) then
return(x)
else
return(y)
end if
end
undef( "max2v")
function max2v(x:numeric, y:numeric)
begin
if (x .ge. y) then
return(x)
else
return(y)
end if
end
begin
x=3
; normal loops !!!!!
do ii=1, 2
do jj=1, 3
print("ii="+(/ii/)+" jj="+(/jj/))
print("1: "+(/fmax2v(ii-x,0)/))
tmp=(/fmax2v(ii-x,0)/)
print("2: "+ (/tmp/))
end do
end do
; abnormal loops !!!!
do ii=1, 2
do jj=1, 3
print("ii="+(/ii/)+" jj="+(/jj/))
print("1: "+(/max2v(ii-x,0)/))
tmp=(/max2v(ii-x,0)/)
print("2: "+ (/tmp/))
end do
end do
end
--------------------------------------------------------
With best regards.
More information about the ncl-talk
mailing list