<div dir="ltr">David,<br><br>The line "setfileoption("nc","Format",ofile_type(ityp))" must be placed *before* the addfile command. This is on the documentation page for setfileoption, under the "Format" heading.<br><div><br></div><div>--Dave</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 25, 2015 at 1:12 PM, Vollaro, David <span dir="ltr"><<a href="mailto:dvollaro@albany.edu" target="_blank">dvollaro@albany.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div style="font-size:12pt;color:#000000;background-color:#ffffff;font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Hi,</p>
<p><br>
</p>
<p>I am trying to write to a NetCDF output file and am running into what I believe is a size limitation. When
</p>
<p>I write out fewer times this problem goes away. I searched for the error and believe that is linked to an</p>
<p>output size issue. I tried changing the NetCDF format following <a href="http://www.ncl.ucar.edu/FAQ/#file_io_004" target="_blank">
http://www.ncl.ucar.edu/FAQ/#file_io_004</a></p>
<p>However, I still get the same error:</p>
<p><br>
</p>
<p>ncendef: ncid 589824: NetCDF: One or more variable sizes violate format constraints<br>
fatal:NetCDF: Operation not allowed in define mode: error attempting to write variable (u) to file (/jm13/djv/XUVTest.nc)<br>
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 164 in file netcdf-size-tst.ncl<br>
<br>
(0) u<br>
ncredef: ncid 589824: NetCDF: Operation not allowed in define mode<br>
ncendef: ncid 589824: NetCDF: One or more variable sizes violate format constraints<br>
fatal:NetCDF: Operation not allowed in define mode: error attempting to write variable (lev) to file (/jm13/djv/XUVTest.nc)<br>
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 166 in file netcdf-size-tst.ncl<br>
<br>
(0) v<br>
ncredef: ncid 589824: NetCDF: Operation not allowed in define mode<br>
ncendef: ncid 589824: NetCDF: One or more variable sizes violate format constraints<br>
fatal:NetCDF: Operation not allowed in define mode: error attempting to write variable (time) to file (/jm13/djv/XUVTest.nc)<br>
fatal:["Execute.c":8128]:Execute: Error occurred at or near line 168 in file netcdf-size-tst.ncl<br>
<br>
(0) t<br>
ncclose: ncid 589824: NetCDF: One or more variable sizes violate format constraints</p>
<p><br>
</p>
<p>----------------------------------------------------------------------------------------------------</p>
<p>I am running version 6.1.2. I have attached the script below and it is called with a parameter:</p>
<p>ncl ityp=3 netcdf-size-tst.ncl</p>
<p><br>
</p>
<p>I have tried "NetCDF3" "NetCDF4" "LargeFile" "64BitOffset" and "NetCDF4Classic" to no avail.</p>
<p>Any help would be appreciated! Thanks</p>
<p><br>
</p>
<p>Dave Vollaro</p>
<p><br>
</p>
<p>----------------------------------------------------------------------------------------------------</p>
<p> test script <br>
</p>
<p>----------------------------------------------------------------------------------------------------</p>
<p>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"<br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"<br>
;load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/ut_string.ncl"<br>
<br>
begin<br>
; netcdf-size-tst.ncl<br>
; Modified by djv 2/13/15<br>
; This program will test size constraints in writing out NETCDF output in ncl.<br>
; Will address below errors: <br>
; ncendef:ncid 327680: NetCDF:One or more variable sizes violate format constraints<br>
; ncvarput: ncid 327680: NetCDF: Operation not allowed in define mode<br>
;<br>
; Will test various setfileoption "Format" options:<br>
; ie "NetCDF3" "NetCDF4" "LargeFile" "64BitOffset" "NetCDF4Classic"<br>
<br>
<br>
print("Starting time:")<br>
sys_cmd = "date "<br>
system(sys_cmd)<br>
sys_cmd = "sleep 1 "<br>
system(sys_cmd)<br>
<br>
;***********************************************<br>
; set USER DEF VARS<br>
;***********************************************<br>
ilon = 512 ;num lons of input GG grid <br>
jlat = 256 ;num lats of input GG grid <br>
odatpth = "/jm13/djv/"<br>
ofile_type = new((/5/),"string")<br>
ofile_type = (/"NetCDF3","NetCDF4","LargeFile","64BitOffset","NetCDF4Classic"/)<br>
print(ofile_type)<br>
ntimes_out=30<br>
year = 1979<br>
;***********************************************<br>
; LEVEL EXTRACT RANGE <br>
;***********************************************<br>
parm = True<br>
parm@blev = 1000 ;bottommost plev to extract both=999 extract all levs<br>
parm@tlev = 50 ;topmost plev to extract both=999 extract all levs<br>
<br>
<br>
;***********************************************<br>
; DATA SOURCE<br>
;***********************************************<br>
url = "<a href="http://ramadda.atmos.albany.edu:8080/repository/opendap/Top/" target="_blank">http://ramadda.atmos.albany.edu:8080/repository/opendap/Top/</a>"<br>
filename_u = url+ "UAlbany+Repository/ERA-Interim/"+year+"/u."+year+".nc/entry.das"<br>
filename_v = url+ "UAlbany+Repository/ERA-Interim/"+year+"/v."+year+".nc/entry.das"<br>
filename_t = url+ "UAlbany+Repository/ERA-Interim/"+year+"/t."+year+".nc/entry.das"<br>
exists = isfilepresent(filename_t)<br>
if(.not.exists) then <br>
print("OPeNDAP isfilepresent test unsuccessful.")<br>
print("File doesn't exist or NCL doesn't have OPeNDAP ability on this system")<br>
else<br>
print("OPeNDAP isfilepresent test successful.")<br>
ufile_nc = addfile(filename_u,"r")<br>
vfile_nc = addfile(filename_v,"r")<br>
tfile_nc = addfile(filename_t,"r")<br>
vars = getfilevarnames(ufile_nc)<br>
print(vars) <br>
end if<br>
<br>
sys_cmd = "ncdump -h "+filename_u<br>
system(sys_cmd)<br>
<br>
namesu = getfilevarnames(ufile_nc) ;Get the variable names in the<br>
namesv = getfilevarnames(vfile_nc) ;Get the variable names in the<br>
namest = getfilevarnames(tfile_nc) ;Get the variable names in the<br>
print(namesu) ;GRIB file and print them out.<br>
print(namesv) ;GRIB file and print them out.<br>
print(namest) ;GRIB file and print them out.<br>
<br>
;***********************************************<br>
; level range selection processing section<br>
;***********************************************<br>
levname = str_match(namesu,"lev") ;finds lev array name (top2bot)<br>
levdims = getfilevardimsizes (vfile_nc,levname) ;<br>
<br>
LEV = ufile_nc->$levname$ ;read in level data<br>
if (parm@blev.eq. 999.and.parm@tlev.eq. 999) then<br>
lev0=0<br>
lev1=levdims-1<br>
else<br>
lev0 = ind_nearest_coord(parm@blev,LEV,0)<br>
lev1 = ind_nearest_coord(parm@tlev,LEV,0)<br>
end if<br>
nlev_out = lev1 - lev0 + 1<br>
print (parm@blev+" "+lev0+" "+parm@tlev+" "+lev1+" nlevout="+nlev_out)<br>
print (LEV(lev0:lev1))<br>
<br>
<br>
;***********************************************<br>
; check for existing output files and remove<br>
;***********************************************<br>
ncout = odatpth+"XUVTest.nc"<br>
rmcmd = "'rm' " + ncout<br>
system (rmcmd) ;remove any pre-exist ncout fil<br>
ncdf_out = addfile(ncout ,"c") ;create output NC file<br>
setfileoption(ncdf_out,"DefineMode",True)<br>
setfileoption("nc","Format",ofile_type(ityp))<br>
print("NCOUT "+ofile_type(ityp))<br>
<br>
;===================================================================<br>
; create global attributes of the file<br>
;===================================================================<br>
fAtt = True ; assign file attributes<br>
fAtt@title = "NCL Efficient Approach to netCDF Creation" <br>
fAtt@source_file = "<a href="http://original-file.nc" target="_blank">original-file.nc</a>"<br>
fAtt@Conventions = "None" <br>
fAtt@creation_date = systemfunc ("date") <br>
fileattdef( ncdf_out, fAtt ) ; copy file attributes <br>
<br>
<br>
<br>
iout=0<br>
;******************************************************************************<br>
; data processing loop (U/V/T(tim,lev,lat,lon)<br>
;******************************************************************************<br>
do i = 0,ntimes_out-1<br>
print (i+" ")<br>
vname = str_match(namesv,"v") ;finds lev array name (top2bot)<br>
V = vfile_nc->v(i,lev0:lev1,:,:) ; read in 3D dataset for 1time<br>
<br>
uname = str_match(namesu,"u") ;finds lev array name (top2bot)<br>
U = ufile_nc->u(i,lev0:lev1,:,:) ; read in 3D dataset for 1time<br>
<br>
tname = str_match(namest,"t") ;finds lev array name (top2bot)<br>
T = tfile_nc->t(i,lev0:lev1,:,:) ; read in 3D dataset for 1time<br>
<br>
<br>
if (i .eq. 0 ) then<br>
;===================================================================<br>
; define dimension characteristics of NETCDF output file<br>
;===================================================================<br>
dimNames = (/"time", "level", "latitude", "longitude"/) <br>
dimSizes = (/ ntimes_out,nlev_out,jlat,ilon/)<br>
dimUnlim = (/ False, False, False, False/) <br>
filedimdef(ncdf_out,dimNames,dimSizes,dimUnlim)<br>
<br>
;===================================================================<br>
; predefine the the dimensionality of the variables to be written out<br>
;===================================================================<br>
filevardef(ncdf_out, "u" ,typeof(U),dimNames)<br>
filevardef(ncdf_out, "v" ,typeof(V),dimNames)<br>
filevardef(ncdf_out, "t" ,typeof(T),dimNames)<br>
<br>
uNew = new ( (/ntimes_out,nlev_out,jlat,ilon/), typeof(U) ) <br>
vNew = new ( (/ntimes_out,nlev_out,jlat,ilon/), typeof(V) ) <br>
tNew = new ( (/ntimes_out,nlev_out,jlat,ilon/), typeof(T) ) <br>
end if<br>
<br>
uNew(iout,:,:,:) = U(lev0:lev1,:,:)<br>
vNew(iout,:,:,:) = V(lev0:lev1,:,:)<br>
tNew(iout,:,:,:) = T(lev0:lev1,:,:)<br>
iout=iout+1<br>
end do <br>
;==========End time processing loop ================================<br>
end<br>
<br>
print("write output")<br>
ncdf_out->$uname$ = (/uNew/)<br>
print("u")<br>
ncdf_out->$vname$ = (/vNew/)<br>
print("v")<br>
ncdf_out->$tname$ = (/tNew/)<br>
print("t")<br>
exit<br>
</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>
</div>
</div>
<br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>