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

Re: netcdf 2.4.3 problem under Solaris 2.5.1 (SunOS 5.5.1) 199611011851.AA26718



Harry:

Attached find a patch to the 2.4 version of libsrc/putget.c which sets
ncerr for problems like this.

Once this patch is applied, your test program will say something like
ncvarget: xdr_floats
when run on this file. I personally don't think this is very helpful,
but there it is.

What is interesting about this file is that is that it violates an
assumption about netcdf file structure. I'm not sure if this file could
be created by a the netcdf library in the absence of a file system error.
The assumption is that records are filled out to the end of a record.
This file has 365 records. If the file followed the assumption,
there would be data for the variable ROBS out to coordinate {364, 0, 26, 38}.
Data for the stops (the file ends) at coordinate {364, 0, 26, 24}.
It might be possible to create such a file if NC_NOFILL was on, but I don't
think so. (If it were so, it would be a bug.) Since the file ends 3 bytes into
{364, 0, 26, 25}, I don't think that is the case here. More likely the the file
was trucated by a file system full error during creation or during a copy.

Just to be clear, the file length is
-r--r--r--   1 davis    ustaff   1539383 Nov  8 09:59 ALSY_1990.nc
If the file were correct, it's length would be 1539436.

ncdump of the file shows some wildly varying values in the data.

-glenn
*** putget.c-   Fri Sep 20 15:26:36 1996
--- putget.c    Fri Nov  8 11:03:42 1996
***************
*** 73,80 ****
  
                /* compute sub size */
                if( !xdr_NC_fill(xdrs, *vpp) )
-                       /* MEMORY: should xdr_free(xdr_NC_fill,
-                        * *vpp) be called? */
                        return(FALSE) ;
        }
        return(TRUE) ;
--- 73,78 ----
***************
*** 158,165 ****
                if(handle->flags & NC_NSYNC) /* write out header->numrecs NOW */
                {
                        if(!xdr_numrecs(handle->xdrs, handle) )
-                               /* MEMORY: should xdr_free(xdr_numrecs,
-                                * handle) be called? */
                                return(FALSE) ;
                        handle->flags &= ~NC_NDIRTY ;
                }
--- 156,161 ----
***************
*** 244,250 ****
--- 240,249 ----
         *              - limitations of stdio, open for update
         */
                if( !xdr_setpos(xdrs, origin) ) 
+               {
+                       nc_serror("Can't set position %lu", origin) ;
                        return(FALSE) ;
+               }
  #endif /* XDRSTDIO */
                /* next op is a get */
                xdrs->x_op = XDR_DECODE ;
***************
*** 296,304 ****
--- 295,309 ----
        if(x_op == XDR_ENCODE)
        {
                if( !xdr_setpos(xdrs, origin) )
+               {
+                       nc_serror("Can't set position %lu", origin) ;
                        return(FALSE) ;
+               }
                if( !xdr_opaque(xdrs, buf, 4))
+               {
+                       NCadvise(NC_EXDR, "xdr_opaque") ;
                        return(FALSE) ;
+               }
        }
  
        return(TRUE) ;
***************
*** 325,331 ****
--- 330,339 ----
  #ifdef XDRSTDIO
                /* See N.B. above */
                if( !xdr_setpos(xdrs, origin) ) 
+               {
+                       nc_serror("Can't set position %lu", origin) ;
                        return(FALSE) ;
+               }
  #endif /* XDRSTDIO */
                /* next op is a get */
                xdrs->x_op = XDR_DECODE ;
***************
*** 366,374 ****
--- 374,388 ----
                buf[which] = (*values >> 8) ;
  
                if( !xdr_setpos(xdrs, origin) )
+               {
+                       nc_serror("Can't set position %lu", origin) ;
                        return(FALSE) ;
+               }
                if( !xdr_opaque(xdrs, (caddr_t)buf, 4))
