[ncl-talk] Loop creating different variable names

Anne anne.seidenglanz at unive.it
Tue Mar 27 09:59:49 MDT 2018


Hi Kevin,

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):
[Note here 'year' and 'Year' are defined elsewhere in the script]

*ens=(/"001","011","012"/)*
*Ts = True*


*do e=0,dimsizes(ens)-1*

*  ctrl_dir =
"/work/as10017/SPS_hindcast_1993_2016/Ini_11_cam/daily_surface/sps_"+year+"11_"+ens(e)+"/"*
*  ctrl_fil =
"CMCC_sps_201111_"+ens(e)+".atm.h3."+year+"11-"+Year+"04.reg.nc
<http://04.reg.nc>"*
*  path=ctrl_dir+ctrl_fil*
*  fc=addfile(ctrl_dir+ctrl_fil,"r")*
*  Ts_@$ens(e)$ = fc->TS*
*  delete(fc)*
* end do*

However, NCL doesn't seem to recognize the @ syntax, because it gives me
the following error message:

*fatal:Variable (Ts_) is undefined, can not assign attribute (001)*

So somehow 001, 011, 012 are not being recognized. Is it because they are
numbers instead if strings?

Any help appreciated!
thanks,
Anne


On Tue, Mar 27, 2018 at 4:49 AM, Anne <anne.seidenglanz at unive.it> wrote:

> Hi Kevin,
>
> 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
>
> printVarSummary(Ts at 001)
>
> NCL complains about the @ sign, and it doesn't proceed. Do you have any
> idea why?
>
> Thanks,
> Anne
>
> On Tue, Feb 27, 2018 at 4:42 PM, Kevin Hallock <hallock at ucar.edu> wrote:
>
>> 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
>>
>>
>>
>

-- 
Nota automatica aggiunta dal sistema di posta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180327/a67f0fc4/attachment.html>


More information about the ncl-talk mailing list