"Fossies" - the Fresh Open Source Software Archive

Member "netcdf-fortran-4.4.5/examples/F90/simple_xy_nc4_rd.f90" (31 Jan 2019, 3144 Bytes) of package /linux/misc/netcdf-fortran-4.4.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Fortran 90 source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 ! This is part of the netCDF package.
    2 ! Copyright 2006 University Corporation for Atmospheric Research/Unidata.
    3 ! See COPYRIGHT file for conditions of use.
    4       
    5 ! This is a simple example which reads a small dummy array, from a
    6 ! netCDF data file created by the companion program simple_xy_wr.f90.
    7       
    8 ! This is intended to illustrate the use of the netCDF fortran 77
    9 ! API. This example program is part of the netCDF tutorial, which can
   10 ! be found at:
   11 ! http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial
   12       
   13 ! Full documentation of the netCDF Fortran 90 API can be found at:
   14 ! http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f90
   15 
   16 ! $Id: simple_xy_nc4_rd.f90,v 1.3 2009/02/25 12:23:45 ed Exp $
   17 
   18 program simple_xy_rd
   19   use netcdf
   20   implicit none
   21 
   22   ! This is the name of the data file and variable.
   23   character (len = *), parameter :: FILE_NAME = "simple_xy_nc4.nc"
   24   character (len = *), parameter :: VAR_NAME = "data"
   25 
   26   ! We are reading 2D data, a 12 x 6 grid. 
   27   integer, parameter :: NX = 6, NY = 12, MAX_DIMS = 2
   28   integer :: data_in(NY, NX)
   29 
   30   ! This will be the netCDF ID for the file and data variable.
   31   integer :: ncid, varid
   32 
   33   ! Information we will read about the variable.
   34   character (len = nf90_max_name) :: name
   35   integer :: xtype, ndims, dimids(MAX_DIMS), natts
   36   integer :: chunksizes(MAX_DIMS), deflate_level, endianness
   37   logical :: contiguous, shuffle, fletcher32
   38 
   39   ! Loop indexes, and error handling.
   40   integer :: x, y
   41 
   42   ! Open the file. NF90_NOWRITE tells netCDF we want read-only access
   43   ! to the file.
   44   call check( nf90_open(FILE_NAME, NF90_NOWRITE, ncid) )
   45 
   46   ! Get the varid of the data variable, based on its name.
   47   call check( nf90_inq_varid(ncid, VAR_NAME, varid) )
   48 
   49   ! Learn about the variable. This uses all optional parameters.
   50   call check( nf90_inquire_variable(ncid, varid, name, xtype, ndims, &
   51        dimids, natts, contiguous = contiguous, chunksizes = chunksizes, &
   52        deflate_level = deflate_level, shuffle = shuffle, &
   53        fletcher32 = fletcher32, endianness = endianness) )
   54 
   55   ! Make sure we got the correct answers. These depend on what was set
   56   ! when creating the file in simple_xy_nc4_wr.f90. Endianness will be
   57   ! whatever is native for the machine that's building this example.
   58   if (name .ne. VAR_NAME .or. xtype .ne. NF90_INT .or. ndims .ne. 2 .or. &
   59        natts .ne. 0 .or. contiguous .or. .not. shuffle .or. &
   60        deflate_level .ne. 1 .or. fletcher32) stop 3
   61 
   62   ! Read the data.
   63   call check( nf90_get_var(ncid, varid, data_in) )
   64 
   65   ! Check the data.
   66   do x = 1, NX
   67      do y = 1, NY
   68         if (data_in(y, x) /= (x - 1) * NY + (y - 1)) then
   69            print *, "data_in(", y, ", ", x, ") = ", data_in(y, x)
   70            stop "Stopped"
   71         end if
   72      end do
   73   end do
   74 
   75   ! Close the file, freeing all resources.
   76   call check( nf90_close(ncid) )
   77 
   78   print *,"*** SUCCESS reading example file ", FILE_NAME, "! "
   79 
   80 contains
   81   subroutine check(status)
   82     integer, intent ( in) :: status
   83     
   84     if(status /= nf90_noerr) then 
   85       print *, trim(nf90_strerror(status))
   86       stop 2
   87     end if
   88   end subroutine check  
   89 end program simple_xy_rd