[ncl-talk] looping through 2d array to find conditional statement

Juris Almonte Juris.Almonte at umanitoba.ca
Fri Nov 4 09:09:49 MDT 2016


Hi NCL talk,

I am trying to create an array with values where a conditional statement is true (where both snow and rain are >0).  Basically, I am looking to find where a transition region (from snow to rain) is occurring, by finding where rain and snow are occurring at the same time. I receive the following error: fatal:Loop variable must be scalar, can't execute loop

Is there any better way at approaching this or suggestions for my code?

Here is the relevant code:

; size of grid (1015,1359) over conus

lat2d = wrf_user_getvar(b,"XLAT",0) ;2d array (xlat,xlong)
lon2d = wrf_user_getvar(b,"XLONG",0)
precip = wrf_user_getvar(a,"PREC_ACC_NC",0) ;2d array (xlat,xlong) total hourly accumulated precip
snow = wrf_user_getvar(a,"SNOW_ACC_NC",0)
graup = wrf_user_getvar(a,"GRAUPEL_ACC_NC",0)
rain = precip-graup-snow

transition = new(dimsizes(precip),typeof(precip),precip at _FillValue) ;creating a new array

do lon2d=1,1358
do lat2d=1,1014

if (snow(lat2d,lon2d) .gt. 0 .and. rain(lat2d,lon2d) .gt. 0) then
transition(lat2d,lon2d) = snow(lat2d,lon2d)+rain(lat2d,lon2d)

end if
end do
end do

Thanks for your help,

Juris
M.Sc. student
University of Manitoba




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161104/dbc4ea68/attachment.html 


More information about the ncl-talk mailing list