<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi,<br>
<br>
I am having a bit of trouble reading a variable from a large NetCDF4 file <br>
that I have created using an NCL example as a guide. I have a <br>
4D variable sAvg(time,lev,lat,lon) which was calc by the program. I dimensioned <br>
the output file to have time=unlimited. Then I defined a output var <br>
u(1,lev,lat,lon). I then write out a 3D var to output for each time.<br>
<br>
The output file has dimensions as follows:<br>
<br>
dimensions:<br>
time = UNLIMITED ; // (366 currently)<br>
lev = 29 ;<br>
lat = 256 ;<br>
lon = 512 ;<br>
variables:<br>
float v(time, lev, lat, lon) ;<br>
<br>
Here is a snippet of the program that created the file:<br>
==============================================================================<br>
...<br>
setfileoption("nc","Format","NetCDF4")<br>
ncdf_out = addfile(ncout ,"c") ;create output NC file<br>
setfileoption(ncdf_out,"DefineMode",True)<br>
<br>
; date processing loop (tim,lat,lon)<br>
iout=0<br>
sname = 'v' <br>
do i = tim0,tim1,tim_inc<br>
print (i+" "+TIME(i))<br>
S = sfile_nc->$sname$(i,lev0:lev1,:,:) ; read in 3D dataset for 1time<br>
if (i.eq.tim0.and.ny.eq.0) then<br>
sNew = new ( (/nyears,ntimes_out,nlev_out,jlat,ilon/), typeof(S) ) <br>
end if<br>
sNew(ny,iout,:,:,:)=S(:,:,:)<br>
iout=iout+1<br>
end do <br>
<br>
ntimes_out1 = 1<br>
sAvg = new ( (/ntimes_out,nlev_out,jlat,ilon/), typeof(S) ) <br>
u = new ( (/ntimes_out1,nlev_out,jlat,ilon/), typeof(S) ) <br>
stmp = new ( (/nlev_out,jlat,ilon/), typeof(S) ) <br>
sAvg = dim_avg_n(sNew,0) ;avgs over all years(0th dim)<br>
<br>
<br>
dimNames = (/"time", "lev", "lat", "lon"/) <br>
dimSizes = (/ ntimes_out1,nlev_out,jlat,ilon/)<br>
dimUnlim = (/ True, False, False,False/) <br>
filedimdef(ncdf_out,dimNames,dimSizes,dimUnlim)<br>
filevardef(ncdf_out, sname ,typeof(S),dimNames)<br>
filevarattdef(ncdf_out,sname,S) ; assign array atts<br>
<br>
print("Outputting to Netcdf.....")<br>
; output time based vars one at a time since time=unlimited<br>
do iout = 0,ntimes_out-1<br>
stmp = (/sAvg(iout,:,:,:)/)<br>
ncdf_out->$sname$(iout,:,:,:) =(/stmp/)<br>
end do<br>
==============================================================================<br>
end snippet<br>
<br>
<br>
Here is a snippet of the program that reads the large NetCDF file<br>
==============================================================================<br>
<br>
begin<br>
filename = "/jm13/djv/CCLIMO+v_1989-1989_512x256.nc"<br>
ufile_nc = addfile(filename,"r")<br>
vars = getfilevarnames(ufile_nc)<br>
print(vars) <br>
<br>
sys_cmd = "ncdump -h "+filename<br>
system(sys_cmd)<br>
<br>
do i= 160,181<br>
V=ufile_nc->v(i,6:22,:,:)<br>
print(V(2,10,10))<br>
end do<br>
end<br>
==============================================================================<br>
end snippet</p>
<p><br>
When I try to read from this file I get the following error:<br>
fatal:Subscript out of range, error in subscript #0</p>
<p><br>
The program seems to read in the data OK, despite this fatal error.<br>
If I read in the entire array at once I do not get this error:<br>
ie V=ufile_nc->v<br>
<br>
Any ideas on why I am getting this seemingly fatal error?</p>
<p>Thanks</p>
<p><br>
</p>
<p>Dave Vollaro<br>
<br>
<br>
</p>
</div>
</body>
</html>