<div dir="ltr"><div>Thank you ! I will be more precise next time!<br></div>Sorry about the confusion. I will work on the code<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 28, 2014 at 3:19 PM, Alan Brammer <span dir="ltr"><<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">“Error” is a very vague term. It helps if you narrow down what you mean by that.<br>
— Is the script returning an error, if so copy and paste that error so everyone can get a better idea as to the problem.<br>
— Is the code just not doing what you want? If so try and be explicit about what it is you want returned from the section code and include data if possible.<br>
<br>
<br>
There are a number of issues on the loop.<br>
—1. I’d recommend running that loop and printing the i, j k values with each iteration to make sure the logic is what you expect. It’s not intuitive to me.<br>
—2. da is an array of 5 numbers. You’re just overwriting all 5 numbers with the scalar return with every iteration so it’s pointless.<br>
—3. This syntax “ ya(k:i) “ says ya only has 1 dimension but you’re trying to average over the the 2nd dimension. Thats going to give you an error message.<br>
<br>
<br>
How I would do this "I am writing a loop to calculate mean every 10 indices “. Which is calculating the mean of 0-9, 10-19, 20-29 etc. If that’s not it, be more explicit in your reply to the list.<br>
<br>
retval = new( dimsizes(ya)/10, float) ;;; assumes ya%10 is 0. if not end indices will be ignored.<br>
ct = 0<br>
do i=0, dimsizes(ya)-10, 10 ; loop from 0 to max length of array and step by 10<br>
retval(ct) = avg( ya(i:i+9) )<br>
ct = ct+1<br>
end do<br>
<br>
<br>
<br>
Good luck,<br>
Alan.<br>
<br>
<br>
##############################<br>
Alan Brammer,<br>
PhD Student,<br>
<br>
Department of Atmospheric and Environmental Sciences,<br>
University at Albany, State University of New York, Albany, NY, 12222<br>
<a href="mailto:abrammer@albany.edu">abrammer@albany.edu</a><br>
##############################<br>
<div class=""><br>
On Jul 28, 2014, at 4:55 PM, Ipshita Majhi <<a href="mailto:ipmajhi@alaska.edu">ipmajhi@alaska.edu</a>> wrote:<br>
<br>
> I am writing a loop to calculate mean every 10 indices and there is an error towards the end of the loop. It would be great if you could help me sort it out<br>
><br>
> ;This is to create decadal mean<br>
><br>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"<br>
><br>
> ncol = 12<br>
> nrows=134<br>
><br>
> air=readAsciiTable("~/Documents/PhD_June_2015/Data_AIR/air.txt", ncol, "integer",2)<br>
><br>
> ya = dim_avg_n(air,1) ;yearly average<br>
><br>
> i=0<br>
> j=0<br>
> k=0<br>
><br>
> da=new(5,"float")<br>
><br>
> do while (i.le.133)<br>
</div>> It would<br>
<div class="">> if (i/1.eq.1+j) then<br>
><br>
> da=dim_avg_n(ya(k:i),1)<br>
><br>
> k=k+10<br>
><br>
> j=j+1<br>
> continue<br>
> end if<br>
><br>
><br>
> i=i+1<br>
><br>
> end do<br>
</div>> _______________________________________________<br>
> ncl-talk mailing list<br>
> List instructions, subscriber options, unsubscribe:<br>
> <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br>
</blockquote></div><br></div>