Re: Subscript out of range, error in subscript #0

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Wed Sep 04 2013 - 19:38:01 MDT

Several comments.

[1] We recommend that people use simple print statements
     to debug codes prior to sending ncl-talk questions.

[2] We ask that people delete 'dead' code. Reading somebody
     else's code is tedious. Dead code makes it even more tedious.

[3] snippet

   nb =12
   nn = dimsizes(in[:]->ocean_time)
   print("nb="+nb+" nn="+nn)

   do nt=nb,nn
      print("loop: nt="+nt)

==
Should it be

   do nt=nb,nn-1
      print("loop: nt="+nt)

????

+++++++++++++++

As noted at: http://www.ncl.ucar.edu/Applications/roms.shtml

ROMS_util.ncl is donated software. It is not supported by
the NCL team. You can readily look at the code and insert
print statement to help debug.

[SNIP]

187
188 ; check if it is defined on "v" coords and transfer it on the "rho"
189 if(var.eq."v") then
190 vin_rho=v2rho(vin)
191 delete(vin)
192 vin=vin_rho
193 delete(vin_rho)
194 end if

[SNIP]

248 if (vtransform.eq.2)
249 do k=0,N-1
250 cff = 1./(hc + h);
251 cffr = hc*Sc_r(k) + h*Cs_r(k);
252 depth(k,:,:)=doubletofloat(zeta + ( zeta + h )*cffr*cff)
253 end do
254 end if

[SNIP]

Good luck

On 9/4/13 6:37 PM, 朱学明 wrote:
> When I tried to plot the vector fields from ROMS results. My code is as follow. I have many years monthly data since 1993-2000, so the variable v's dimension size should be 96*22*633*1545. But when it run to nb=13, I have got an error message as follow,
>
> fatal:Subscript out of range, error in subscript #0
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 250 in file $NCARG_ROOT/lib/ncarg/nclscripts/roms/ROMS_utils.ncl
>
> fatal:["Execute.c":8128]:Execute: Error occurred at or near line 188 in file ROMS_vector_plot_rectangle.ncl
>
> My ncl code is as follow,
>
> ;----------------------------------------------------------------------
> 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/roms/ROMS_utils.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> ;************************************************
> begin
> ;************************************************
> ; read in netCDF file
> ;************************************************
> data_file = "np8_monthly_*.nc"
> ; data_file = "np8_clm_mon*.nc"
> nb = 12
> ne = -1
> depth = -20.0
>
> lat_min = 0
> lat_max = 25
> lon_min = 99
> lon_max = 125
> resol = 1
>
> infile = systemfunc("ls ./"+data_file)
> in = addfiles(infile,"r") ;
> ;************************************************
> ; read in netCDF file
> ;************************************************
> grd_file = "/cygdrive/f/np8/np8_grd.nc"
> ; grd_file = "F:/np8/np8_grd.nc"
> grd = addfile(grd_file,"r")
> lon = grd->lon_rho(1,:)
> lat = grd->lat_rho(:,1)
> ; lon_u = grd->lon_u(1,:)
> ; lat_u = grd->lat_u(:,1)
> ; lon_v = grd->lon_v(1,:)
> ; lat_v = grd->lat_v(:,1)
> ; lon = fspan(lon_min,lon_max,10*(lon_max-lon_min)/resol+1)
> ; lat = fspan(lat_min,lat_max,10*(lat_max-lat_min)/resol+1)
> ; lon@units = "degree_east"
> ; lat@units = "degree_north"
> h = doubletofloat(grd->h)
> ......................
>
> nn = dimsizes(in[:]->ocean_time)
> do nt=nb,nn
> time=in[:] ->ocean_time(nt-1)
> utc_date = cd_calendar(time, -3)
> print(""+utc_date)
>
> ;************************************************
> ; read in zonal [u] and meridional [v] winds
> ;************************************************
> u = roms_3d_interp(in,"u",nt-1,h,depth) ; Line 188
> v = roms_3d_interp(in,"v",nt-1,h,depth)
> ; tmp = in[:]->v(nt-1,21,:,:)
> ; v = linint2(lon_v,lat_v,tmp,False,lon,lat,0)
> ; delete(tmp)
> speed = sqrt(u^2 + v^2)
> ; if(nt .eq. nb) then
> u!0 = "lat"
> u!1 = "lon"
> u&lat = lat
> u&lon = lon
> v!0 = "lat"
> v!1 = "lon"
> v&lat = lat
> v&lon = lon
> speed!0 = "lat"
> speed!1 = "lon"
> speed&lat = lat
> speed&lon = lon
> ; end if
> printVarSummary(u)
> vcres@tiMainString = "Surface currents distribution"
> vcres@gsnLeftString = utc_date
> vcres@gsnRightString = "m/s"
>
> wks = gsn_open_wks(wks_type ,"velocity_"+flt2string(depth)+"-"+utc_date) ; open a ps file
> gsn_define_colormap(wks,"rainbow") ;"BlAqGrYeOrRe") ; choose colormap
> ; plot = gsn_csm_contour_map_ce(wks,speed, res)
>
> plot = gsn_csm_vector_scalar_map_ce(wks,u,v,speed,vcres) ; create plot
> ; plot = gsn_csm_vector_map_ce(wks,u,v,vcres)
> end do
> 2013-09-05
>
>
>
> 朱学明
>
>
>
> _______________________________________________
> 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 Wed Sep 4 19:38:02 2013

This archive was generated by hypermail 2.1.8 : Mon Sep 16 2013 - 13:43:52 MDT