[ncl-talk] sub: array assignment

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Wed Apr 29 02:34:14 MDT 2020


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/542be89c/attachment.html>


More information about the ncl-talk mailing list