Re: Subtracting running mean

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri Jul 05 2013 - 13:05:34 MDT

Subscript #0 refers to the leftmost subscript of an array. When you see an error that refers to this subscript, you should look at all places where you are subscripting the leftmost dimension of your arrays and make sure it is in the correct range.

The problem is likely with the "data(i,:,:)" on the left side of the "=" sign. You are subcripting it with "i", which goes from 120 to ntim-1, but the leftmost dimension of data is of size "ntim-120".

I think you meant to have:

> data(i-120,:,:) = …

Also, it is not necessary to keep including the dimension names when you subscript your arrays, unless they are *not* dimensioned time x lat x lon.

> do i=120,ntim-1
> data(i-120,:,:) = work(i,:,:)-dim_avg_n_Wrap(work(i-120:i-1,:,:),0)
> end do

--Mary

On Jul 5, 2013, at 11:22 AM, Abhik Santra wrote:

>
> Dear NCL-users,
>
> I am subtracting previous 120-day running mean from an array (ntim x nlat x mlon).
> My script is as follows:
>
> dimx = dimsizes( work )
> ntim = dimx(0)
> data = new((/ntim-120,nlat,mlon/),typeof(work),getFillValue(work))
>
> do i=120,ntim-1
> data(i,:,:) = work(time|i,lat|:,lon|:)-dim_avg_n_Wrap(work(time|i-120:i-1,lat|:,lon|:),0)
> end do
>
> This line is giving an error as:
> fatal:Subscript out of range, error in subscript #0
>
> Where is the error in this code sequence?
> Can you please let me know?
> Thanks in advance.
>
> Regards,
> Abhik
>
> ___________________________________________
>
> Abhik Santra
> CSIR Research Fellow,
> Indian Institute of Tropical Meteorology,
> Pune - 411008.
> India
> ___________________________________________
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Jul 5 13:05:43 2013

This archive was generated by hypermail 2.1.8 : Fri Jul 05 2013 - 13:06:49 MDT