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

Hoffman Cheung hoffmancheung at gmail.com
Thu Nov 10 01:19:12 MST 2016


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 I don't know how to
>> do loop and some other operations based on these similar names since (
>> "iz"+i) can't be identified as a variable in the following script.  Can
>> anyone help?
>> ............................................................
>> .........................................................
>>
>> fieldf(0,:) = asciiread(fi,-1,"float")
>>    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/20161110/6a0b1084/attachment.html 


More information about the ncl-talk mailing list