[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 950923: netCDF Ackpht!!! What's wrong...



> Subject: 1995923
> Ackpht!!! What's wrong...
> 
> >To:       address@hidden
> >From: Bill Roberts <address@hidden>
> >Organization: NCAR/HAO
> >Keywords: 199509232315.AA25964

Hi Bill,

>   I've got the C version of this working, no problemo, but I 
> now, unfortunately, must get it under fortran.  I cannot see
> what is going wrong here.  Might you be able to point out the
> error in my ways?
 ...
>       subroutine wncdf ()
> 
>       include "/opt/local/include/netcdf.inc"
> 
>         common /x/ idata
> 
>       integer idata(5,3)
>       integer start(2), count(2)
>       integer dims(2), ncid, rcode, dataid
>       
>       ncid= nccre("wncdf.nc", NCCLOB, rcode)
> 
>       dims(1)= ncddef(ncid, 'dim1', 5, rcode)
>       dims(2)= ncddef(ncid, 'dim2', NCUNLIM, rcode)
> 
>       dataid= ncvdef(ncid, 'data', NCDOUBLE, 2, dims, rcode)
>       write (6, '("ncvdef: rcode= ",i6)') rcode
> 
> c Close and reopen... to work around a bug/feature ;-)
>       call ncclos(ncid, rcode)
>       ncid= ncopn("wncdf.nc", NCWRITE, rcode)
> 
>       start(1)= 1
>       start(2)= 1
>       count(1)= 5
>       count(2)= 3
>       call ncvpt(ncid, dataid, start, count, idata, rcode)
>       write (6, '("ncvpt: rcode= ",i6)') rcode
> 
>       end

I see three problems:

  1.  You've declared the netcdf variable "data" to be of type NCDOUBLE for
      double-precision floating point, but you're trying to store integer
      data from the Fortran variable "idata".  The data you write has to
      match the type of the variable you write.
      
  2.  You didn't call 
      
        ncendf(ncid,rcode)
      
      after defining dimensions and variables but before writing data.  You
      can't read or write netCDF data in define mode, you need to be in data
      mode first, which requires a call to ncendf().  This call should
      replace your comment about a bug/feature and the unnecessary calls to
      ncclos()/ncopen().  The documentation says ncclos() calls ncendf() for
      you, but it is not intended to replace ncclos().  The fact that you
      don't get an error message when you try to call ncvpt() while still in
      define mode is a bug in the Fortran interface in netCDF 2.3.2 that's
      fixed in the upcoming 2.4 release.

  3.  You haven't called ncclos() at the end of the subroutine, before
      returning.  This is OK if you intend to write more data, but you
      should explicitly call ncclos() before the program exits to make sure
      all the data you have written to the file gets written to the disk.

--Russ