+               {
+                       NCadvise(NC_EXDR, "xdr_opaque") ;
                        return(FALSE) ;
+               }
        }
        else
        {
***************
*** 394,399 ****
--- 408,414 ----
  Void *values ;
  {
        u_long rem ;
+       bool_t xstat = FALSE;
  
        switch(type){
        case NC_BYTE :
***************
*** 404,410 ****
--- 419,428 ----
                break ;
        }
        if( !xdr_NCsetpos(xdrs, where) )
+       {
+               nc_serror("Can't set position %lu", where) ;
                return(FALSE) ;
+       }
  
        switch(type){
        case NC_BYTE :
***************
*** 414,426 ****
        case NC_SHORT :
                return( xdr_NCvshort(xdrs, (unsigned)rem/2, (short *)values) ) ;
        case NC_LONG :
!               return( xdr_nclong(xdrs, (nclong *)values) ) ;
        case NC_FLOAT :
!               return( xdr_float(xdrs, (float *)values) ) ;
        case NC_DOUBLE : 
!               return( xdr_double(xdrs, (double *)values) ) ;
        }
!       return(FALSE) ;
  }
  
  
--- 432,455 ----
        case NC_SHORT :
                return( xdr_NCvshort(xdrs, (unsigned)rem/2, (short *)values) ) ;
        case NC_LONG :
!               xstat = xdr_nclong(xdrs, (nclong *)values) ;
!               break;
        case NC_FLOAT :
!               xstat = xdr_float(xdrs, (float *)values) ;
!               break;
        case NC_DOUBLE : 
!               xstat = xdr_double(xdrs, (double *)values) ;
!               break;
!       default:
!               xstat = FALSE;
!               NCadvise(NC_EBADTYPE, "xdr_NCv1data") ;
!               break;
        }
!       if(!xstat)
!       {
!               NCadvise(NC_EXDR, "xdr_NCv1data") ;
!       }
!       return(xstat) ;
  }
  
  
***************
*** 450,466 ****
  
        if(vp->assoc->count == 0) /* 'scalar' variable */
        {
!               return(
!               xdr_NCv1data(handle->xdrs, vp->begin, vp->type, value) ?
                0 : -1 ) ;
- #if 0
-               /* MEMORY: should the above be rewritten as the
-                * following in order to plug a memory leak? */
-               if (xdr_NCv1data(handle->xdrs, vp->begin, vp->type, value))
-                   return 0;
-               xdr_free(xdr_NCv1data, value);
-               return -1;
- #endif
        }
  
        if( !NCcoordck(handle, vp, coords) )
--- 479,486 ----
  
        if(vp->assoc->count == 0) /* 'scalar' variable */
        {
!               return( xdr_NCv1data(handle->xdrs, vp->begin, vp->type, value) ?
                0 : -1 ) ;
        }
  
        if( !NCcoordck(handle, vp, coords) )
***************
*** 476,482 ****
  #endif /* VDEBUG */
  
        if( !xdr_NCv1data(handle->xdrs, offset, vp->type, value))
-               /* MEMORY: should xdr_free(xdr_NCv1data, value) be called? */
                return(-1) ;
  
        return(0) ;
--- 496,501 ----
***************
*** 553,559 ****
--- 572,581 ----
                break ;
        }
        if( !xdr_NCsetpos(xdrs, where) )
+       {
+               nc_serror("Can't set position %lu", where) ;
                return(FALSE) ;
+       }
  
        switch(type){
        case NC_BYTE :
***************
*** 570,576 ****
--- 592,601 ----
                rem = count%4 ; /* tail remainder */
                count -= rem ;
                if(!xdr_opaque(xdrs, values, count))
+               {
+                       NCadvise(NC_EXDR, "xdr_opaque") ;
                        return(FALSE) ;
+               }
  
                if(rem != 0)
                {
***************
*** 580,586 ****
                                return(FALSE) ;
                        return(TRUE) ;  
                } /* else */
!               return(TRUE) ;
        case NC_SHORT :
                if(rem != 0)
                {
--- 605,611 ----
                                return(FALSE) ;
                        return(TRUE) ;  
                } /* else */
!               break ;
        case NC_SHORT :
                if(rem != 0)
                {
***************
*** 592,598 ****
--- 617,626 ----
                rem = count%2 ; /* tail remainder */
                count -= rem ;
                if(!xdr_shorts(xdrs, (short *)values, count))
+               {
+                       NCadvise(NC_EXDR, "xdr_shorts") ;
                        return(FALSE) ;
+               }
                if(rem != 0)
                {
                        values += (count * sizeof(short)) ;
***************
*** 599,614 ****
                        return( xdr_NCvshort(xdrs, (unsigned)0,
                                (short *)values) ) ;
                } /* else */
!               return(TRUE) ;
        case NC_LONG :
!               return( xdr_nclongs(xdrs, (nclong *)values, count) );
        case NC_FLOAT :
!               return( xdr_floats(xdrs, (float *)values, count) );
        case NC_DOUBLE : 
!               return( xdr_doubles(xdrs, (double *)values, count) );
        default :
                return(FALSE) ;
        }
  }
  
  
