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

960513: xdrposix_putlong() segmentation fault problems



Dar Magnus Weis,

>Date: Mon, 13 May 1996 07:24:05 +0200 
>From: Magnus Weis <address@hidden>
>Organization: . 
>To: Steve Emmerson <address@hidden>
>Subject: 960510: xdrposix_putlong() segmentation fault problems 
>Keywords: 199605091033.AA23012

In the above message you wrote:

> I did some more debugging to solve my segmentation fault problems. As
> far as I understand, all trouble is caused by an incorrect unlimited
> dimension. Here again is some code:
> 
> to define my variables:
> 
>       integer ncid, errno, ncd, ncv
>       integer nc1dv, nc2dv(2), nc3dv(3), nc4dv(4)
>       character buffer*255
> c
>       ncid = nccre('data.cdf', NCCLOB, errno)
> c     
>       buffer = 'sicopolis netCDF - data'
>       call ncaptc(ncid, NCGLOBAL, 'title', NCCHAR, strlen(buffer),
>      <     buffer, errno)
> c
>       ncd = ncddef(ncid, 'IMAX', IMAX+1, errno)
>       ncd = ncddef(ncid, 'JMAX', JMAX+1, errno)
>       ncd = ncddef(ncid, 'KCMAX', KCMAX+1, errno)
>       ncd = ncddef(ncid, 'KTMAX', KTMAX+1, errno)
>       ncd = ncddef(ncid, 'KRMAX', KRMAX+1, errno)
>       ncd = ncddef(ncid, 'RECORD', NCUNLIM, errno)
> c
> c
> c     Definition der Variablen
> c
>       nc1dv = ncdid(ncid, 'RECORD', errno)
>       ncv = ncvdef(ncid, 't', NCDOUBLE, NC1D, nc1dv, errno)
>       buffer = 'year'
>       call ncaptc(ncid, ncv, 'units', NCCHAR, strlen(buffer),
>      <     buffer, errno)
>       buffer = 'Modellzeit'
>       call ncaptc(ncid, ncv, 'long_name', NCCHAR, strlen(buffer),
>      <     buffer, errno)
> c
>       nc2dv(1) = ncdid(ncid, 'IMAX', errno)
>       nc2dv(2) = ncdid(ncid, 'RECORD', errno)
>       ncv = ncvdef(ncid, 'xi', NCDOUBLE, NC2D, nc2dv, errno)
>       buffer = 'm'
>       call ncaptc(ncid, ncv, 'units', NCCHAR, strlen(buffer),
>      <     buffer, errno)
>       buffer = 'Koordinate xi der Gitterpunkte i'
>       call ncaptc(ncid, ncv, 'long_name', NCCHAR, strlen(buffer),
>      <     buffer, errno)
> c
>       call ncendf(ncid, errno)
>       call ncclos(ncid, errno)
> 
> now write some data:
> 
>       character runname*5
> c     
>       integer ncid, errno, ncv
>       integer nc1dv
>       integer nc1cor, nc2cor(2), nc3cor(3), nc4cor(4)
>       integer nc1cnt, nc2cnt(2), nc3cnt(3), nc4cnt(4)
>       integer record
>       character buffer*255
> c     
> #include "sico_grl.common"
> c     
>       ncid = ncopn('data.cdf', NCWRITE, errno)
> c
>       nc1dv = ncdid(ncid, 'RECORD', errno)
>       call ncdinq(ncid, nc1dv, buffer, record, errno)
>       record = record + 1
> c
>       ncv = ncvid(ncid, 't', errno)
>       nc1cor = record
>       call ncvpt1(ncid, ncv, nc1cor, time / YEAR_SEC, errno)
> c
>       ncv = ncvid(ncid, 'xi', errno)
>       nc2cor(1) = 1
>       nc2cor(2) = record
>       nc2cnt(1) = IMAX + 1
>       nc2cnt(2) = nc2cor(2)
>       call ncvpt(ncid, ncv, nc2cor, nc2cnt, xi, errno)
> 
> 
> If I try to write data several time, record counts 1, 2, 4, 8, 16,
> ... instead of 1, 2, 3, 4, ... I think that causes my trouble.
> What's wrong with it ? Writing one or to records seems OK, but not
> more.

I think the problem is the last line:

    call ncvpt(ncid, ncv, nc2cor, nc2cnt, xi, errno)

According to the above code, you're trying to write the following array:

    REAL xi(IMAX+1,record)

into the netCDF dataset beginning at coordinates (1,record).
Unfortunately, the array `xi' doesn't appear to be dimensioned properly
(indeed, it doesn't appear to be an array at all -- merely a scalar
variable).

Also, the `t' variable requires that a DOUBLEPRECISION variable be used
in any NCVPT1 call.  The one you are using appears to be only REAL.

Please let me know if this helps.

--------
Steve Emmerson   <address@hidden>