[ncl-talk] Loop creating different variable names

Kevin Hallock hallock at ucar.edu
Tue Feb 27 08:42:29 MST 2018


Hi Anne,

Unfortunately, NCL’s “$var$” notation is only valid when used to reference a variable on a file (“file->$vars(n)$”) or attributes/dimensions on a variable (“var@$atts(n)$”) and cannot be used as part of a variable’s name.

I think the idea you found about treating months as attributes of another variable might be the easiest way to proceed:
month = (/"nov", "dec", "jan”/)
var_nsidc = True
do m=0,dimsizes(month)-1
  var_nsidc@$month(m)$ = var_dtrend_nsidc(0::12,:,:)
end do

print(var_nsidc at nov)
print(var_nsidc at dec)

I hope this helps,
Kevin

> On Feb 27, 2018, at 4:18 AM, Anne <anne.seidenglanz at unive.it> wrote:
> 
> Hello,
> 
> I am trying to loop through a number of months (like month = (/"nov", "dec", "jan"/)) to compute some climatologies (I know there are functions but I need to do it manually here). Because I am reading in and plotting 4 different data sets I am looking for way to loop over the months, in order to become part of the new variable name, so as to make the script shorter and better readable.
> My "$" syntax doesn't seem to work here (see below). There was an ncl talk a few years ago saying that one needs to treat the months as  attributes of another variable in order to be able to use the "$" syntax, is that still the case?
> 
> month = (/"nov", "dec", "jan"/)
> 
>  do m=0,dimsizes(month)-1
>    var_$month(m)$_nsidc = var_dtrend_nsidc(0::12,:,:)
>  end do
> 
> I want to end up with:
> var_nov_nsidc
> var_dec_nsidc
> var_jan_nsidc
> 
> 
> What am I doing wrong here?
> 
> Any help appreciated,
> thanks
> Anne
> 
> 
> 
> 
> 
> 
> Nota automatica aggiunta dal sistema di posta.
> 
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180227/3acddd27/attachment.html>


More information about the ncl-talk mailing list