[ncl-talk] how to fill an array with an other

Rashed Mahmood rashidcomsis at gmail.com
Wed May 6 11:51:58 MDT 2020


Hi Laura,
There is nothing to be afraid of the loops!,  infect they are very useful
in this type situations and i do not think that it would be too slow in
this case.

Cheers,
Rashed


On Wed, May 6, 2020 at 7:26 AM Laura Fowler <laura at ucar.edu> wrote:

> Hi Rashed:
> What your proposed only works if I were to loop over cells. This would
> take quite some time if cells were a large number? There must be some kind
> of an array syntax to do this.
> Thanks,
> Laura
>
> On Tue, May 5, 2020 at 12:08 PM Rashed Mahmood <rashidcomsis at gmail.com>
> wrote:
>
>> Hi Laura,
>> The error message is telling what is wrong, you defining a one
>> dimensional and then trying to assign it two dimensional data:
>> *ppbl = new((/cells/),typeof(p))*
>>
>> *ppbl(0:cells-1) = p(0:cells-1,kpbl(0:cells-1)) ; this is 2D and even
>> wrong dimension sizes note the nVertLevels*
>>
>>
>> I am not sure if the following is what you want?
>>
>> vlevel = 0 ; 0 or any other VertLevels
>> ppbl = new((/cells/),typeof(p))
>> ppbl(0:cells-1) = p(0:cells-1,vlevel)
>>
>>
>> Cheers,
>> Rashed
>>
>>
>>
>> On Tue, May 5, 2020 at 8:37 AM Laura Fowler via ncl-talk <
>> ncl-talk at ucar.edu> wrote:
>>
>>> Hello:
>>> I cannot figure out how to do the following and would love to get some
>>> help:
>>>
>>> I have an array kpbl which contains the vertical index of the PBL top:
>>> printVarSummary gives:
>>>
>>> Variable: kpbl
>>>
>>> Type: integer
>>>
>>> Total Size: 15728832 bytes
>>>
>>>             3932208 values
>>>
>>> Number of Dimensions: 2
>>>
>>> Dimensions and sizes: [Time | 13] x [cells | 163842]
>>>
>>> Coordinates:
>>>
>>> Number Of Attributes: 2
>>>
>>>   units : unitless
>>>
>>>   long_name : index level of PBL top
>>>
>>>
>>>
>>> I have a second array p which contains the 3D pressure: print VarSummary
>>> gives:
>>>
>>>
>>> Variable: p
>>>
>>> Type: float
>>>
>>> Total Size: 865085760 bytes
>>>
>>>             216271440 values
>>>
>>> Number of Dimensions: 3
>>>
>>> Dimensions and sizes: [Time | 13] x [cells | 163842] x [nVertLevels |
>>> 55]
>>>
>>> Coordinates:
>>>
>>> Number Of Attributes: 2
>>>
>>>   units : hPa
>>>
>>>   long_name : Pressure
>>>
>>>
>>>
>>> What I would like to get is the pressure at the index level kpbl, i.e.
>>> pressure at the PBL top. In fortran and for one time-level (itime), I would
>>> have a loop like:
>>>
>>> do icell = 0, cells-1
>>>      ppbl(itime,icell) = p(itime,icell,kpbl(iCell))
>>> end do
>>>
>>> In NCL, I tried the following (for one time-level):
>>> ppbl = new((/cells/),typeof(p))
>>> ppbl(0:cells-1) = p(0:cells-1,kpbl(0:cells-1))
>>>
>>> but this does not work. I get an error message that the left and right
>>> side do not have the same dimensions. I am definitely running out of ideas
>>> on how to solve this and would appreciate a hint.
>>>
>>> Many thanks,
>>> Laura
>>>
>>> --
>>>
>>> !-------------------------------------------------------------------------------------------------------------
>>> 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
>>>
>>>
>>> !-------------------------------------------------------------------------------------------------------------
>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> --
>
> !-------------------------------------------------------------------------------------------------------------
> 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: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20200506/90c8c596/attachment.html>


More information about the ncl-talk mailing list