"Fossies" - the Fresh Open Source Software Archive

Member "netcdf-fortran-4.4.5/examples/F77/simple_xy_nc4_rd.f" (31 Jan 2019, 2421 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 77 source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 C     This is part of the netCDF package.
    2 C     Copyright 2006 University Corporation for Atmospheric Research/Unidata.
    3 C     See COPYRIGHT file for conditions of use.
    4       
    5 C     This is a simple example which reads a small dummy array, from a
    6 C     netCDF data file created by the companion program simple_xy_wr.f.
    7       
    8 C     This is intended to illustrate the use of the netCDF fortran 77
    9 C     API. This example program is part of the netCDF tutorial, which can
   10 C     be found at:
   11 C     http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-tutorial
   12       
   13 C     Full documentation of the netCDF Fortran 77 API can be found at:
   14 C     http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-f77
   15 
   16 C     $Id: simple_xy_nc4_rd.f,v 1.1 2007/05/04 13:33:20 ed Exp $
   17 
   18       program simple_xy_rd
   19       implicit none
   20       include 'netcdf.inc'
   21 
   22 C     This is the name of the data file we will read. 
   23       character*(*) FILE_NAME
   24       parameter (FILE_NAME='simple_xy_nc4.nc')
   25 
   26 C     We are reading 2D data, a 12 x 6 grid. 
   27       integer NX, NY
   28       parameter (NX = 60, NY = 120)
   29       integer data_in(NY, NX)
   30 
   31 C     This will be the netCDF ID for the file and data variable.
   32       integer ncid, varid
   33 
   34 C     Loop indexes, and error handling.
   35       integer x, y, retval
   36 
   37 C     Open the file. NF_NOWRITE tells netCDF we want read-only access to
   38 C     the file.
   39       retval = nf_open(FILE_NAME, NF_NOWRITE, ncid)
   40       if (retval .ne. nf_noerr) call handle_err(retval)
   41 
   42 C     Get the varid of the data variable, based on its name.
   43       retval = nf_inq_varid(ncid, 'data', varid)
   44       if (retval .ne. nf_noerr) call handle_err(retval)
   45 
   46 C     Read the data.
   47       retval = nf_get_var_int(ncid, varid, data_in)
   48       if (retval .ne. nf_noerr) call handle_err(retval)
   49 
   50 C     Check the data.
   51       do x = 1, NX
   52          do y = 1, NY
   53             if (data_in(y, x) .ne. (x - 1) * NY + (y - 1)) then
   54                print *, 'data_in(', y, ', ', x, ') = ', data_in(y, x)
   55                stop 2
   56             end if
   57          end do
   58       end do
   59 
   60 C     Close the file, freeing all resources.
   61       retval = nf_close(ncid)
   62       if (retval .ne. nf_noerr) call handle_err(retval)
   63 
   64       print *,'*** SUCCESS reading example file ', FILE_NAME, '!'
   65       end
   66 
   67       subroutine handle_err(errcode)
   68       implicit none
   69       include 'netcdf.inc'
   70       integer errcode
   71 
   72       print *, 'Error: ', nf_strerror(errcode)
   73       stop 2
   74       end