<div dir="ltr"><div>Dear NCL-experts,</div><div><br></div><div>I would like to do a spectral analysis on a <b>ntim x nlat x lon</b> data as indicated in example 3 from this page: <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/specx_anal.shtml">https://www.ncl.ucar.edu/Document/Functions/Built-in/specx_anal.shtml</a></div><div><br></div><div><b>Specifically, I would like to get the mean spectra so that the final output will have meanspectra x lat x lon</b></div><div><b><br></b></div><div><b><br></b></div><div><b>So far, I have the following:</b></div><div><br></div><div>  ufile  = addfile("<a href="http://anom_rain_sm_1951-2007_jjas.nc">anom_rain_sm_1951-2007_jjas.nc</a>","r")       ; open netcdf file<br>  rain = ufile->rAnom_sm(:,:,:)<br><br>  printVarSummary(rain)            ;[time | 6954] x [latitude | 220] x [longitude | 220]<br><br>  d   = 0<br>  sm  = 1         ; periodogram<br>  pct = 0.10<br><br><br>;************************************************<br>; calculate mean spectrum spectrum and lag1 auto cor<br>;************************************************<br><br>ntim = 6954<br>nlat = 220<br>nlon = 220<br><br>nseg = 49<br>nlen  = ntim/nseg<br><br>spcavg = new (ntim/141, typeof(rain))<br>printVarSummary(spcavg)<br>spcavg = new ( ntim/2, typeof(rain))<br>spcavg = 0.0<br>r1zsum = 0.0<br><br>    <span style="color:rgb(255,0,0)"> do n=0,nseg-1<br>      dof    = specx_anal(rain(latitude|nl:nl,longitude|ml:ml,time|:),d,sm,pct)      ; current segment spc<br>      spcavg = spcavg + dof@spcx                ; sum spc of each segment<br>      r1     = dof@xlag1                        ; extract segment lag-1<br>      r1zsum = r1zsum  + 0.5*(log((1+r1)/(1-r1)) ; sum the Fischer Z<br>    end do<br>   r1z  = r1zsum/nseg                           ; average r1z<br>   r1   = (exp(2*r1z)-1)/(exp(2*r1z)+1)            ; transform back<br>                                                                        ; this is the mean r1<br>   spcavg  = spcavg/nseg                                ; average spectrum<br></span></div><div><b><br></b></div><div><b>Questions:</b><br></div><div> (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.</div><div><br></div><div><br></div><div>I'll appreciate any help on this.</div><div><br></div><div><br></div><div>-Lyndz<br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>