Hi,
I am trying to create NETCDF files from other NETCDF files I already have. I
am trying to use the example from the website (efiicient approach for netcdf
output) but I get the error message:
fatal:FileAddVar: an error occurred while adding a variable to a file, check
to make sure data type is supported by the output format
fatal:Execute: Error occurred at or near line 80 in file edit_file.ncl
Below is the complete code.
thank you
*****************************************************************************
begin
;do year=
;do month=
;do day=
;do hour=
;filename=2008010100 ;example for testing purposes
;*********************LOOP ON FILES****************************
setfileoption("nc","DefineMode",True)
;===================================================================
;Read files
;===================================================================
datafile=addfile("./NETCDF2m25/allyear_VAR_218/
fcst_phy2m25.1979010100.nc", "r")
lat=datafile!0
lon=datafile!1
diab_heating=datafile->VAR_218_GDS0_SFC_acc6h
time=diab_heating_at_initial_time
;===================================================================
; Assume variables T, PS and ORO exist and that they have
; associated meta data: (a) coordinate variables time, lev, lat, lon
; and (b) attributes
;===================================================================
ntim = dimsizes(time) ; get dimension sizes
nlat = dimsizes(lat)
nlon = dimsizes(lon)
diro = "./NETCDF2m25/allyear_VAR_218_edited/" ;
Output directory
; filo = "fcst_phy2m25."+filename+".nc" ; Output file
filo = "fcst_phy2m25.1979010100.nc"
system("/bin/rm -f " + diro + filo) ; remove if exists
fout = addfile (diro + filo, "c") ; open output file
;===================================================================
; explicitly declare file definition mode. Improve efficiency.
;===================================================================
setfileoption(fout,"DefineMode",True)
;===================================================================
; create global attributes of the file
;===================================================================
fAtt = True ; assign file attributes
fAtt_at_title = "NCL Efficient Approach to netCDF Creation"
fAtt_at_source_file = "original-file.nc"
fAtt_at_Conventions = "None"
fAtt_at_creation_date = systemfunc ("date")
fileattdef( fout, fAtt ) ; copy file attributes
;===================================================================
; predefine the coordinate variables and their dimensionality
; note: to get an UNLIMITED record dimension, we set the dimensionality
; to -1 and set the unlimited array to True.
;===================================================================
dimNames = (/"time", "lat", "lon"/)
dimSizes = (/ -1 , nlat, nlon /)
dimUnlim = (/ True , False, False/)
filedimdef(fout,dimNames,dimSizes,dimUnlim)
;===================================================================
; predefine the the dimensionality of the variables to be written out
; filevardef(output_file, name of variable, type of variable, CV's of
; variable) note: at this point, when you do an ncdump on the file, it
; will look like the variable is there. If you do not output the values,
; however, then an ncdump -v xxx will reveal that there is no data.
;===================================================================
; Here we are explicitly defining the variable's dimension name(s).
; However, the following could be replaced with:
; filevardef(fout, "time" ,typeof(time),getvardims(time))
;==================================================================
;===================================================================
filevardef(fout, "time" ,typeof(time),"time")
filevardef(fout, "lat" ,typeof(lat),"lat")
filevardef(fout, "lon" ,typeof(lon),"lon")
filevardef(fout, "diab_heating" ,typeof(diab_heating)
,(/"time","lat","lon"/))
;===================================================================
; Copy attributes associated with each variable to the file
; All attributes associated with each variable will be copied.
;====================================================================
filevarattdef(fout,"diab_heating",diab_heating) ; copy
diab_heating attributes
filevarattdef(fout,"time",time) ; copy time
attributes
filevarattdef(fout,"lat",lat) ; copy lat
attributes
filevarattdef(fout,"lon",lon) ; copy lon
attributes
;===================================================================
; explicitly exit file definition mode. **NOT REQUIRED**
;===================================================================
setfileoption(fout,"DefineMode",False)
;===================================================================
; output only the data values since the dimensionality and such have
; been predefined. The "(/", "/)" syntax tells NCL to only output the
; data values to the predefined locations on the file.
;====================================================================
fout->time = (/time/)
fout->lat = (/lat/)
fout->lon = (/lon/)
fout->T = (/diab_heating/)
;end do
;end do
;end do
;end do
end
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jun 25 2008 - 11:34:15 MDT
This archive was generated by hypermail 2.2.0 : Wed Jun 25 2008 - 12:04:57 MDT