# [ncl-talk] problem with specx_anal (ntim x nlat x nlon)

Lyndz olagueralyndonmark429 at gmail.com
Tue Aug 8 22:51:00 MDT 2023

```Dear NCL-experts,

I would like to do a spectral analysis on a *ntim x nlat x lon* data as
https://www.ncl.ucar.edu/Document/Functions/Built-in/specx_anal.shtml

*Specifically, I would like to get the mean spectra so that the final
output will have meanspectra x lat x lon*

*So far, I have the following:*

netcdf file
rain = ufile->rAnom_sm(:,:,:)

printVarSummary(rain)            ;[time | 6954] x [latitude | 220] x
[longitude | 220]

d   = 0
sm  = 1         ; periodogram
pct = 0.10

;************************************************
; calculate mean spectrum spectrum and lag1 auto cor
;************************************************

ntim = 6954
nlat = 220
nlon = 220

nseg = 49
nlen  = ntim/nseg

spcavg = new (ntim/141, typeof(rain))
printVarSummary(spcavg)
spcavg = new ( ntim/2, typeof(rain))
spcavg = 0.0
r1zsum = 0.0

do n=0,nseg-1
dof    =
specx_anal(rain(latitude|nl:nl,longitude|ml:ml,time|:),d,sm,pct)      ;
current segment spc
spcavg = spcavg + dof at spcx                ; sum spc of each segment
r1     = dof at xlag1                        ; extract segment lag-1
r1zsum = r1zsum  + 0.5*(log((1+r1)/(1-r1)) ; sum the Fischer Z
end do
r1z  = r1zsum/nseg                           ; average r1z
r1   = (exp(2*r1z)-1)/(exp(2*r1z)+1)            ; transform back
;
this is the mean r1
spcavg  = spcavg/nseg                                ; average spectrum

*Questions:*
(1) How do I loop this across all the gridpoints? I am having a problem
with the looping and saving the spectra in spcavg(ntim,nlat,nlon). Any
suggestions on how to do this in NCL? The example in the page is incomplete.

I'll appreciate any help on this.

-Lyndz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20230809/e0d82ee5/attachment.htm>
```