This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Maureen, > To: address@hidden > From: Maureen Cribb <address@hidden> > Organization: Dalhousie University > Keywords: 199512191601.AA23714 In the above message you wrote: > Enclosed are a couple of sample programs and small data sets that > illustrate the problem I'm having in appending data. > > The program "first.f" creates a netcdf file containing the variable > "a1" (with an unlimited dimension), reads in data from "first.dat" > (ten elements) and writes this data to the netcdf file. This part > works fine. > > Now an additional five elements (from "second.dat") are to appended > to the variable in this netcdf file. The program "second.f" opens > the newly created netcdf file, gets the id number for the "a1" > variable, reads in data from "second.dat" and writes it to the netcdf > file. This data is, indeed, appended but extra data also appears to be > appended. > > I expected fifteen elements to appear for "a1" in the netcdf file but > twenty-five elements actually appear. Could you shed some light on this > situation? > > Thanks in advance for your help ... > > M.Cribb > > - ---------- > X-Sun-Data-Type: default > X-Sun-Data-Name: first.f > X-Sun-Content-Lines: 35 > > program first > > include '/opt/netcdf/include/netcdf.inc' > > integer ncid,rcode,rec_dim,a1_id > real a1(10) > > c open data file > open(1000, file='first.dat', status='old') > > c create netcdf file > ncid=nccre('try.nc',ncnoclob,rcode) I'd change the `ncnoclob' to `ncclob' in the above line to prevent reuse of a previously existing netCDF dataset. > > c define dimension and variable > rec_dim=ncddef(ncid,'index',ncunlim,rcode) > > a1_id=ncvdef(ncid,'a1',ncfloat,1,rec_dim,rcode) > > c leave define mode > call ncendf(ncid,rcode) > > c read in data and put into netcdf file > > do i=1,10 > > read(1000,'(f5.2)') a1(i) > > end do > > call ncvpt(ncid,a1_id,1,10,a1,rcode) > > c close netcdf file > call ncclos(ncid,rcode) > > end > - ---------- > X-Sun-Data-Type: default > X-Sun-Data-Name: second.f > X-Sun-Content-Lines: 32 > > program second > > include '/opt/netcdf/include/netcdf.inc' > > integer ncid,rcode,a1_id > real a1(5) > > c open data file > open(1000, file='second.dat', status='old') > > c open old netcdf file > ncid=ncopn('try.nc',ncwrite,rcode) > > c get variable id > a1_id=ncvid(ncid,'a1',rcode) > > c read in data and append to netcdf file > > do i=1,5 > > read(1000,'(f5.2)') a1(i) > > end do > > > call ncvpt(ncid,a1_id,11,15,a1,rcode) The fourth argument above should be `5' rather than `15'. The COUNTS argument indicates how much data the `a1' variable contains. In this case, you're adding 5 additional values -- not 15. > > > c close netcdf file > call ncclos(ncid,rcode) > > end Please let me know if this helps. -------- Steve Emmerson <address@hidden>