# [ncl-talk] do loop and rtest problem

Dennis Shea shea at ucar.edu
Thu Aug 14 06:25:11 MDT 2014

```Ditto what Alan has written.
======================
If you are new to NCL, please read the 'Mini-Reference Manual' at:
http://www.ncl.ucar.edu/Document/Manuals/
=======================

You must have had error message indicating that 'escar' was undefined.
Error messages should be read, they often will tell you the exact problem.

That said:

[1]
The *autocorrelation* function 'esacr' *may* be what you want to use.

https://www.ncl.ucar.edu/Document/Functions/Built-in/esacr.shtml

-----
*mxlag*

A scalar integer. It is recommended that 0 <= mxlag <= N/4. This is because
the correlation

algorithm(s) use N rather than (N-k) values in the denominator (Chatfield
Chapter 4).

-----
REPLACE

do LAG=0,dimsizes(indx_sst)-1
crr_indx=escar(indx_sst,LAG)
crr_DJF=escar(rr_DJF,LAG)
end do

WITH (NOTE: *no do loop used* ; NCL is an array language; ;     again,

LAGMX = dimsizes(indx_sst)/4
acr_indx = esacr(indx_sst, LAGMX)
acr_DJF =esacr(rr_DJF, LAGMX)

**Use 'printVarSummary' often and carefully look** at the dimensions sizes
and
shape of the resultant variables.

printVarSummary(acr_indx)     ; acr_indx(LAGMX)
printVarSummary(acr_DJF)     ; acr_DJF(nlat,mlon,LAGMX)
;
0     1         2
print(acr_indx)

[2]
**After you have carefully examined the output from the above statements**,
you will note that
the array shapes are different (one-dimension & three-dimension).

You can not directly multiply 1D and 3D arrays. You must use the 'conform'
function:

https://www.ncl.ucar.edu/Document/Functions/Built-in/conform.shtml
<https://www.ncl.ucar.edu/Document/Functions/Built-in/conform.shtml>

After reading the documentation including examples, you will do the
following:

acr_indx_3d = conform(acr_DJF, acr_indx, 2)
printVarSummary(acr_indx_3d)                         ;
acr_indx_3d(nlat,mlon,LAGMX)

Now you want to sum the LAGMX auto-correlations  at each grid point. No 'do
loop' necessary.

https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum_n.shtml
<https://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum_n.shtml>

c = dim_sum_n(acr_indx_3d*acr_DJF, 2)
printVarSummary(c)                                             ;
c(nlat,mlon)

[3]
d = 1+ 2*c
printVarSummary(d)                                             ;
d(nlat,mlon)

df = dimsizes(indx_sst)/d
printVarSummary(df)                                            ;
df(nlat,mlon)
print("df: min="+min(df)+"   max="+max(df))        ; does this look
reasonable?

rtest requires that the 'df' to be integer

https://www.ncl.ucar.edu/Document/Functions/Built-in/rtest.shtml

Further, as previously noted, 'rtmp' is nowhere to be seen, presumably
rtmp(nlat,mlon)

r_test=rtest(rtmp, toint(df), 0) ; presumably 'rtmp' is defined
'somewhere'

printVarSummary(r_test)                                            ;
r_test(nlat,mlon)
print("r_test: min="+min(r_test)+"   max="+max(dr_test))

On Wed, Aug 13, 2014 at 7:59 AM, Alan Brammer <abrammer at albany.edu> wrote:

>
> Marcia,
> See some of my comments for each line below.  Next time send the list the
> specific error messages and/or the whole ncl code.  The error messages are
> usually very specific about the problem, which would save the list from
> trying to guess at the problem.
>
>
> You may just have a typo with respect to esacr() / escar()  but the other
> comments I think are still valid.
>
>
>
> ;====  rtest ====================================
>  ;==== dimension : sst_DJF_anom(time,lat,lon), indx_sst(time)
> ;=============================================
>
>
> rr_DJF=sst_DJF_anom(lat|:,lon|:,time|:)
>
>
> do LAG=0,dimsizes(indx_sst)-1 ; Is this the whole code ? Where was
> indx_sst defined?
>  crr_indx=escar(indx_sst,LAG) ; Do you mean for crr_indx to just keep
> being over written ?
>  crr_DJF=escar(rr_DJF,LAG) ; Also what is escar()  It doesn’t appear to
> be an NCL supported function?
>
>   ; Do you mean to be using esccr ()  or esacr () ?
>
> end do
>
> c =0
> do i=1,dimsizes(indx_sst)
>  c= c+crr_indx*crr_DJF ; Again is you’re just multiplying by 2 scalar
> values and incrementing c. Not sure what the point of this is.
> end do
>
> d = 1+ 2*c
>
>
> df = dimsizes(indx_sst)/d
>
>  r_test=rtest(rtmp, df, 0) ;  Where was rtmp defined?   Was it defined ?
>
>
>
> Alan.
>
>
>
>
>
>
>
> ##############################
> Alan Brammer,
> PhD candidate,
>
> Department of Atmospheric and Environmental Sciences,
> University at Albany, State University of New York, Albany, NY, 12222
> abrammer at albany.edu
> ##############################
>
> _______________________________________________
> ncl-talk mailing list
> 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/20140814/9d224591/attachment.html
```