readgrid3d (3-dimensional Dataset)

readgrid3d _ [vdt] _ll [cdt] _t [tdt] subroutine is used to read and alloc a 3-dimensional NetCDF dataset into a datatype structure. Combinations can be made for the statements of this subroutine by replacing [vdt] by one of the data types defined in the FPL library ([byte, short, int, float, double]), [cdt] by a defined suffix for the data type of the coordinates f for float and d for double and [tdt] by a defined suffix for the datatype of time (i for integer, f for float and d for double).

readgrid3d _ [vdt] _ll [cdt] _t [tdt] (ifile, idata)

Type naming:
[vdt]:variable datatype [byte, short, int, float or double]
[cdt]:coordinates datatype(float f, double d).
[tdt]:time datatype [byte, short, int, float or double]
Subroutine Parameters:
 
ifile:file path [character]
idata:3d dataset structure. See Structure Fields.
Local parameters:
 
ncid:map ID [integer]
varid:variable ID [integer]
i:auxiliary variable [integer]
Return:
idata:map structure with readed fields. See Structure Fields.
times:array of map times [integer, float or double]
longitudes:array of longitudes [float or double]
latitudes:array of latitudes [float or double]

Example:

Read a 3-dimensional NetCDF dataset with variable declared as byte, coordinates declared as double and time declared as integer (readgrid3d _ byte _ll d _t i).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
subroutine readgrid3d_byte_lld_ti(ifile, idata)
  character(*), intent(in) :: ifile
  type(nc3d_byte_lld_ti) :: idata

  integer(kind=intgr) :: ncid, varid, i

  call griddims(ifile, idata)

  allocate(idata%times(idata%ntimes))
  allocate(idata%longitudes(idata%nlons))
  allocate(idata%latitudes(idata%nlats))

  allocate(idata%ncdata(idata%dimsize(idata%dims(1)), idata%dimsize(idata%dims(2)), &
           idata%dimsize(idata%dims(3))))

  !Open NetCDF
  call check(nf90_open(ifile, nf90_nowrite, ncid))

  do i = 1, idata%ndims
    if(idata%dimname(i).eq."longitude".or.idata%dimname(i).eq."lon")then
      call check(nf90_get_var(ncid, idata%varids(i), idata%longitudes))
      idata%lonunits = idata%dimunits(i)
    end if

    if(idata%dimname(i).eq."latitude".or.idata%dimname(i).eq."lat") then
      call check(nf90_get_var(ncid, idata%varids(i), idata%latitudes))
      idata%latunits = idata%dimunits(i)
    end if

    if(idata%dimname(i).eq."time") then
      call check(nf90_get_var(ncid, idata%varids(i), idata%times))
      idata%timeunits = idata%dimunits(i)
    end if
  end do

  !Get Variable name
  call check(nf90_inq_varid(ncid, idata%varname, varid), idata%varname, ifile)
  call check(nf90_get_var(ncid, varid, idata%ncdata), idata%vartype,"BYTE", ifile)

  call check(nf90_close(ncid))
end subroutine readgrid3d_byte_lld_ti