<div dir="ltr">NCL variables are based upon the netCDF variable data structure. Generally, NCL variables adhere to netCDF rules regarding attributes and coordinate variables.<br><br>By netCDF rule, an attribute can only be assigned to a *<b>pre-existing</b>* variable. You have:<br><br><b>Ts</b> = True     ; variable Ts<br>ens=(/"001","011","012"/)<br>e  = 0<br><br><div>Later, you use <b>Ts_</b><i>  </i>as a variable name. There is no pre-existing variable <b>Ts_</b> . Hence, <br><br><b>Ts_</b>@$ens(e)$ = fc->TS<i><br></i><br></div><div>will fail<i> </i>with an error message saying the <b>Ts_</b> does not exist. <br>This has nothing to do with the attribute assignment per se.<i><br><br></i>===<br><br></div><div>You can do the following:<br></div><div><i><br></i><b>Ts</b>_ = True     ; variable Ts_<i><br></i><div><br></div>Since <b>Ts_</b> exists<br><br><b>Ts_</b>@$ens(e)$ = fc->TS<i><br><br></i></div><div>However, <b>by netCDF rules</b> which NCL follows <br><br>[1] A variable's attribute can not have its own attributes.  'Attribute cascade' (ie: attributes of attributes) is not allowed.<br></div><div>[2] A variable's attribute can not have coordinate variables associated with it. <br></div><div>[3] netCDF allows  only one-dimensional arrays for attributes.<br><br></div><div>Presumably, the 'TS" variable being imported has named dimensions, coordinates, attributes and is multidimensional.  <br><br>You hit the 'jack-pot'! The simple import statement you used has violated multiple netCDF (hence, NCL) rules. :-)    :-)    :-)<br><br>Likely, NCL did not know what to do! My speculation, is that you would get a variable <b>T</b>s_ size [1] of type logical with a *one-dimensional* array of attributes with no attribute name!! <br><br>====<br></div><div>For a simple illustration:<br><br><br>  X =True ; create variable <br><br>  foo = "FOO"        ; string<br>  X@$foo$ = (/2, -5, 3/)<br><br>  foo2= "FOO2"<br>  X@foo2 = (/ (/10,20/), (/30,40/) /)    ; 2x2 array<br><br>  printVarSummary(X)<br><br>====<br></div><div>Variable: X<br>Type: logical<br>Total Size: 4 bytes<br>            1 values<br>Number of Dimensions: 1<br>Dimensions and sizes:    [1]<br>Coordinates: <br>Number Of Attributes: 2<br>  foo2 :    ( 10, 20, 30, 40 )      ; note one-dimensional<br>  FOO :    ( 2, -5, 3 )<br>=====<br><br></div><div>OK, What to do? <br><br>I would suggest:<br><br><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml">https://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml</a><br><br><pre>[ncl_join | 5] x [time | ??] x [lev | ?] x [lat | ?] x [lon | ?]<br><br></pre><pre>You can change the 0-th name<br><br></pre><pre>  TS!0 = "ensemble"<br><br>[ensemble | 5] x [time | ??] x [lev | ?] x [lat | ?] x [lon | ?]</pre></div><div>This allows for explicit acces to each or all ensemble members.<br><br>===<br><br></div><div>The key is accessing ensemble members in different directories.<br><br><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml">https://www.ncl.ucar.edu/Document/Functions/Built-in/systemfunc.shtml</a><br><br></div><div>Think about it.<br><br></div><div>Good Luck<br></div><div><br></div><div><br></div><div><i></i></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 27, 2018 at 9:59 AM, Anne <span dir="ltr"><<a href="mailto:anne.seidenglanz@unive.it" target="_blank">anne.seidenglanz@unive.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Kevin,<div><br></div><div>I just wanted to be a little clearer on what I meant in my last email; I created a loop in which I loop over 3 ensemble members, and using the approach to define the single members as attributes of 'Ts' (last conversation):</div><div>[Note here 'year' and 'Year' are defined elsewhere in the script]</div><div><i><br></i></div><div><div><i>ens=(/"001","011","012"/)</i></div><div><i>Ts = True</i></div><div><i><br></i></div><div><i>do e=0,dimsizes(ens)-1<br></i></div><div><i>  ctrl_dir = "/work/as10017/SPS_hindcast_<wbr>1993_2016/Ini_11_cam/daily_<wbr>surface/sps_"+year+"11_"+ens(<wbr>e)+"/"<br></i></div><div><i>  ctrl_fil = "CMCC_sps_201111_"+ens(e)+".<wbr>atm.h3."+year+"11-"+Year+"<a href="http://04.reg.nc" target="_blank">04.<wbr>reg.nc</a>"</i></div><div><i>  path=ctrl_dir+ctrl_fil</i></div><div><i>  fc=addfile(ctrl_dir+ctrl_fil,"<wbr>r")</i></div><div><i>  Ts_@$ens(e)$ = fc->TS</i></div><div><i>  delete(fc)</i></div><div><i> end do</i></div></div><div><br></div><div>However, NCL doesn't seem to recognize the @ syntax, because it gives me the following error message: </div><div><br></div><div><i>fatal:Variable (Ts_) is undefined, can not assign attribute (001)</i><br></div><div><i><br></i></div><div>So somehow 001, 011, 012 are not being recognized. Is it because they are numbers instead if strings?</div><div><br></div><div>Any help appreciated!</div><div>thanks,</div><div>Anne</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 27, 2018 at 4:49 AM, Anne <span dir="ltr"><<a href="mailto:anne.seidenglanz@unive.it" target="_blank">anne.seidenglanz@unive.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Kevin,<div><br></div><div>thanks for your advice, I have implemented what you wrote above just for another case this time (ensemble members instead of months), however, when doing </div><div><br></div><div>printVarSummary(Ts@001)<br></div><div><br></div><div>NCL complains about the @ sign, and it doesn't proceed. Do you have any idea why?</div><div><br></div><div>Thanks,</div><div>Anne</div></div><div><div class="h5"><div class="m_3246546503473191955HOEnZb"><div class="m_3246546503473191955h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 27, 2018 at 4:42 PM, Kevin Hallock <span dir="ltr"><<a href="mailto:hallock@ucar.edu" target="_blank">hallock@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Anne,<div><br></div><div>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.</div><div><br></div><div>I think the idea you found about treating months as attributes of another variable might be the easiest way to proceed:</div><span><div><font face="Menlo">month = (/"nov", "dec", "jan”/)</font></div></span><div><font face="Menlo">var_nsidc = True</font></div><div><font face="Menlo">do m=0,dimsizes(month)-1</font></div><div><font face="Menlo">  var_nsidc@$month(m)$ = var_dtrend_nsidc(0::12,:,:)</font></div><div><font face="Menlo">end do</font></div><div><font face="Menlo"><br></font></div><div><div><font face="Menlo">print(var_nsidc@nov)</font></div></div><div><div><font face="Menlo">print(var_nsidc@dec)</font></div></div><div><font face="Menlo"><br></font></div><div>I hope this helps,</div><div>Kevin</div><div><br><div><blockquote type="cite"><div><div class="m_3246546503473191955m_1611788735368299272h5"><div>On Feb 27, 2018, at 4:18 AM, Anne <<a href="mailto:anne.seidenglanz@unive.it" target="_blank">anne.seidenglanz@unive.it</a>> wrote:</div><br class="m_3246546503473191955m_1611788735368299272m_1163896649899553827Apple-interchange-newline"></div></div><div><div><div class="m_3246546503473191955m_1611788735368299272h5"><div dir="ltr">Hello,<div><br></div><div>I am trying to loop through a number of months (like <i>month = (/"nov", "dec", "jan"/)</i>) 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, <i>in order to become part of the new variable name</i>, so as to make the script shorter and better readable.<br></div><div>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?</div><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">month = (/"nov", "dec", "jan"/)</span><br></div><div><br></div><div><div> do m=0,dimsizes(month)-1</div><div>   var_$month(m)$_nsidc = var_dtrend_nsidc(0::12,:,:)<br></div><div> end do</div></div><div><br></div><div><i>I want to end up with:</i></div><div>var_nov_nsidc</div><div>var_dec_nsidc</div><div>var_jan_nsidc</div><div><br></div><div><br></div><div>What am I doing wrong here?</div><div><br></div><div>Any help appreciated,</div><div>thanks</div><div>Anne</div><div><br></div><div><br></div><div><br><div class="gmail_extra"><br><div class="gmail_quote"><br></div></div></div></div>

<br>
</div></div><div><font style="font-family:Arial,Helvetica,sans-serif" size="2">Nota automatica aggiunta dal sistema di posta.</font></div><div><img src="https://www.unive.it/media/banner_150.jpg"></div>______________________________<wbr>_________________<br>ncl-talk mailing list<br><a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>List instructions, subscriber options, unsubscribe:<br><a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailma<wbr>n/listinfo/ncl-talk</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>
</div></div></div></div></blockquote></div><br></div><div class="HOEnZb"><div class="h5">

<br>
<div><font style="font-family:Arial,Helvetica,sans-serif" size="2">Nota automatica aggiunta dal sistema di posta.</font></div><div><img src="https://www.unive.it/media/banner_150.jpg"></div></div></div><br>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>