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

Guido Cioni guidocioni at gmail.com
Fri Nov 4 09:15:39 MDT 2016


Hey Juris,
the error is exactly telling you what the problem is: lon2d and lat2d, the variables that you are using to loop on the domain, are 2-Dimensional. You need 1-D integer array to do loops :) 

Some other suggetions:

[1] I'm not using WRF data so often, but I believe that you'd need to convert into a "normal" netcdf file before plotting with NCL in order to have the minimum number of issues. Have you done that? As far as I remember, XLAT and XLONG are the "old" unformatted variables.

[2] You can achieve the same goal with the aid of the where function, which should be more efficient since is doing the loop internally. Something like that should work (note that you don't need to define the array before since it will automatically be defined depending on rain and snow array!).

[!NOT TESTED]
transition=where( snow.gt.0  .AND. rain.gt.0, snow+rain, transition at _FillValue)

Cheers

Guido Cioni
http://guidocioni.altervista <http://guidocioni.altervista/>.org

> On 04 Nov 2016, at 16:09, Juris Almonte <Juris.Almonte at umanitoba.ca> wrote:
> 
> 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
> 
> 
> 
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

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


More information about the ncl-talk mailing list