Re: Issue with subscripts in array

From: Rick Brownrigg <brownrig_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 25 2014 - 19:25:03 MDT

Hi Tabish,

NCL uses zero-based indexing, as you correctly coded in your loops. That
means if the array dimensions are 89x99, the indices should range from 0-88
x 0-98. Something like:

topoDims = dimsizes(topo)
do i=0,topoDims(1)-1,1 ; the trailing ",1" is superfluous
   do j=0,topoDims(2)-1,1 ; ditto
....


Rick


On Wed, Jun 25, 2014 at 2:57 PM, Tabish Ansari <tabishumaransari@gmail.com>
wrote:

> Hi
>
> I am using the following script:
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> begin
> a=addfile("geo_em_flatasia.d01.nc","w")
> topo = a->HGT_M
> printMinMax(topo,True)
> print (dimsizes(topo))
>
> do i=0,89,1
> do j=0,99,1
> if (topo(0,i,j).gt.200) then
> topo(0,i,j) = (200 + (0.01*(topo(0,i,j)-200)))
> end if
> end do
> end do
> printMinMax(topo,True)
> printMinMax(a->HGT_M,True)
>
> end
>
> ​I am getting the following output:
>
> Copyright (C) 1995-2012 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 6.1.0
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
> (0)
> (0) Topography height: min=-122.312 max=5411.67
> (0) 1
> (1) 89
> (2) 99
> fatal:Subscript out of range, error in subscript #2
> fatal:An error occurred reading topo
> fatal:["Execute.c":7743]:Execute: Error occurred at or near line 12 in
> file flattentopo.ncl
> ​
>
> --
> Thanks & Regards
> Tabish Umar Ansari
> MS Research Scholar
> Environmental & Water Resources Engineering Division
> Department of Civil Engineering
> IIT Madras
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

Received on Thu Jun 26 01:25:20 2014

This archive was generated by hypermail 2.1.8 : Wed Jul 23 2014 - 15:33:46 MDT