Hello,
I am trying to output an NetCDF-4 file; but I ran into the error
"NclNetCDF4: Error to define dim: <ncl_000> with length: 201" at the
command "f->lon = (/newlon/)". The variable name and dimension for both
lat and lon are similar in the script. I don't understand why there is no
error about lat; but an error about lon. Could anyone explain the error
and show me the solution?
##### output
.........
(0) Defining file attributes
(0) Defining file variables
(0) Defining file variable attributes
(0) Creating coordinate arrays
fatal:["NclNetCDF4.c":4940]:NclNetCDF4: Error to define dim: <ncl_000> with
length: 201
^Mfatal:["Execute.c":8128]:Execute: Error occurred at or near line 164 in
file edgarRegd.ncl
##### NCL script
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"
begin
latS = 35.0
latN = 50.0
lonE = -80.0 +360
lonW = -105.0 +360
in= addfile("/home/fas/xhlee/yh387/EDGAR/TOT/
v42_FT2010_N2O_2010_TOT.0.1x0.1.nc","r")
emi_n2o= in->emi_n2o
printVarSummary(emi_n2o)
em_n2o = emi_n2o({latS:latN},{lonW:lonE})
printVarSummary(em_n2o)
; newgrid = g2gsh_Wrap(em_n2o,(/181,201/), 0)
; newgrid = g2gsh_Wrap(em_n2o,(/ 64,128/), 0)
;************************************************
; interpolate to new grid
;***********************************************
lat = fspan(35,50,150)
lon = fspan(-105,-80,250)
newlat = fspan(35,50,181)
newlon = fspan(-105,-80,201)
newlat@units = "degrees_north"
newlon@units = "degrees_east"
newgrid = linint2(lon,em_n2o&lat,em_n2o,True,newlon,newlat,0)
newgrid!0 = "lat"
newgrid!1 = "lon"
newgrid&lat = newlat
newgrid&lon = newlon
printVarSummary(newgrid)
;==========================================================================;
; Output netCDF with one unlimited dimension, plus chunking and compression
;==========================================================================;
theflnm = "./EDGAR_N2O.nc"
setfileoption("nc","format","netcdf4")
setfileoption("nc","headerReserveSpace",64000)
setfileoption("nc","preFill",False)
; setfileoption("nc","defineMode",True)
; Remove the file if it already existed.
if (isfilepresent(theflnm)) then
system("rm " + theflnm)
end if
; Create the file:
f = addfile(theflnm,"c")
; Define dimensions:
; (Note ONLY time dimension is unlimited, and its current value is 1.)
ctim = 1
ntim = 250 ;1000 will be little bit too much
ds = dimsizes(newgrid)
nlat = ds(0)
nlon = ds(1)
dim_names = (/"time","lat","lon"/)
; time dimension is unlimited, but currently set to 1.
dim_sizes = (/ctim,nlat,nlon/)
dim_unlimited = (/True,False,False/)
; print("Defining dimension sizes to be " + dim_sizes)
filedimdef(f,dim_names,dim_sizes,dim_unlimited)
; Define some file properties:
atts = True
atts@description = "This file tests NCL's ability to create >2GB
variables"
atts@timestamp = systemfunc("date")
print("Defining file attributes")
fileattdef(f,atts)
; Define file variables:
print("Defining file variables")
filevardef(f,"time","float","time")
filevardef(f,"newlat","float","lat")
filevardef(f,"newlon","float","lon")
filevardef(f,"time_n2o","float",(/"time","lat","lon"/))
; Define file variables attributes:
print("Defining file variable attributes")
tatts = True
tatts@long_name = "elapsed time"
tatts@units = "hours since 01-01-2000"
filevarattdef(f,"time",tatts)
latatts = True
latatts@long_name = "latitude"
latatts@units = "degrees_north"
filevarattdef(f,"newlat",latatts)
lonatts = True
lonatts@long_name = "longitude"
lonatts@units = "degrees_east"
filevarattdef(f,"newlon",lonatts)
n2oatts = 0.0
n2oatts@long_name = "Emissions of N2O - "
n2oatts@units = "kg m-2 s-1"
n2oatts@_FillValue = 1e32
filevarattdef(f,"time_n2o",n2oatts)
ntim = 365*8 ; every 3 hr
time = fspan(0,ntim-1,ntim)
; chunk_sizes = (/1,ds(0)/10,ds(1)/10/)
; filechunkdimdef(f,dim_names,chunk_sizes,dim_unlimited)
; filevarchunkdef(f, "time_n2o", chunk_sizes)
filevarcompressleveldef(f, "time_n2o", 2)
; Create coordinate arrays:
print("Creating coordinate arrays")
f->time= (/time/)
f->lat = (/newlat/)
f->lon = (/newlon/)
pi = 3.14159265
time_n2o= new((/ntim,ds(0),ds(1)/),float);,n2oatts@_FillValue)
do i= 0,ntim-1
f->time_n3o(i,:,:)= newgrid(:,:) *cos(pi/180*(i/8))
end do
delete(f)
end
#####
Many thanks,
Yi-Chih
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Apr 12 16:52:31 2014
This archive was generated by hypermail 2.1.8 : Tue Apr 15 2014 - 10:45:19 MDT