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

Re: 951010: netcdf bug? Corrupted file



Jim:

There is nothing jumping out at us to indicate
the cause of your problem. What you are doing
appears to be reasonable.

We recently (last Thursday) made a new release of netcdf
available, netcdf 2.4 beta. It has some fixes to known bugs
in the I/O layers, and may fix your problem. Please give
that a try if possible and let us know. If it doesn't
fix your problem, at least we'll be working from
from the same base code.

One other thing to check is whether your code
could inadvertently cause a "seek" (position change)
on the netcdf file descriptor.

-glenn

> From: Jim Mansbridge <address@hidden>
> Date: Fri, 13 Oct 95 18:50:49 EST
> To: address@hidden
> Subject: Re: 951010: netcdf bug?
> Cc: address@hidden
>
> Steve,
>
> The intended behaviour of my model is much as you describe:
>
>     1.  run model
>       call cr_netcdf
>       time step loop begins
>               call hist_netcdf
>       time step loop ends
>
>     2.  cp hist_09a.nc hist_09c_1.nc
>
>     3.  run model 2nd time
>       time step loop begins
>               call hist_netcdf
>       time step loop ends
>
>     4.  cp hist_09a.nc hist_09c_2.nc
>
> The second run differs from the first in that it does not have to create
> the file hist_09a.nc.  I begin cr_netcdf by creating hist_09a.nc and
> then close it at the end.  I begin hist_netcdf by opening hist_09a.nc
> and then close it at the end.
>
> To make this clearer I have included code fragments (a lot of the code
> was generated by using ncgen -f)
>
> %%% Begin fragment from cr_netcdf %%%
>
> !     enter define mode
>          ncid = nccre (filename, NCCLOB, iret)
> !     define dimensions
>          Lmdim = ncddef(ncid, 'Lm', Lm, iret)
>          Ldim = ncddef(ncid, 'L', L, iret)
>          Lpdim = ncddef(ncid, 'Lp', Lp, iret)
>          Mmdim = ncddef(ncid, 'Mm', Mm, iret)
>          Mdim = ncddef(ncid, 'M', M, iret)
>          Mpdim = ncddef(ncid, 'Mp', Mp, iret)
>          Ndim = ncddef(ncid, 'N', N, iret)
>          onesixtydim = ncddef(ncid, 'onesixty', 160, iret)
> #if defined ISLANDS || defined PERINTG
>          nifreedim = ncddef(ncid, 'nifree', nifree, iret)
> #endif  /* ISLANDS || PERINTG */
>          record_nodim = ncddef(ncid, 'record_no', NCUNLIM, iret)
> !     define variables
>          dims(2) = record_nodim
>          dims(1) = onesixtydim
>          identid = ncvdef (ncid, 'ident', NCCHAR, 2, dims, iret)
>          dims(1) = record_nodim
>          timeid = ncvdef (ncid, 'time', NCDOUBLE, 1, dims, iret)
>          dims(4) = record_nodim
>          dims(3) = Ndim
>          dims(2) = Mpdim
>          dims(1) = Ldim
>          uid = ncvdef (ncid, 'u', NCFLOAT, 4, dims, iret)
>          dims(4) = record_nodim
>          dims(3) = Ndim
>          dims(2) = Mdim
>          dims(1) = Lpdim
>          vid = ncvdef (ncid, 'v', NCFLOAT, 4, dims, iret)
>          dims(4) = record_nodim
>          dims(3) = Ndim
>          dims(2) = Mpdim
>          dims(1) = Lpdim
>          tid = ncvdef (ncid, 't', NCFLOAT, 4, dims, iret)
> #ifdef S_CALC
>          dims(4) = record_nodim
>          dims(3) = Ndim
>          dims(2) = Mpdim
>          dims(1) = Lpdim
>          sid = ncvdef (ncid, 's', NCFLOAT, 4, dims, iret)
> #endif   /* S_CALC */
>          dims(3) = record_nodim
>          dims(2) = Mdim
>          dims(1) = Ldim
>          psiid = ncvdef (ncid, 'psi', NCFLOAT, 3, dims, iret)
> #if defined ISLANDS || defined PERINTG
>          dims(2) = record_nodim
>          dims(1) = nifreedim
>          circid = ncvdef (ncid, 'circ', NCFLOAT, 2, dims, iret)
> #endif  /* ISLANDS || PERINTG */
> !     assign attributes
>          call ncaptc(ncid, identid, 'long_name', NCCHAR, 29,
>      $        'first 2 lines of spem.in file', iret)
>          call ncaptc(ncid, timeid, 'long_name', NCCHAR, 13,
>      $        'snapshot time', iret)
>          call ncaptc(ncid, timeid, 'units', NCCHAR, 50, date_start_run,
>      $        iret)
>          call ncaptc(ncid, uid, 'long_name', NCCHAR, 16,
>      $        'u(i, j, k, lnew)', iret)
>          call ncaptc(ncid, uid, 'units', NCCHAR, 5, 'm/sec', iret)
>          call ncaptc(ncid, vid, 'long_name', NCCHAR, 16,
>      $        'v(i, j, k, lnew)', iret)
>          call ncaptc(ncid, vid, 'units', NCCHAR, 5, 'm/sec', iret)
>          call ncaptc(ncid, tid, 'long_name', NCCHAR, 16,
>      $        't(i, j, k, lnew)', iret)
>          call ncaptc(ncid, tid, 'units', NCCHAR, 9, 'degrees C', iret)
> #ifdef S_CALC
>          call ncaptc(ncid, sid, 'long_name', NCCHAR, 16,
>      $        's(i, j, k, lnew)', iret)
>          call ncaptc(ncid, sid, 'units', NCCHAR, 3, 'ppt', iret)
> #endif   /* S_CALC */
>          call ncaptc(ncid, psiid, 'long_name', NCCHAR, 14,
>      $        'streamfunction', iret)
>          call ncaptc(ncid, psiid, 'units', NCCHAR, 8, 'm**2/sec', iret)
> #if defined ISLANDS || defined PERINTG
>          call ncaptc(ncid, circid, 'long_name', NCCHAR, 38,
>      $        'circulation around each island at lnew', iret)
>          call ncaptc(ncid, circid, 'units', NCCHAR, 8, 'm**2/sec', iret)
> #endif  /* ISLANDS || PERINTG */
> !     leave define mode
>          call ncendf(ncid, iret)
>          call ncclos (ncid, iret)
>
>          print*, 'Create ', filename
> %%% End fragment from cr_netcdf %%%
>
> %%% Begin fragment from hist_netcdf %%%
>
>       ncid = ncopn (cdf_name(iout), NCWRITE, iret)
>       if ( iret .ne. 0 ) then
>          return
>       endif
>
>       corner(1) = 1
>       edges(1) = 160
>       corner(2) = count_out
>       edges(2) = 1
>       idd = ncvid (ncid, 'ident', iret)
>       call ncvptc(ncid, idd, corner, edges, ident, 160, iret)
>       if ( iret .ne. 0 ) return
>
>       corner(1) = count_out
>       edges(1) = 1
>       idd = ncvid (ncid, 'time', iret)
>       if ( count_out .eq. 1 ) then
>          call ncaptc(ncid, idd, 'units', NCCHAR, 50, date_start_run,
>      $        iret)
>       endif
>       xx = time
>       call ncvpt1(ncid, idd, corner, xx, iret)
>       if ( iret .ne. 0 ) return
>
> !     print*, 'time = ', time
>
>       corner(1) = 1
>       corner(2) = 1
>       corner(4) = count_out
>       edges(1) = L
>       edges(2) = Mp
>       edges(3) = 1
>       edges(4) = 1
>       idd = ncvid (ncid, 'u', iret)
>       do k = 1, N
>          corner(3) = k
>          call slice_netcdf(.false., u(1, 0, k, lnew), 2)
>       enddo
>
>       corner(1) = 1
>       corner(2) = 1
>       corner(4) = count_out
>       edges(1) = Lp
>       edges(2) = M
>       edges(3) = 1
>       edges(4) = 1
>       idd = ncvid (ncid, 'v', iret)
>       do k = 1, N
>          corner(3) = k
>          call slice_netcdf(.false., v(0, 1, k, lnew), 2)
>       enddo
>
>       corner(1) = 1
>       corner(2) = 1
>       corner(4) = count_out
>       edges(1) = Lp
>       edges(2) = Mp
>       edges(3) = 1
>       edges(4) = 1
>       idd = ncvid (ncid, 't', iret)
>       do k = 1, N
>          corner(3) = k
>          call slice_netcdf(.false., t(0, 0, k, lnew), 2)
>       enddo
>
> #ifdef S_CALC
>
>       corner(1) = 1
>       corner(2) = 1
>       corner(4) = count_out
>       edges(1) = Lp
>       edges(2) = Mp
>       edges(3) = 1
>       edges(4) = 1
>       idd = ncvid (ncid, 's', iret)
>       do k = 1, N
>          corner(3) = k
>          call slice_netcdf(.false., s(0, 0, k, lnew), 2)
>       enddo
>
> #endif  /* S_CALC */
>
>       corner(1) = 1
>       corner(2) = 1
>       corner(3) = count_out
>       edges(1) = L
>       edges(2) = M
>       edges(3) = 1
>       idd = ncvid (ncid, 'psi', iret)
>       call slice_netcdf(.false., psi, 2)
>
> #if defined ISLANDS || defined PERINTG
>
>       corner(1) = 1
>       corner(2) = count_out
>       edges(1) = nifree
>       edges(2) = 1
>       idd = ncvid (ncid, 'circ', iret)
>       call slice_netcdf(.false., circ, 1)
>
> #endif  /* ISLANDS || PERINTG */
>
> !     call ncendf(ncid, iret)
>       call ncclos (ncid, iret)
>       count_out = count_out + 1
> !     stop 'one done'
>       return
> %%% End fragment from hist_netcdf %%%
>
> This is probably more code than you wanted to see, but unfortunately I
> have not been able to reproduce the problem in a smaller program.
> Although I do access other netcdf files during my model run they are
> opened as readonly and I follow the same procedure of opening and
> closing them in the same subroutine.  If I do have a bug in my code
> (like confusing netCDF IDs) it seems a bit strange that the
> behaviour on the Cray is all right.
>
>       Thanks for your trouble,
>       Jim
>
> Jim Mansbridge                   |  email:     address@hidden
> CSIRO Marine Laboratories  |  telephone: within Australia (002) 32 5416
> GPO Box 1538             |             Internationally +61 02 32 5416
> Hobart                           |  fax:       within Australia (002) 32 5123
> Australia 7001                   |             Internationally +61 02 32 5123