[ncl-talk] sub: array assignment

dale zuri dalezuri at gmail.com
Wed Apr 29 02:59:26 MDT 2020


Hi Dave,
Thanks.

DZ

On Wed, Apr 29, 2020 at 12:34 AM Dave Allured - NOAA Affiliate <
dave.allured at noaa.gov> wrote:

> Do not use ".eq." to compare type logical to a number.  Just use the
> logical directly within an "if" statement.
>
> No:    if (.not.ismissing(M(i,j)) .eq. 1) then
> Yes:   if (.not.ismissing(M(i,j))) then
>
> Also you have one too many loops to do what you want, as Jonathan already
> indicated.  Also, use print statements to see what is going on.  Try this.
>
>    print ("Number not missing = " + num (.not. ismissing (M)))
>    k = 0
>    do i=0,(dimsizes(lat2d(:,0))-1)
>      do j=0,(dimsizes(lon2d(0,:))-1)
>         if (.not.ismissing(M(i,j)) .eq. 1)then
>            k = k + 1
>            M(i,j) = k
>         end if
>      end do
>    end do
>    print ("Number of assignments = " + k)
>
>
> On Tue, Apr 28, 2020 at 9:15 PM dale zuri via ncl-talk <ncl-talk at ucar.edu>
> wrote:
>
>> Hi NCL user,
>>  I have been trying to assign number 1,2, 3 etc, for the specific
>> locations. But this piece of code seems to break and not producing any
>> results. I would appreciate any help to fix this problem.
>>
>> Thanks in advance!
>> do k=0, 8242
>>
>>    do i=0,(dimsizes(lat2d(:,0))-1)
>>
>>      do j=0,(dimsizes(lon2d(0,:))-1)
>>
>>         if (.not.ismissing(M(i,j)) .eq. 1)then
>>
>>            M(i,j)= k
>>
>>         end if
>>
>>      end do
>>
>>    end do
>>
>> end do
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200429/dcdce5e0/attachment.html>


More information about the ncl-talk mailing list