Re: subscript out of range error

From: Dennis Shea (shea AT XXXXXX)
Date: Fri May 30 2003 - 18:03:28 MDT

  • Next message: James D. Scott: "using wrapit and the fortran - ncl interface on solaris"

     ncdump -h 200304232000_MMOUTPUT_DOMAIN1.GRM.nc
     
     yields [after deleteing irrelevant stuff]
     
     netcdf 200304232000_MMOUTPUT_DOMAIN1.GRM {
             y = 84 ;
             x = 98 ;
             member = 16 ;
     
             float LATITCRS(y, x) ;
                     LATITCRS:_FillValue = 9.96921e+36f ;
                     LATITCRS:long_name = "LATITUDE (SOUTH NEGATIVE)" ;
                     LATITCRS:units = "DEGREES" ;
                     LATITCRS:stagger = "C" ;
             float LONGICRS(y, x) ;
                     LONGICRS:_FillValue = 9.96921e+36f ;
                     LONGICRS:long_name = "LONGITUDE (WEST NEGATIVE)" ;
                     LONGICRS:units = "DEGREES" ;
                     LONGICRS:stagger = "C" ;
             float HRAINR(member, y, x) ;
                   HRAINR:_FillValue = -999.f ;
     
     
    >I am trying to create a contour plot but I am getting a subscript out
    >of range error that I am not sure about. The beginning of my script
    >looks like
    >
    >begin
    > in_file = addfile ("200304232000_MMOUTPUT_DOMAIN1.GRM.nc","r")
    > rain_rate = in_file->HRAINR
    > lat = in_file->LATITCRS ; <** this is a 2D array
    > lon = in_file->LONGICRS ; <** this is a 2D array
    >
    > wks = gsn_open_wks ("X11", "line" )
    >
    > lat_min = min (lat)
    > lat_max = max (lat)
    >
    > lon_min = min (lon)
    > lon_max = max (lon)
    >
    > data = rain_rate(0,:,:)
    > data_min = min (data)
    > data_max = max (data)
    >
    > r_data = data ({lat_min:lat_max},{lon_min:lon_max})
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                          This is illegal.
                          
                       The curly-brackets {} can only be used
                       on coordinates that conform to the
                       strict netCDF data model's definition
                       of "coordinate variable". By netCDF/Unidata
                       definition: a coordinate variable must be
                       a one-dimensional array of monotonically
                       increasing or decreasing values. The lat/lo
                       data on the file are 2D so there is an error.
                       
                       Because the {..} are not applicable to the
                       "lat" and "lon" dimensions NCL is doing something
                       strange which results in the error below.
                       
                       Personally, I think NCL should give message like
                       "Illegal use coordinate subscripting. "
     
     
     ------------- End Forwarded Message -------------
     
     Also, you have other issues with your 2D coordinates.
     It is not conventional to have lat/lon coordinates
     that are missing (_FillValue). I looked at the data
     and the rightmost coordinates and the top row
     of latitudes are missing. So I read in the non-missing
     subset.
     
      rain_rate = f->HRAINR(:,0:82,0:96) ; (member, y, x)
      lat2d = f->LATITCRS(0:82,0:96) ; (y,x)
      lon2d = f->LONGICRS(0:82,0:96) ; (y,x)
      rain_rate@lat2d = lat2d
      rain_rate@lon2d = lon2d

    You still can not use {...} type subscripting because the
    lat/lon arrays are 2D.

    However, the information on the file indicate that
    it is a native lambert conformal. It also
    includes the the required 2 parallels and central meridian.

    They are included as file attributes. Thus,

      res@mpProjection = "LambertConformal" ; f@map_projection
      res@mpLambertParallel1F = f@truelat1
      res@mpLambertParallel2F = f@truelat2
      res@mpLambertMeridianF = f@central_longitude

    ; data on a native grid, must use the "corners" method of zooming
      
      dim = dimsizes(rain_rate)
      nmem = dim(0)
      nlat = dim(1)
      nlon = dim(2)

      res@mpLimitMode = "Corners" ; choose range of map
      res@mpLeftCornerLatF = lat2d(0,0)
      res@mpLeftCornerLonF = lon2d(0,0)
      res@mpRightCornerLatF = lat2d(nlat-1,nlon-1)
      res@mpRightCornerLonF = lon2d(nlat-1,nlon-1)

    Good luck
    D

    _______________________________________________
    ncl-talk mailing list
    ncl-talk@ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Sun Jun 01 2003 - 16:00:53 MDT