[ncl-talk] Error: Subscript out of range error in subscript #1
Michael Notaro
mnotaro at wisc.edu
Thu Nov 6 11:46:21 MST 2014
It's a good idea to specify which line # is giving the error message.
sce_week has dimensions of 47,52.
Therefore, sce_week(i,52) is out of range.
The 2nd dimension is 0:51, so 52 is too large.
Michael
On 11/06/14, Ipshita Majhi wrote:
> Hi All,
>
>
> I wrote a code to calculate the weekly long term mean for snow covered area.
>
> First I wanted to create a matrix which had each years week and then finally calculate it. while trying to create such a matrix I get the above mentioned error. If anyone can help it would be great.
>
> Here is the code
>
> ;*******************************************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> ;*******************************************
> ;Reading in the data
>
> a=addfile("~/Documents/Snow_cover_IMS/nhsce_v01r01_19661004_20140602.nc(http://nhsce_v01r01_19661004_20140602.nc)","r")
>
> sce=a->snow_cover_extent
> time_sce=a->time
>
>
> ;Now converting the time from georgian to ut_calender
> ;Doing an area average for sce
>
> sce_area=wgt_areaave_Wrap(sce,1.0,1.0, 0)
>
> ut_sce=cd_calendar(time_sce,0)
>
>
> ;Extracting just the year information from the time series
>
> xyears=ut_sce(:,0)
>
> ;This part of code is to create a matrix with each years weekly data
> ;The years go from 1967 to 2013 i.e 47 years with 52 weeks for each year
>
> sce_week=new((/47,52/),"float")
>
>
> do i=1,47
>
> years=ispan(1967,2013,1)
>
> yind=years(i)
>
> time_ind= ind(xyears.eq.yind) ; We are extracting each year one by one
>
> z=dimsizes(time_ind)
>
> sce_ind=sce_area(time_ind); extracting the array of sce which matches the indices
>
> sce_year=sce_ind(1:52); This is to take only 52 weeks from the indices for each year
>
> sce_reshape=reshape(sce_year,(/1,52/)); This is putting the output with one row and 52 columns
>
> sce_week(i,52)=sce_reshape; This is putting the array in the new array
>
> if (z.gt.52) then ; This is for years which have more then 52 weeks
> i=i+1
> end if
>
> end do
> ;*****************************************************************************
>
>
> Thank You
> Best Regards
> Ipshita
More information about the ncl-talk
mailing list