Search the data

Fortran routine for use with sea level data

This is a Fortran template file designed to read the given netCDF file into memory.

c-----------------------------------------------------------------------
c
c  readnet.f                      
c  This file is a fortran template file designed to read the given
c  netCDF file into memory.
c
c  History:
c  Date       Name          Action
c  ---------  ------------  --------------------------------------------
c  ?? ??? ??  cids          Created.
c
c-----------------------------------------------------------------------

c     Do not forget to include the -I path_to_netcdf_includes in your
c     compile statement
c     Required includes.
      include 'netcdf.inc'

c     Define Variables.
c     Variable ids run sequentially from 1 to nvars =   07
      parameter      (nvars =    7)          ! number of variables
      parameter      (nrec=  8760)         ! change this 'to generalize
      parameter      (ndims =    2)          ! number of dimensions
      parameter      (primary_dimension =   8760)
      parameter      (position_dimension =      1)
      integer*4      rcode                   ! error code
      integer*4     recdim                    ! record dimension
      real*4         sea_level(nrec)
      character*1    sea_level_quality_flag(nrec)
      real*4         woce_time_of_day(nrec)
      character*1    woce_time_of_day_quality_flag(nrec)
      real*8         woce_date(nrec)
      real*4                     latitude(position_dimension            
     +                                                                   
     +                               )
      real*4                    longitude(position_dimension            
     +                                                                   
     +                               )
      integer*4      start(ndims)            ! hyperslab starting index
      integer*4      count(ndims)            ! hyperslab count from start
      integer        vdims(ndims)            ! max # of var dims
      character*1024 strbuf                  ! string buffer for var
                                             !  and attr names

c     Open netCDF file.
      ncid=ncopn('b0033379.cdf',ncnowrit,rcode)

c     Get info on the record dimension for this file.
      call ncinq(ncid,ndims,nvars,ngatts,recdim,rcode)
      call ncdinq(ncid,recdim,strbuf,nrecs,rcode)
c     nrecs now contains the # of records for this file

c     Retrieve data for sea_level variable.
      call ncvinq(ncid,   1,strbuf,nctype,nvdim,vdims,nvatts,rcode)
      lenstr=1
      do j=1,nvdim
         call ncdinq(ncid,vdims(j),strbuf,ndsize,rcode)
         lenstr=lenstr*ndsize
         start(j)=1
         count(j)=ndsize
      end do
      call ncvgt(ncid,   1,start,count,sea_level,rcode)

c     Retrieve data for sea_level_quality_flag variable.
      call ncvinq(ncid,   2,strbuf,nctype,nvdim,vdims,nvatts,rcode)
      lenstr=1
      do j=1,nvdim
         call ncdinq(ncid,vdims(j),strbuf,ndsize,rcode)
         lenstr=lenstr*ndsize
         start(j)=1
         count(j)=ndsize
      end do
      call ncvgtc(ncid,   2,start,count,sea_level_quality_flag,lenstr,rc
     +ode)

c     Retrieve data for woce_time_of_day variable.
      call ncvinq(ncid,   3,strbuf,nctype,nvdim,vdims,nvatts,rcode)
      lenstr=1
      do j=1,nvdim
         call ncdinq(ncid,vdims(j),strbuf,ndsize,rcode)
         lenstr=lenstr*ndsize
         start(j)=1
         count(j)=ndsize
      end do
      call ncvgt(ncid,   3,start,count,woce_time_of_day,rcode)

c     Retrieve data for woce_time_of_day_quality_flag variable.
      call ncvinq(ncid,   4,strbuf,nctype,nvdim,vdims,nvatts,rcode)
      lenstr=1
      do j=1,nvdim
         call ncdinq(ncid,vdims(j),strbuf,ndsize,rcode)
         lenstr=lenstr*ndsize
         start(j)=1
         count(j)=ndsize
      end do
      call ncvgtc(ncid,   4,start,count,woce_time_of_day_quality_flag,le
     +nstr,rcode)

c     Retrieve data for woce_date variable.
      call ncvinq(ncid,   5,strbuf,nctype,nvdim,vdims,nvatts,rcode)
      lenstr=1
      do j=1,nvdim
         call ncdinq(ncid,vdims(j),strbuf,ndsize,rcode)
         lenstr=lenstr*ndsize
         start(j)=1
         count(j)=ndsize
      end do
      call ncvgt(ncid,   5,start,count,woce_date,rcode)

c     Retrieve data for latitude variable.
      call ncvinq(ncid,   6,strbuf,nctype,nvdim,vdims,nvatts,rcode)
      lenstr=1
      do j=1,nvdim
         call ncdinq(ncid,vdims(j),strbuf,ndsize,rcode)
         lenstr=lenstr*ndsize
         start(j)=1
         count(j)=ndsize
      end do
      call ncvgt(ncid,   6,start,count,latitude,rcode)

c     Retrieve data for longitude variable.
      call ncvinq(ncid,   7,strbuf,nctype,nvdim,vdims,nvatts,rcode)
      lenstr=1
      do j=1,nvdim
         call ncdinq(ncid,vdims(j),strbuf,ndsize,rcode)
         lenstr=lenstr*ndsize
         start(j)=1
         count(j)=ndsize
      end do
      call ncvgt(ncid,   7,start,count,longitude,rcode)

c     ******************************************

c     Begin writing statements to use the data.

c     ******************************************

c     End Program.
      stop
      end