--- 627,659 ----
                        return( xdr_NCvshort(xdrs, (unsigned)0,
                                (short *)values) ) ;
                } /* else */
!               break ;
        case NC_LONG :
!               if( !xdr_nclongs(xdrs, (nclong *)values, count) )
!               {
!                       NCadvise(NC_EXDR, "xdr_nclongs") ;
!                       return FALSE ;
!               }
!               break;
        case NC_FLOAT :
!               if( !xdr_floats(xdrs, (float *)values, count) )
!               {
!                       NCadvise(NC_EXDR, "xdr_floats") ;
!                       return FALSE ;
!               }
!               break;
        case NC_DOUBLE : 
!               if( !xdr_doubles(xdrs, (double *)values, count) )
!               {
!                       NCadvise(NC_EXDR, "xdr_doubles") ;
!                       return FALSE ;
!               }
!               break;
        default :
+               NCadvise(NC_EBADTYPE, "xdr_NCvdata") ;
                return(FALSE) ;
        }
+       return(TRUE) ;
  }
  
  
***************
*** 702,708 ****
        if(!xdr_NCvdata(handle->xdrs,
                        offset, vp->type, 
                        (unsigned)*edges, values))
-               /* MEMORY: should xdr_free(xdr_NCvdata, values) be called? */
                return(-1) ;
  
        if(newrecs > 0)
--- 747,752 ----
***************
*** 720,727 ****
                if(handle->flags & NC_NSYNC) /* write out header->numrecs NOW */
                {
                        if(!xdr_numrecs(handle->xdrs, handle) )
-                               /* MEMORY: should xdr_free(xdr_numrecs,
-                                * handle) be called? */
                                return(-1) ;
                        handle->flags &= ~NC_NDIRTY ;
                }
--- 764,769 ----
***************
*** 772,785 ****
                return(
                xdr_NCv1data(handle->xdrs, vp->begin, vp->type, values) ?
                0 : -1 ) ;
- #if 0
-               /* MEMORY: should the above be rewritten as the
-                * following to plug a memory leak? */
-               if (xdr_NCv1data(handle->xdrs, vp->begin, vp->type, values))
-                   return 0;
-               xdr_free(xdr_NCv1data, values);
-               return -1;
- #endif
        }
  
        if( !NCcoordck(handle, vp, start) )
--- 814,819 ----
***************
*** 880,887 ****
                                {
                                        Free(coords);
                                        Free(upper);
-                                       /* MEMORY: should xdr_free(xdr_NCvdata,
-                                        * values) be called? */
                                        return(-1) ;
                                }
                                values += iocount * szof ;
--- 914,919 ----
***************
*** 1096,1103 ****
                if(!xdr_NCvdata(handle->xdrs,
                                offset, rvp[ii]->type, 
                                iocount, datap[ii]))
-                       /* MEMORY: should xdr_free(xdr_NCvdata,
-                        * datap[ii]) be called? */
                        return(-1) ;
        }
        return 0 ;
--- 1128,1133 ----
***************
*** 1157,1164 ****
                if(handle->flags & NC_NSYNC) /* write out header->numrecs NOW */
                {
                        if(!xdr_numrecs(handle->xdrs, handle) )
-                               /* MEMORY: should xdr_free(xdr_numrecs,
-                                * handle) be called? */
                                return(FALSE) ;
                        handle->flags &= ~NC_NDIRTY ;
                }
--- 1187,1192 ----