Re: Coordinate variable undefined (reading ERA-40 grib file)

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Wed Nov 17 2010 - 10:30:30 MST

Hi Arlene,
I think that you need to define a lat array. By having the following
code: bigvar&lat = lat

You are saying that you wish to assign the lat array as a coordinate
variable to the dimension of bigvar named "lat". Taking a look at your
.nc file, I think you can define lat like this upon opening the file:

lat = f[0]->g4_lat_1

and conversely lon:

lon = f[0]->g4_lon_2

That should fix things. If not, let us know..
Adam

On 11/17/2010 10:18 AM, Arlene Laing wrote:
> Hi folks,
>
> I am getting the following error:
>
> fatal:Variable (lat) is undefined
>
> I am reading from era-40 grib files as shown in the script (excerpt
> below). The dimensions are printed correctly and I assign names to
> the dimensions (time, lat, lon). However when I assign the coordinate
> variable (the "&"), the fatal error occurs.
>
> The script excerpt and output are below.
>
> Thanks in advance for your help.
>
>
> Arlene
>
> *************start script excerpt***********************
>
> ;--------------------------------------------------------------
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> 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/shea_util.ncl"
>
> ;--------------------------------------------------------------
> begin
>
> dirin ="/project/amp/andrew/conflict/era40/"
> dirout ="/project/amp/laing/conflict/era40/"
>
> yyyymm = yyyymm_time(1970, 1970, "integer")
> ;print (yyyymm)
> nmonths = dimsizes(yyyymm)
>
> ;--------------------------------------------------------------
> ; loop through specified years
>
> do iyr = 0,nmonths-1,12
> yyyy= yyyymm(iyr)/100
>
> ; print (yyyy)
> yr = sprinti ("%4.0i",yyyy)
>
> fieldin1="CP"
> fieldin2="LSP"
> fieldout="TOT_PRCP"
>
> field1 =fieldin1+"_GDS4_SFC"
> field2 =fieldin2+"_GDS4_SFC"
>
> ;--------------------------------------------------------------
> ; READ AN ORDERED LIST OF FILES....
>
> files=systemfunc("ls "+dirin+"e4oper.an.sfc.othr."+yr+"*")
>
> ;print(files)
> f = addfiles(files+".gr","r")
>
> print(f)
>
> bigvarcp = f[:]->$field1$
> bigvarlsp = f[:]->$field2$
> bigvar = bigvarcp + bigvarlsp
>
> printVarSummary(bigvar)
> ndims = dimsizes(bigvar)
> print(ndims)
> ;--------------------------------------------------------------
> ;rename coordinate arrays
>
> bigvar!0="time"
> bigvar!1="lat"
> bigvar!2="lon"
>
> print("before latitude flip")
> printVarSummary(bigvar)
>
> ;-------------------------------------------------------------
> ; flip latitude to S to N (initially, N to S)
> bigvar = bigvar(:,::-1,:)
>
> print("after latitude flip")
> printVarSummary(bigvar)
>
> bigvar!0="time"
> bigvar!1="lat"
> bigvar!2="lon"
>
> bigvar&lat = lat ;*******fatal error here****************
> bigvar&lon = lon
> bigvar@time = time
>
>
> *************end script excerpt***********************
>
>
> *************start output ***********************
>
> Variable: f
> Type: list
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
>
>
> Variable: bigvar
> Type: float
> Total Size: 299008000 bytes
> 74752000 values
> Number of Dimensions: 3
> Dimensions and sizes: [1460] x [160] x [320]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : 1e+20
>
>
> Variable: ndims
> Type: integer
> Total Size: 12 bytes
> 3 values
> Number of Dimensions: 1
> Dimensions and sizes: [3]
> Coordinates:
> (0) 1460
> (1) 160
> (2) 320
> (0) before latitude flip
>
>
> Variable: bigvar
> Type: float
> Total Size: 299008000 bytes
> 74752000 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 1460] x [lat | 160] x [lon | 320]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : 1e+20
> (0) after latitude flip
>
>
> Variable: bigvar
> Type: float
> Total Size: 299008000 bytes
> 74752000 values
> Number of Dimensions: 3
> Dimensions and sizes: [time | 1460] x [lat | 160] x [lon | 320]
> Coordinates:
> Number Of Attributes: 1
> _FillValue : 1e+20
> fatal:Variable (lat) is undefined
> fatal:Execute: Error occurred at or near line 123 in file
> rera40_grib2cdf_daily_rain.ncl
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
__________________________________________________
Adam Phillips 
asphilli@ucar.edu
National Center for Atmospheric Research   tel: (303) 497-1726
Climate and Global Dynamics Division         fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Nov 17 10:30:36 2010

This archive was generated by hypermail 2.1.8 : Wed Nov 17 2010 - 13:14:26 MST