[netcdfgroup] NetCDF: Start+count exceeds dimension bound

I'm doing a program in Fortran 95 to transform simple ascii information
into the netcdf format and when i try to run my program it does an error
in the writing function (nf90_put_var) and says NetCDF: Start+count
exceeds dimension bound.
I've searched a lot, tried to change the order of writing and some other
things, really don't know what more to do.

this is the program:

Program transf_netCDF
use netcdf
Implicit None

 ! This is the name of the data file we will create.
 Character (len = *), parameter :: FILE_NAME = "netCDFyxz.nc"

 ! We are writing 4D data
 integer, parameter :: NDIMS = 3


 ! When we create netCDF files, variables and dimensions, we get back
 ! an ID for each one.
 integer :: ncid, varid, dimids(NDIMS)
 integer :: x_dimid, y_dimid, z_dimid

 !Integer, parameter :: ni=3 , nj=3 , nk=3

 ! This is the data array we will write. It will just be filled with
 ! a progression of integers for this example.
 real(KIND=8) , allocatable:: data_out(:,:,:)


 Integer :: i ,j ,k ,a
 Integer :: ni, nj, nk
 Real :: v
 Character :: vfile3d
 integer:: error


open(50,file="vfile.p",status="old")    !Aqui terá de ser alterado o nome
do ficheiro a ser lido

read(50,*) ni ,nj ,nk


ALLOCATE ( data_out(ni,nj,nk) , stat=error )


  if (error /= 0) then
     print*, "Nao foi possivel alocar o espaço para o array"
     stop
  end if

!data_out = (/ ni, nj, nk /)

!Print*, "ni,nk,nj - numero de pontos nas direcções y (S-N), x (O-E) e Z
(vertical)"
! i->y / k->x / j->z
!read(*,*) ni ,nk ,nj


      do i=1, ni
            do j=1, nj
                  do k=1, nk

                        read(50,*) v

                        data_out(i,j,k)= v

                  end do
            end do
      end do



  ! Create the netCDF file. The nf90_clobber parameter tells netCDF to
  ! overwrite this file, if it already exists.
  a=1
  call check( nf90_create(FILE_NAME, NF90_CLOBBER, ncid) )

  ! Define the dimensions. NetCDF will hand back an ID for each.
  a=2
  call check( nf90_def_dim(ncid, "x", nk, x_dimid) )
  a=3
  call check( nf90_def_dim(ncid, "y", ni, y_dimid) )
  a=4
  call check( nf90_def_dim(ncid, "z", nj, z_dimid) )

  ! The dimids array is used to pass the IDs of the dimensions of
  ! the variables. Note that in fortran arrays are stored in
  ! column-major format.
  dimids =  (/ x_dimid, y_dimid , z_dimid /)

  ! Define the variable. The type of the variable in this case is
  ! NF90_INT (4-byte integer).
  a=5
  call check( nf90_def_var(ncid, "data", NF90_double, dimids, varid) )

  ! End define mode. This tells netCDF we are done defining metadata.
  a=6
  call check( nf90_enddef(ncid) )


  ! Write the pretend data to the file. Although netCDF supports
  ! reading and writing subsets of data, in this case we write all the
  ! data in one operation.
  a=7
  call check( nf90_put_var(ncid, varid, data_out) )

  ! Close the file. This frees up any internal netCDF resources
  ! associated with the file, and flushes any buffers.
  a=8
  call check( nf90_close(ncid) )

  print *, "*** SUCCESS writing example file netCDFyxz.nc! "

deallocate(data_out)

contains
  subroutine check(status)
    integer, intent ( in) :: status

    if(status /= nf90_noerr) then
      print*, a
      print *, trim(nf90_strerror(status))
      stop "Stopped"
    end if
  end subroutine check

end program transf_netCDF


It's based in one example from the netcdf people. The reading file as in
the first line the size of each coordinate and in the rest of the file the
velocities to be written.



Thanks in advance
Ricardo Torres




  • 2009 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: