# [ncl-talk] do loop based on variable similar names

xyzheng at mail.ustc.edu.cn xyzheng at mail.ustc.edu.cn
Thu Nov 10 18:20:34 MST 2016

```Thanks s lot for your detailed answer，the solution is very smart!(*^__^*)

Sorry for a careless mistake in the previous reply.

The do loop should be better starting from 0 in NCL.

izMin = (/.../)
izMax = (/.../)

do i = 0, 12
iz = ind(field(0,:).ge.izMin(i) .and. field(0,:).lt.izMax(i)) ; define izMin and izMax explicitly before executing the loop

if (.not. any(ismissing(iz)) then
print("Number of data fall between "+ izMin(i) + " and " + izMax(i) + " = " + dimsizes(iz))
else
print("No data can be found for the values between "+ izMin(i) + " and " + izMax(i))
end if

delete(iz)
end do

2016-11-10 9:05 GMT+01:00 Hoffman Cheung <hoffmancheung at gmail.com>:

Hi Zoey,

In this case, you may just read the values inside the do loop, and delete the variable at the end of the loop.

izMin = (/.../)
izMax = (/.../)

do i = 1, 13
iz = ind(field(0,:).ge.izMin(i) .and. field(0,:).lt.izMax(i)) ; define izMin and izMax explicitly before executing the loop

if (.not. any(ismissing(iz)) then
print("Number of data fall between "+ izMin(i) + " and " + izMax(i) + " = " + dimsizes(iz))
else
print("No data can be found for the values between "+ izMin(i) + " and " + izMax(i))
end if

delete(iz)
end do

Cheers,
Hoffman

2016-11-10 3:44 GMT+01:00 <xyzheng at mail.ustc.edu.cn>:

Hello,
I am looking for a way to call a series of variables through  their names (string) in NCL.These variables are of different sizes,so they can't be set as an array iz(k) of fixed size. And Idon't know how to do loop and some other operations based on these similar namessince ("iz"+i) can't be identified as a variable in the following script. Can anyone help?
.....................................................................................................................

iz1=ind(fieldf(0,:).ge.0.and.fieldf(0,:).lt.1.5)
iz2=ind(fieldf(0,:).ge.1.and.fieldf(0,:).lt.2.2)
iz3=ind(fieldf(0,:).ge.2.2.and.fieldf(0,:).lt.3)
iz4=ind(fieldf(0,:).ge.3.and.fieldf(0,:).lt.4.2)
iz5=ind(fieldf(0,:).ge.4.2.and.fieldf(0,:).lt.5.6)
iz6=ind(fieldf(0,:).ge.5.6.and.fieldf(0,:).lt.6)
iz7=ind(fieldf(0,:).ge.6.and.fieldf(0,:).lt.7)
iz8=ind(fieldf(0,:).ge.7.and.fieldf(0,:).lt.8)
iz9=ind(fieldf(0,:).ge.8.and.fieldf(0,:).lt.9.1)
iz10=ind(fieldf(0,:).ge.9.1.and.fieldf(0,:).lt.10)
iz11=ind(fieldf(0,:).ge.10.and.fieldf(0,:).lt.11)
iz12=ind(fieldf(0,:).ge.11.and.fieldf(0,:).lt.12)
iz13=ind(fieldf(0,:).ge.12.and.fieldf(0,:).lt.13)

do i=1,13
print(dimsizes("iz"+i))
end do
....................................................................................................

Thanks very much,

Zoey

_______________________________________________
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/20161111/76ab428b/attachment.html
```