[ncl-talk] index lists in assignment

Seifert Axel Axel.Seifert at dwd.de
Fri Nov 30 14:09:40 MST 2018


Hi Dennis and Rick,


Thanks for your comments. Yes, the do-loop is kind of slow and would then be the most expensive part of that script. The length of an observation vector is of order 100000 for one hour of satellite data and I have several months of data, which have to be processed for multiple model simulations.


I can probably restructure my data to avoid double indices, or multiple overpasses, in one observation vector. Alternatively, I could simply ignore that slight loss of data. At least, it would always use the newer data and overwrite the older data. This is probably not a bad choice as well.


Axel




________________________________
Von: Dennis Shea <shea at ucar.edu>
Gesendet: Freitag, 30. November 2018 20:21
An: Rick Brownrigg
Cc: Axel.Seifert at dwd.de; Ncl-talk
Betreff: Re: [ncl-talk] index lists in assignment

My recollection is that the way fortran and NCL handled 'indirect subscripting' (my words) yielded different results.
Hence, the 'expected results' are colored by past expeerience in fortran.

Unfortunately, I can not find my NCL/fortran   example. Sorry.

D


On Fri, Nov 30, 2018 at 11:27 AM Rick Brownrigg <brownrig at ucar.edu<mailto:brownrig at ucar.edu>> wrote:
Hi Axel,

Apologies in delay in getting back to you on this.  As far as I can tell, the behavior ox "x(idx) = x(idx) + z" is the intended behavior (perhaps not the same as "desired" behavior in your case), in the sense that the right-hand side is completely evaluated before the (re)assignment to the variable "x": is performed.

The do-loop approach does work -- it it just unbearably slow?  Without knowing more about your data, I don't have a suggestion for how to avoid looping.

Rick


On Thu, Nov 29, 2018 at 10:37 AM Axel Seifert <Axel.Seifert at dwd.de<mailto:Axel.Seifert at dwd.de>> wrote:


Maybe I should add that the output of my little script is


(0)      0 0
(1)      3 4
(2)      2 2


This is with NCAR Command Language Version 6.3.0


The variables x and y are


Variable: x
Type: float
Total Size: 12 bytes
            3 values
Number of Dimensions: 1
Dimensions and sizes:   [3]
Coordinates:
Number Of Attributes: 1
  _FillValue :  9.96921e+36
(0)      0
(1)      3
(2)      2

Variable: y
Type: float
Total Size: 12 bytes
            3 values
Number of Dimensions: 1
Dimensions and sizes:   [3]
Coordinates:
Number Of Attributes: 1
  _FillValue :  9.96921e+36
(0)      0
(1)      4
(2)      2



Am 24.11.2018 um 15:16 schrieb Seifert Axel:


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








_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk<https://ssi.dwd.de/mailman/listinfo/,DanaInfo=.ambkoqftG2lk2Lrr9+ncl-talk>


_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk<https://ssi.dwd.de/mailman/listinfo/,DanaInfo=.ambkoqftG2lk2Lrr9+ncl-talk>
_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk<https://ssi.dwd.de/mailman/listinfo/,DanaInfo=.ambkoqftG2lk2Lrr9+ncl-talk>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181130/f2a7742f/attachment-0001.html>


More information about the ncl-talk mailing list