[ncl-talk] conversion from loop to array syntax

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Fri Nov 11 18:25:06 MST 2022


I think what is happening is, NCL does not understand the intent to
synchronize the two subscript ranges.  It tries to run them independently,
which means a 2621442 x 2621442 array.  Boom!

There might be an array syntax for this, but I can't think of one right
now.  Synchronized ranges work well for separate terms in an expression,
but I think not within a single 2+ dimensional subscript expression.  You
might be stuck with that loop.  Just code that as compactly as possible,
when N is large.  Or maybe, resort to an external helper function.


On Fri, Nov 11, 2022 at 8:11 PM Laura Fowler <laura at ucar.edu> wrote:

> Hi Dave:
> Thanks for your reply. I did get the same segmentation fault (see below).
> I do not know what you mean by "replacement operator".
> Thanks,
> Laura
>
>
> (0) --- nCells  = 2621442
>
> (0) --- nLevels = 55
>
> fatal:NclMalloc Failed:[errno=12]
>
> Segmentation fault (core dumped)
>
>
> On Fri, Nov 11, 2022 at 6:03 PM Dave Allured - NOAA Affiliate <
> dave.allured at noaa.gov> wrote:
>
>> Laura, I am not sure that will work.  But if it does, assign the result
>> to a new variable, not a predefined one.  Or else use the replacement
>> operator.  Try this, see if you get the expected result dimensions:
>>
>>       pp = pres(:,kpbl(:))
>>
>> Also, it is simply ncl-talk at ucar.edu.
>>
>>
>> On Fri, Nov 11, 2022 at 7:06 PM Laura Fowler via ncl-talk <
>> ncl-talk at mailman.ucar.edu> wrote:
>>
>>> Hello:
>>> I have an integer array that includes the index of the PBL top (kpbl). I
>>> would like to get the pressure (press) corresponding to the index of the
>>> PBL top. A printVarSummary provides the following information:
>>>
>>> Variable: kpbl
>>>
>>> Type: integer
>>>
>>> Total Size: 10485768 bytes
>>>
>>>             2621442 values
>>>
>>> Number of Dimensions: 1
>>>
>>> Dimensions and sizes: [nCells | 2621442]
>>>
>>> Coordinates:
>>>
>>> Number Of Attributes: 2
>>>
>>>   units : unitless
>>>
>>>   long_name : index level of PBL top
>>>
>>>
>>> Variable: pres
>>>
>>> Type: float
>>>
>>> Total Size: 576717240 bytes
>>>
>>>             144179310 values
>>>
>>> Number of Dimensions: 2
>>>
>>> Dimensions and sizes: [nCells | 2621442] x [nVertLevels | 55]
>>>
>>> Coordinates:
>>>
>>> Number Of Attributes: 3
>>>
>>>   _FillValue : 9.96921e+36
>>>
>>>   units : hPa
>>>
>>>   long_name : Pressure at layer midpoint
>>>
>>>
>>> where nCells is the number of grid columns and nVertLevels is the
>>> number of vertical levels. Below is the loop that I would like to convert
>>> to a more compact array syntax:
>>>
>>>
>>> do n = 0,nCells-1
>>>
>>>    pp(n) = pres(n,kpbl(n))
>>>
>>>    print("--- n = "+n +" "+kpbl(n) +"  "+pres(n,kpbl(n)) +"  "+pp(n))
>>>
>>> end do
>>>
>>>
>>> When I convert the loop above to the following array syntax (see below),
>>> I unfortunately get a "Segmentation Fault".
>>>
>>> pp(:) = pres(:,kpbl(:))
>>>
>>>
>>> fatal:VarVarWrite: Number of dimensions on left hand side does not match
>>> right hand side
>>>
>>> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 207 in
>>> file plot.pressure.ncl
>>>
>>>
>>>
>>> Can somebody help me figure this out. I would really appreciate it.
>>>
>>> Thanks,
>>>
>>> Laura
>>>
>>>
>>> note: I posted the same email this morning, but to the address
>>> ncl-talk-request at ucar.edu. Not sure which email to use for posts. Sorry
>>> about the double email message.
>>>
>>>
>>> !-------------------------------------------------------------------------------------------------------------
>>> Laura D. Fowler
>>>
>>> Mesoscale and Microscale Meteorology Division (MMM)
>>> National Center for Atmospheric Research
>>> P.O. Box 3000, Boulder CO 80307-3000
>>>
>>> e-mail: laura at ucar.edu
>>> phone: 303-497-1628
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221111/b6567277/attachment.htm>


More information about the ncl-talk mailing list