[ncl-talk] NCL can't recognize a string as a variable name

Rashed Mahmood rashidcomsis at gmail.com
Sat Nov 6 18:18:43 MDT 2021


Hi Tabish,
Your variable S is essentially a new string variable so it is not going to
represent your level variable names.

One way to do this is to use ListPush and ListPop :
https://www.ncl.ucar.edu/Document/Functions/Built-in/ListPush.shtml
e.g. after defining levels:

lev_list = NewList("fifo")

ListPush(lev_list, lev21)
ListPush(lev_list, lev22)
...
ListPush(lev_list, lev31)

levels := ListPop(lev_list)
res at cnLevels   := levels

I guess there are other methods for listing variables, but I think this
should work.

Cheers,
Rashed


On Sat, Nov 6, 2021 at 3:19 PM Tabish Ansari via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Hi
>
> I'm using an NCL script to create contour plots for different days where
> everything but the contour levels remain the same. I have already defined
> the contour levels explicitly for all the days but I don't want to
> comment/uncomment them each time I run the script for different days. So,
> I'm looking for a more efficient way to do it.
>
> Here's the code snippet:
> =======================================================================
>   lev21    = (/ 5,10,15,20,25,30,35/)   ; set levels for 21Oct
>   lev22    = (/ 25,30,35,40,45,50,55,60,65,70,75,80,85/)   ; set levels
> for 22Oct
>   lev23    = (/ 25,50,75,100,125,150,175,200/)   ; set levels for 23Oct
>   lev24    = (/ 75,100,125,150,175,200,225,250,275,300/)   ; set levels
> for 24Oct
>   lev25    = (/ 75,100,125,150,175,200,225,250,275/)   ; set levels for
> 25Oct
>   lev26    = (/ 5,10,15,20,25,30,35/)   ; set levels for 26Oct
>   lev27    = (/ 5,10,15,20,25,30,35,40,45,50/)   ; set levels for 27Oct
>   lev28    = (/ 25,30,35,40,45,50,55,60,65,70,75,80,85/)   ; set levels
> for 28Oct
>   lev29    = (/ 25,50,75,100,125,150,175/)   ; set levels for 29Oct
>   lev30    = (/ 75,100,125,150,175,200,225,250,275/)   ; set levels for
> 30Oct
>   lev31    = (/ 25,50,75,100,125,150,175,200/)   ; set levels for 31Oct
>
>   N = day + 21
>   S = "lev"+N
>   print(S)
>   res at cnLevels    = $S$
> ==========================================================================
>
> Here, I'm just setting the value for "day" between 0 and 10 and I'm able
> to create a string S with exactly the same name as those arrays that I have
> defined, which contain the contour levels. But NCL won't accept a string as
> a variable name. Is there anyway around this?
>
> Thank you
>
> Tabish
>
>
> *----------------------------------------------------------Dr Tabish U
> Ansari <https://www.rug.nl/staff/t.u.ansari/>*
> *Assistant Professor - Earth & Energy*
>
> *University of Groningen - Campus Fryslân <https://www.rug.nl/cf/?lang=en>*
>
> *Leeuwarden, the Netherlands*
> *ResearchGate <https://www.researchgate.net/profile/Tabish_Ansari> |
> Google Scholar
> <https://scholar.google.com/citations?user=E94r-mwAAAAJ&hl=en&oi=ao> |
> Twitter <https://twitter.com/tabishbiet> *
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20211106/1bc24731/attachment.html>


More information about the ncl-talk mailing list