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

[netCDF #GYC-914895]: Reading of file produces corrupted data



Stefan,

After looking at the "bug" more carefully, it appears to be in the program 
that calls nf90_put_var().  The bug is trying to access the values of the
array ctns(NX,NY) which is local to the subroutine ncread_debug(), *after*
returning from that subroutine.  You can't depend on values local to a
subroutine still being available after the subroutine has returned, unless
you mark the values with the "save" attribute.

You can verify this fixes the problem by inserting the "save" attribute in
your declaration of the local array in ncread_debug():

! Without a 'save' attribute, the following array is local to this subroutine
! so its values shouldn't be depended on after return to caller
!       real(rk), target :: ctns(NX,NY)
        real(rk), save, target :: ctns(NX,NY)

--Russ

> > When I compile the program run.f90 with
> >
> > gfortran run.f90 -o run -lnetcdff -L/home/z3439823/programs/netcdf/lib 
> > -I/home/z3439823/programs/netcdf/include
> >
> > and run it, the data in data_in.nc is read partially corrupted. The program
> > outputs the last data entry as 0.0, and not -1.84714535003628, which is the
> > last value in
> >
> > ncdump -v ctns data_in.nc
> >
> > The command
> >
> > ncdump -v ctns data_out.nc
> >
> > shows that the output data is partially corrupted (about the last third of
> > the data is bad).
> >
> > I have tried to understand what's going on, but I have no clue. I do the
> > exact same procedure with other datasets of identical size and type, and it
> > works as it should.
> >
> > I use netcdf-4.2.1.
> 
> Using our latest snapshot release of the netCDF C and Fortran-90 libraries,
> I can reproduce the error you're seeing, though I don't understand yet
> what the cause is.  It appears to be a bug in the netCDF F90 library, but
> I'll need to spend more time studying the problem in a debugger.
> 
> Thanks for reporting this potentially serious problem, and for providing
> the demonstration program.  I'm entering the problem in our bug-tracking
> system, where you can follow any progress we make in finding and fixing
> the bug:
> 
> https://bugtracking.unidata.ucar.edu/browse/NCFORTRAN-23
> 
> --Russ
> 
> Russ Rew                                         UCAR Unidata Program
> address@hidden                      http://www.unidata.ucar.edu
> 
> 
Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu



Ticket Details
===================
Ticket ID: GYC-914895
Department: Support netCDF
Priority: Normal
Status: Closed