Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 
Previous: Creating a NetCDF Dataset Next: The 2D Example Dataset CDL Table of contents Frames User guide
2008 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF Example Programs

6.8 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 User guide
2008 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF Example Programs

 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Community Programs   Unidata is a member of the UCAR Community Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690