Previous: Creating a NetCDF Dataset Next: The 2D Example Dataset CDL Table of contents Frames 2010 Unidata NetCDF Workshop > Introduction to the NetCDF APIs and Example Programs

9.21 Read The Simple XY Example in F90
A Fortran 90 program that reads the simple_xy.nc example dataset.

 

program simple_xy_rd
  use netcdf
  implicit none

  character (len = *), parameter :: FILE_NAME = "simple_xy.nc"
  integer, parameter :: NX = 6, NY = 12
  integer :: data_in(NY, NX)
  integer :: ncid, varid
  integer :: x, y

  call check( nf90_open(FILE_NAME, NF90_NOWRITE, ncid) )
  call check( nf90_inq_varid(ncid, "data", varid) )
  call check( nf90_get_var(ncid, varid, data_in) )

  ! Check the data.
  do x = 1, NX
     do y = 1, NY
        if (data_in(y, x) /= (x - 1) * NY + (y - 1)) then
           print *, "data_in(", y, ", ", x, ") = ", data_in(y, x)
           stop "Stopped"
        end if
     end do
  end do

  call check( nf90_close(ncid) )
  print *,"*** SUCCESS reading example file ", FILE_NAME, "! "

contains
  subroutine check(status)
    integer, intent ( in) :: status
    
    if(status /= nf90_noerr) then 
      print *, trim(nf90_strerror(status))
      stop "Stopped"
    end if
  end subroutine check  
end program simple_xy_rd

 


Previous: Creating a NetCDF Dataset Next: The 2D Example Dataset CDL Table of contents Frames 2010 Unidata NetCDF Workshop > Introduction to the NetCDF APIs and Example Programs