[ncl-talk] Reading variable from large NetCDF file
Vollaro, David
dvollaro at albany.edu
Fri May 15 16:14:19 MDT 2015
Hi,
I am having a bit of trouble reading a variable from a large NetCDF4 file
that I have created using an NCL example as a guide. I have a
4D variable sAvg(time,lev,lat,lon) which was calc by the program. I dimensioned
the output file to have time=unlimited. Then I defined a output var
u(1,lev,lat,lon). I then write out a 3D var to output for each time.
The output file has dimensions as follows:
dimensions:
time = UNLIMITED ; // (366 currently)
lev = 29 ;
lat = 256 ;
lon = 512 ;
variables:
float v(time, lev, lat, lon) ;
Here is a snippet of the program that created the file:
==============================================================================
...
setfileoption("nc","Format","NetCDF4")
ncdf_out = addfile(ncout ,"c") ;create output NC file
setfileoption(ncdf_out,"DefineMode",True)
; date processing loop (tim,lat,lon)
iout=0
sname = 'v'
do i = tim0,tim1,tim_inc
print (i+" "+TIME(i))
S = sfile_nc->$sname$(i,lev0:lev1,:,:) ; read in 3D dataset for 1time
if (i.eq.tim0.and.ny.eq.0) then
sNew = new ( (/nyears,ntimes_out,nlev_out,jlat,ilon/), typeof(S) )
end if
sNew(ny,iout,:,:,:)=S(:,:,:)
iout=iout+1
end do
ntimes_out1 = 1
sAvg = new ( (/ntimes_out,nlev_out,jlat,ilon/), typeof(S) )
u = new ( (/ntimes_out1,nlev_out,jlat,ilon/), typeof(S) )
stmp = new ( (/nlev_out,jlat,ilon/), typeof(S) )
sAvg = dim_avg_n(sNew,0) ;avgs over all years(0th dim)
dimNames = (/"time", "lev", "lat", "lon"/)
dimSizes = (/ ntimes_out1,nlev_out,jlat,ilon/)
dimUnlim = (/ True, False, False,False/)
filedimdef(ncdf_out,dimNames,dimSizes,dimUnlim)
filevardef(ncdf_out, sname ,typeof(S),dimNames)
filevarattdef(ncdf_out,sname,S) ; assign array atts
print("Outputting to Netcdf.....")
; output time based vars one at a time since time=unlimited
do iout = 0,ntimes_out-1
stmp = (/sAvg(iout,:,:,:)/)
ncdf_out->$sname$(iout,:,:,:) =(/stmp/)
end do
==============================================================================
end snippet
Here is a snippet of the program that reads the large NetCDF file
==============================================================================
begin
filename = "/jm13/djv/CCLIMO+v_1989-1989_512x256.nc"
ufile_nc = addfile(filename,"r")
vars = getfilevarnames(ufile_nc)
print(vars)
sys_cmd = "ncdump -h "+filename
system(sys_cmd)
do i= 160,181
V=ufile_nc->v(i,6:22,:,:)
print(V(2,10,10))
end do
end
==============================================================================
end snippet
When I try to read from this file I get the following error:
fatal:Subscript out of range, error in subscript #0
The program seems to read in the data OK, despite this fatal error.
If I read in the entire array at once I do not get this error:
ie V=ufile_nc->v
Any ideas on why I am getting this seemingly fatal error?
Thanks
Dave Vollaro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20150515/97dd4632/attachment.html
More information about the ncl-talk
mailing list