<div dir="ltr">You created 'n' as an array<br><div><br>n=u(level|:,lat|:,lon|:,time|iStrt:iLast)<br>anew=n({500},:,:,:)<br><br></div><div>then you use 'n' <br><br>do n=0,neof-1<br><br></div><div>do loops require require *scalars* n=0 is not allowed<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 6, 2016 at 4:54 PM, Adv <span dir="ltr"><<a href="mailto:advita6@gmail.com" target="_blank">advita6@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi ,<br></div>Could someone help me to fix this bug? I don't whats the fatal error says about. <br></div>Thank you<br><div><br><div><div>;***************************************************<br>begin<br>;***************************************************<br> yrStrt = 196501<br> yrLast = 200512<br><br> season = "SON" ; choose Dec-Jan-Feb seasonal mean<br>;####################################################<br>............<br>f = addfile("<a href="http://hgt.mon.mean.nc" target="_blank">hgt.mon.mean.nc</a>", "r") ; note the "s" of addfile<br>u = f->hgt<br>printVarSummary (u)<br> YYYYMM = cd_calendar( f->time, -1)<br><br> iStrt = ind(YYYYMM.eq.yrStrt)<br> iLast = ind(YYYYMM.eq.yrLast)<br>n=u(level|:,lat|:,lon|:,time|iStrt:iLast)<br>anew=n({500},:,:,:)<br>printVarSummary (anew)<br>;############################################################<br>;anomalies-------------------------<br>temp= rmMonAnnCycTLL(anew(time|:,lat|:,lon|:))<br>printVarSummary(temp)<br>;dtrend the values/------------------<br>anew1Dtrend = dtrend(temp(lat|:,lon|:,time|:),True)<br>printVarSummary(anew1Dtrend)<br>;print(anew1Dtrend@slope)<br>;print(anew1Dtrend@y_intercept)<br>copy_VarCoords(anew,anew1Dtrend)<br><br>; ==============================================================<br>; compute desired global seasonal mean: month_to_season (contributed.ncl)<br>; ==============================================================<br> anew1a = month_to_season (anew1Dtrend(time|:,lat|:,lon|:), season)<br> nyrs = dimsizes(anew1a&time)<br> printVarSummary(anew1a)<br>printMinMax(anew1a,False)<br>;%%%%%%%%%%%%%%%EOF%%%%%%%%%%%%%%%%%%%%%%%%<br>;Dont change at all . Here is a trick..<br>;Globe<br> latS = 37<br> latN = 49. <br> lonL = -116<br> lonR = -90 <br><br>;Center=0<br><br>;%%%%%%%%%%%%%%%EOF%%%%%%%%%%%%%%%%%%%%%%%%<br> <br><br>neof = 3 ; number of EOFs<br> optEOF = True<br> optEOF@jopt = 0 ; This is the default; most commonly used; no need to specify.<br>;;optEOF@jopt = 1 ; **only** if the correlation EOF is desired<br>; ==============================================================<br>; dataset longitudes span 0=>357.5<br>; Because EOFs of the North Atlantic Oscillation are desired<br>; use the "lonFlip" (contributed.ncl) to reorder<br>; longitudes to span -180 to 177.5: facilitate coordinate subscripting<br>; ==============================================================<br> anew1a = lonFlip(anew1a)<br> printVarSummary(anew1a) ; note the longitude coord<br>orig=anew1a({lat|latS:latN},{lon|lonL:lonR},time|:)<br> printVarSummary(orig)<br><br>; =================================================================<br>; create weights: sqrt(cos(lat)) [or sqrt(gw) ]<br>; =================================================================<br> rad = 4.*atan(1.)/180.<br> clat = anew1a(0,:,0)<br> printVarSummary(clat) <br> clat = sqrt( cos(rad*clat) ) ; gw for gaussian grid<br> printVarSummary(clat) <br>; =================================================================<br>; weight all observations <br>; =================================================================<br> wSLP = anew1a ; copy meta data<br> printVarSummary(wSLP)<br> printMinMax(wSLP,False)<br> wSLP = anew1a*conform(anew1a, clat, 1)<br> wSLP@long_name = "Wgt: "+anew1a@long_name<br> printVarSummary(wSLP)<br>printMinMax(wSLP,False)<br>; =================================================================<br>; Reorder (lat,lon,time) the *weighted* input data<br>; Access the area of interest via coordinate subscripting<br>; =================================================================<br> x = wSLP({lat|latS:latN},{lon|lonL:lonR},time|:)<br> printVarSummary(x)<br>print(min(x))<br>print(max(x))<br> dimx = dimsizes( x )<br> mln = dimx(1)<br> sumWgt = mln*sum( clat({lat|latS:latN}) )<br>printMinMax(sumWgt,False)<br> eof = eofunc_Wrap(x, neof, optEOF) <br> printVarSummary(eof)<br><br>print(eof(0,:,:))<br>;return<br>;;;;EOF spatial patterns may be tested for orthogonality by using the dot product: <br>d01 = sum(eof(0,:,:)*eof(1,:,:))<br> d12 = sum(eof(1,:,:)*eof(2,:,:))<br> d02 = sum(eof(0,:,:)*eof(2,:,:))<br> print("d01="+d01+" d12="+d12+" d02="+d02) ; may be +/- 1e-8<br>;return<br>printMinMax(eof(0,:,:),False)<br>;To retain same unit<br> do ne=0,neof-1<br> eof(ne,:,:) = eof(ne,:,:)*sqrt( eof@eval(ne) )<br> end do<br>;print(eof(:,:,:))<br>printMinMax(eof(0,:,:),False)<br>;return<br>;========================================================<br>;Print the Percentage variance;;;;;;<br>; print("% var="+ eof@pcvar(0))<br>;========================================================<br>eof_ts = eofunc_ts_Wrap (x, eof, False)<br> printVarSummary( eof_ts )<br> print( eof_ts )<br>;=======================================================<br>;To test the EOF time series for orthogonality, compute correlations;;;;;<br> r01 = escorc(eof_ts(0,:), eof_ts(1,:))<br> r12 = escorc(eof_ts(1,:), eof_ts(2,:))<br> r02 = escorc(eof_ts(0,:), eof_ts(2,:))<br> print("r01="+r01+" r12="+r12+" r02="+r02) ; numbers may be +/- 1e-8<br>; =================================================================<br>; Normalize time series: Sum spatial weights over the area of used<br>; =================================================================<br>; dimx = dimsizes( x )<br>; mln = dimx(1)<br>; sumWgt = mln*sum( clat({lat|latS:latN}) )<br>;eof_ts = eof_ts/sumWgt<br>;nlat = dimsizes(eof&lat) ; lat==> whatever the coordinate name is<br>; mlon= dimsizes(eof&lon)<br>;print(eof_ts)<br> eof_ts = dim_standardize_n( eof_ts, 0, 1) ; normalize<br> eof_regres = eof ; create an array w meta data<br> do ne=0,neof-1<br> eof_regres(ne,:,:) = (/ regCoef(eof_ts(ne,:),orig(lat|:,lon|:,time|:)) /)<br> end do<br>printMinMax(eof_regres(0,:,:),False)<br>printVarSummary( eof_regres )<br>;print(eof_ts)<br>;print(eof(0,:,:))<br>;===================================================================<br> nlat = dimsizes(eof&lat) ; lat==> whatever the coordinate name is<br> mlon= dimsizes(eof&lon)<br>;------------------------------------------------------------<br><br>; =================================================================<br>; Extract the YYYYMM from the time coordinate<br>; associated with eof_ts [same as SLP&time]<br>; =================================================================<br><br> yyyymm = cd_calendar(eof_ts&time,-2)/100<br>;;yrfrac = yyyymm_to_yyyyfrac(yyyymm, 0.0); not used here<br>;*******************************************<br>; North significance test: any pcvar, eval_transpose, eval can be used<br>;*******************************************<br><br> dimp = dimsizes(x)<br> ntim = dimp(0) ; max # eigenvalues possible<br><br> prinfo = True<br> sig = eofunc_north(eof@pcvar, ntim, prinfo)<br><br>;************************************************<br>; plotting parameters <br>;************************************************<br>;wks = gsn_open_wks("x11","SlpReconst_Anom_eof_Reanal_"+season+"_temp1965-2005")<br>wks = gsn_open_wks("x11","heightReconst_Anom_eof_Reanal_"+season+"_temp1965-2005")<br> gsn_define_colormap(wks,"NCV_jaisnd") <br> plot = new(neof,graphic) ; create graphic array<br> ; only needed if paneling<br>; EOF patterns<br><br> res = True<br> res@gsnDraw = False ; don't draw yet<br> res@gsnFrame = False ; don't advance frame yet<br><br>;---This resource not needed in V6.1.0<br> res@gsnSpreadColors = True ; spread out color table<br>res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels<br> res@cnMinLevelValF = -10.0 ; set min contour level<br> res@cnMaxLevelValF = 10.0 ; set max contour level<br> res@cnLevelSpacingF = 0.5 ; set contour spacing<br><br> res@gsnAddCyclic = False ; plotted dataa are not cyclic<br><br> res@mpFillOn = False ; turn off map fill<br><br> res@mpMinLatF = eof&lat(0)+3 ; zoom in on map<br> res@mpMaxLatF = eof&lat(nlat-1)<br> res@mpMinLonF = eof&lon(0)<br> res@mpMaxLonF = eof&lon(mlon-1)<br><br>res@cnLineLabelsOn = False<br> res@cnFillOn = True ; turn on color fill<br> res@cnLinesOn = False ; True is default<br> res@lbLabelBarOn = False ; turn off individual lb's<br>; res@mpPerimOn = True ; draw box around map<br>res@mpGeophysicalLineThicknessF = 3.0<br>res@mpGeophysicalLineColor = "Black"; (/22/)<br>res@mpOutlineBoundarySets = "GeophysicalAndUSStates" ; add state boundaries<br>res@mpNationalLineColor = res@mpGeophysicalLineColor<br>res@mpUSStateLineThicknessF = 3.0<br>res@mpUSStateLineColor = res@mpGeophysicalLineColor<br><br><br> ; set symmetric plot min/max<br>; symMinMaxPlt(eof, 16, False, res) ; contributed.ncl<br><br>; panel plot only resources<br> resP = True ; modify the panel plot<br> resP@gsnMaximize = True ; large format<br> resP@gsnPanelLabelBar = True ; add common colorbar<br> resP@lbLabelAutoStride = True ; auto stride on labels<br> resP@lbLabelFontHeightF = 0.017 ; label bar font<br><br> yStrt = yyyymm(0)/100<br> yLast = yyyymm(nyrs-1)/100<br> resP@txString = "Regres_Reanal_height(m): "+season+": "+yStrt+"-"+yLast<br><br>;*******************************************<br>; first plot<br>;*******************************************<br> do n=0,neof-1<br> res@gsnLeftStringFontHeightF = 0.02 ; instead of using txFontHeightF or gsnStringFontHeightF <br> res@gsnCenterStringFontHeightF = 0.02 ; to set the gsnLeft/Center/RightString font heights,<br> res@gsnRightStringFontHeightF = 0.02 ; individually set each string's font height.<br> res@gsnLeftString = "EOF "+(n+1)<br> res@gsnCenterString= "NORTH="+sig(n)<br> res@gsnRightString = sprintf("%5.1f", eof@pcvar(n)) +"%"<br> plot(n)=gsn_csm_contour_map_ce(wks,eof_regres(n,:,:),res)<br> end do<br> gsn_panel(wks,plot,(/neof,1/),resP) ; now draw as one plot<br><br><br> frame(wks)<br><br><br>end<br><br><br><br></div><div>ERROR printed: <br></div><div><br>fatal:Loop variable must be scalar, can't execute loop<br>fatal:["Execute.c":8575]:Execute: Error occurred at or near line 242 in file heightReconstruct_Temp_eof_Reanal.ncl<br><br><br></div></div></div></div>
<br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>