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

Tabish Ansari tabishumaransari at gmail.com
Sat Nov 6 13:19:13 MDT 2021


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> *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20211106/d3943d22/attachment.html>


More information about the ncl-talk mailing list