[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
20040913: netCDF Access Violation error in Fortran
- Subject: 20040913: netCDF Access Violation error in Fortran
- Date: Mon, 13 Sep 2004 16:54:46 -0600
Elizabeth,
> To: address@hidden
> From: Elizabeth North <address@hidden>
> Subject: Access Violation error in Fortran
> Organization: University of Maryland
> Keywords: 200409121151.i8CBpInJ007499 netCDF Fortran
The above message contained the following:
> I am trying to access a portion of an array from a large .nc file. When
> the program gets to the line with STATUS = NF_GET_VARA_REAL it aborts
> (before it assigns a STATUS error message). Compac Visual Fortran
> debugger has the error message "Access Violation". I thought the file
> could be corrupt, but I can read in the entire array without a problem.
> It just happens when I use the NF_GET_VARA_REAL statement. I've pasted
> the relevant code below. If you have any advice on what I can do to avoid
> the error, I'd really appreciate it!
Off the top of my head, there are several posibilities:
1. The start-vector (startb) is incorrect. Does the following
statement
startb=1
assign 1 to every element of startb?
2. The count-vector (rendb) is incorrect.
3. The receiving array (U) is too small. It's 3-D. Does it need
to be 4?
Basically, there's got to be a mismatch between the amount of the array
you're trying to read and the space available in which to put the
values.
Information on the Fortran-77 start- and count-vectors can be found at
http://my.unidata.ucar.edu/content/software/netcdf/guidef/
> Regards,
> Elizabeth North
> Assistant Research Scientist (soon to be Assistant Professor)
> University of Maryland
> Center for Environmental Science
> Horn Point Laboratory
> 2020 Horns Point Road
> Cambridge, MD 21613 USA
> phone: (410) 221-8497
> fax: (410) 221-8490
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> program main
> include 'netcdf.inc'
> REAL U(81,122,20),Uvelb(81,122,20),Uvelc(81,122,20),
> 1 Uvelf(81,122,20),hc,days,seconds,daytime
> integer time,dt,iint,counter,counter2,counter3,
> 1 stepf,stepc,stepb,stepT,timem,prcount,iprint,printdt,
> 2 imu,jmu,kmu,
> 4 startb(4),rendb(4),startc(4),rendc(4),startf(4),rendf(4)
> CHARACTER prefix*5,suffix*3,buffer*30,filenm*15
> integer NCID,STATUS,NVARS,dimcount(4),dimids(4),ndims,idv_u
> . . .
> c Open netCDF file
> counter=iint+180
> prefix='kklw_'
> suffix='.nc'
> WRITE(buffer,'(A,I3,A)') prefix,counter,suffix
> READ(buffer,'(A)') filenm
> write(*,*) filenm
> c
> STATUS = NF_OPEN(filenm, NF_NOWRITE, NCID)
> if (STATUS .NE. NF_NOERR) write(*,*) 'Problem NF_OPEN'
> write(*,*) 'ncid = ', ncid
>
> c **** U velocity
> STATUS = NF_INQ_VARID(NCID,'u',idv_u)
> write(*,*) 'u varID =', idv_u
> STATUS = NF_INQ_VARNDIMS(NCID,idv_u,ndims)
> status = NF_INQ_VARDIMID(NCID,idv_u,dimids)
> write(*,*) ' ndims =',ndims
> write(*,*) ' dimids =',dimids
> do i=1,ndims
> STATUS = NF_INQ_DIMLEN(NCID,dimids(i),dimcount(i))
> !write(*,*) 'u dim ',i,' = ',dimcount(i)
> enddo
> imu= dimcount(1)
> jmu= dimcount(2)
> kmu= dimcount(3)
> timem= dimcount(4)
> write(*,*) ' u- imu,jmu,kmu,timem = ',imu,jmu,kmu,timem
> rendb(1) = imu
> rendb(2) = jmu
> rendb(3) = kmu
> rendb(4) = stepb
> startb=1
> U=0.0
> write(*,*) ' rendb',rendb(1),rendb(2),rendb(3),rendb(4)
> write(*,*) ' startb',startb(1),startb(2),startb(3),startb(4)
> STATUS = NF_GET_VARA_REAL(NCID,idv_u,startb,rendb,U)
> if (STATUS .NE. NF_NOERR) write(*,*) 'Problem read array'
> do 40 kk = 1,kmu
> do 41 jj = 1,jmu
> do 42 ii = 1,imu
> Uvelb(ii,jj,kk) = U(ii,jj,kk)
> 42 continue
> 41 continue
> 40 continue
Regards,
Steve Emmerson
> NOTE: All email exchanges with Unidata User Support are recorded in the
> Unidata inquiry tracking system and then made publicly available
> through the web. If you do not want to have your interactions made
> available in this way, you must let us know in each email you send to us.