[ncl-talk] index lists in assignment

Seifert Axel Axel.Seifert at dwd.de
Sat Nov 24 07:16:43 MST 2018


Hi,


I have a somewhat unexpected behavior when using index lists. Here a simplified example:

  x = new( 3, float)
  x = 0.0
  y = x

  z = (/1.,2.,3./)
  idx = (/1,2,1/)

  x(idx) = x(idx) + z

  do i=0,dimsizes(idx)-1
    y(idx(i)) = y(idx(i)) + z(i)
  end do

  print(" "+x+" "+y)

I would have expected that x and y end up being the same, but they are not. The double assignment to index 1 does not work for the vector assignment. Is this the intended behavior for arrays in ncl?

How can I get the 2nd behavior and still avoid the do-loop?

In my case I am assigning measured values from satellite overpasses to a global grid and it can of course happen that I have multiple overpasses for a grid point in an observation vector. Hence, in addition to the sum of the values I would count the number of overpasses

  cnt = (/0,0,0/)
  cnt(idx) = cnt(idx) + 1
  print(" "+cnt)

and then xavg = x/cnt should give me the proper average for, for example, one hour of data. What I need in the end is the correct average for xavg and the number of measurements used at each grid point.

Thanks in advance for any helpful comments and suggestions.

Axel





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181124/0bc6b727/attachment.html>


More information about the ncl-talk mailing list