<div dir="ltr"><div class="gmail_default" style="font-size:small">Thanks for providing a short script that very clearly illustrates the problem. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The problem seems to be with the "0" that's being passed in as the second argument to max2n.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">If I change this to a variable:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"><span style="font-family:arial,sans-serif;font-size:13px">; abnormal loops !!!!</span></div><div class="gmail_default" style="font-size:small">zero = 0<br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">do i=1, 2</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px"> print("i="+(/i/))</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px"> print("Before v=max2n(i-3,0)") ; Printed, got here</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px"> v=max2n(i-3,zero)</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px"> print("After v=max2n(i-3,0)") ; Crashed, didn't get here</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px"> print("v is " + v)</span><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">end do</span><br></div><div class="gmail_default" style="font-size:small"><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div class="gmail_default"><font face="arial, sans-serif">then the code runs file.</font></div><div class="gmail_default"><font face="arial, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, sans-serif">I have filed a ticket on this, NCL-2098. Hopefully the work-around of using a variable instead of passing in a direct value is acceptable for now.</font></div><div class="gmail_default"><font face="arial, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, sans-serif">--Mary</font></div><div class="gmail_default"><font face="arial, sans-serif"><br></font></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 28, 2014 at 5:39 AM, 李嘉鹏 <span dir="ltr"><<a href="mailto:lijpbasin@126.com" target="_blank">lijpbasin@126.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I agree with 陶玮 on the second script.<br>
<br>
To be sure, I replaced all the variable and function names while checking for typos, and eliminated as much code as possible to make the problem look more obvious (at least obvious enough for me) like a bug.<br>
<br>
- The program crashed in the second loop (i = 2), causing a "Segmentation fault".<br>
<br>
- I thought `numeric` is equivalent to `integer` since two integer values are passed to the function, so I tried `integer` too, same problem, and `float` did not cause any trouble.<br>
<br>
<br>
<br>
<br>
Here is the script I tested:<br>
<br>
undef("max2n")<br>
function max2n(n1:numeric, n2:numeric) ; Crashes<br>
;function max2n(n1:integer, n2:integer) ; Crashes<br>
;function max2n(n1:float, n2:float) ; Fine<br>
begin<br>
if (n1 .ge. n2) then<br>
return(n1)<br>
else<br>
return(n2)<br>
end if<br>
end<br>
<br>
begin<br>
<br>
; abnormal loops !!!!<br>
do i=1, 2<br>
print("i="+(/i/))<br>
print("Before v=max2n(i-3,0)") ; Printed, got here<br>
v=max2n(i-3,0)<br>
print("After v=max2n(i-3,0)") ; Crashed, didn't get here<br>
print("v is " + v)<br>
end do<br>
<br>
end<br>
<span class="im HOEnZb"><br>
<br>
At 2014-10-28 12:53:25, "陶玮" <<a href="mailto:1201111616@pku.edu.cn">1201111616@pku.edu.cn</a>> wrote:<br>
</span><div class="HOEnZb"><div class="h5">>Hi, everyone.<br>
>Q1:<br>
>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:<br>
>QUESTION 1:-----------------------------------------------------------------<br>
>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br>
>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br>
>load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"<br>
><br>
>begin<br>
><br>
>nyears=5<br>
>ncases=4<br>
>nspec=4<br>
>ntimes_real=680<br>
>nvlevs=2<br>
><br>
>colspectmp=new((/nyears,ncases,nspec,ntimes_real,100,100/), float)<br>
>colspec=new((/nyears,ncases,nspec,100,100/), float)<br>
>colspectmp=1.<br>
><br>
>specdntmp=new((/nyears,ncases,nspec,ntimes_real,nvlevs,100,100/), float)<br>
>specdn=new( (/nyears,ncases,nspec,nvlevs,100,100/), float)<br>
>specdntmp=1.<br>
><br>
>;abnormal !!!! It seemed that no values were passed to colspec !!!!<br>
>colsepc=dim_avg_n((/colspectmp/), 3)<br>
>print(avg(colspec))<br>
><br>
>;normal !!!!<br>
>specdn=dim_avg_n((/specdntmp/), 3)<br>
>print(avg(specdn))<br>
><br>
>end<br>
>--------------------------------------------------------------------------------------<br>
><br>
>Q2:What's the difference between numeric and float when using userdefined function. though max((/a,b/)) would do the same thing, I am<br>
>eager to know the answer.<br>
>QUESTION2---------------------------------------------------------------------------------<br>
>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br>
>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br>
>load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"<br>
><br>
>undef( "fmax2v")<br>
>function fmax2v(x:float, y:float)<br>
>begin<br>
> if (x .ge. y) then<br>
> return(x)<br>
> else<br>
> return(y)<br>
> end if<br>
>end<br>
><br>
>undef( "max2v")<br>
>function max2v(x:numeric, y:numeric)<br>
>begin<br>
> if (x .ge. y) then<br>
> return(x)<br>
> else<br>
> return(y)<br>
> end if<br>
>end<br>
><br>
>begin<br>
><br>
>x=3<br>
><br>
>; normal loops !!!!!<br>
>do ii=1, 2<br>
>do jj=1, 3<br>
> print("ii="+(/ii/)+" jj="+(/jj/))<br>
> print("1: "+(/fmax2v(ii-x,0)/))<br>
> tmp=(/fmax2v(ii-x,0)/)<br>
> print("2: "+ (/tmp/))<br>
>end do<br>
>end do<br>
><br>
>; abnormal loops !!!!<br>
>do ii=1, 2<br>
>do jj=1, 3<br>
> print("ii="+(/ii/)+" jj="+(/jj/))<br>
> print("1: "+(/max2v(ii-x,0)/))<br>
> tmp=(/max2v(ii-x,0)/)<br>
> print("2: "+ (/tmp/))<br>
>end do<br>
>end do<br>
><br>
><br>
>end<br>
>--------------------------------------------------------<br>
><br>
>With best regards.<br>
><br>
><br>
><br>
><br>
><br>
><br>
>_______________________________________________<br>
>ncl-talk mailing list<br>
>List instructions, subscriber options, unsubscribe:<br>
><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</div></div></blockquote></div><br></div></div>