<div dir="ltr"><div>Dear NCL-experts,</div><div><br></div><div>Just a follow up on my post earlier.</div><div><br></div><div>I tried the following:</div><div><br></div><div><br></div><div>;************************************************<br>; calculate mean spectrum spectrum and lag1 auto cor<br>;************************************************<br><br>ntim = 6954<br>nlat = 220<br>nlon = 220<br>nseg = 49<br>nlen = ntim/nseg<br>minlat = -14.875<br>maxlat = 39.875<br>minlon = 90.125<br>maxlon = 144.875<br>spcavg = onedtond(rain,(/nseg,nlat,nlon/))<br>printVarSummary(spcavg)<br>spcavg = 0.0<br>r1zsum = 0.0<br><br>dm = 1<br>sm = 1<br>pct = 0.10<br>r1zsum = 0.0<br><br>mlon=220<br>nlat=220<br><br> do nl=0,nlat-1<br> do ml=0,mlon-1<br> 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> end do ; ml<br>end do ; nl<br></div><div><br></div><div><br></div><div>It gives the following error:</div><div><br></div><div><span style="color:rgb(255,0,0)">ncl 64> do nl=0,nlat-1 <br>ncl 65> do ml=0,mlon-1<br>ncl 66> do n=0,nseg-1<br>ncl 67> dof = specx_anal(rain(latitude|nl:nl,longitude|ml:ml,time|:),d,sm,pct) ; current segment spc<br>ncl 68> spcavg = spcavg + dof@spcx ; sum spc of each segment<br>ncl 69> r1 = dof@xlag1 ; extract segment lag-1<br>ncl 70> r1zsum = r1zsum + 0.5*(log((1+r1)/(1-r1))) ; sum the Fischer Z<br>ncl 71> end do<br>ncl 72> end do ; ml<br>ncl 73> end do ; nl</span></div><div><br></div><div><span style="color:rgb(255,0,0)"><b>fatal:Number of dimensions in parameter (0) of (specx_anal) is (3), (1) dimensions were expected <br>fatal:["Execute.c":8635]:Execute: Error occurred at or near line 67</b></span><br></div><div><br></div><div><br></div><div>Any suggestion on how to do this correctly in NCL?<br></div><div><br></div><div>-Lyndz<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>---------------------------------------------------------------------<br></div><div class="gmail_quote"><br><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" target="_blank">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" target="_blank">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>
</div></div>