griddims subroutine¶
Inquire about the coordinates, time, level and variable type of a NetCDF dataset.
How to use¶
-
subroutine
griddims
(ifile, idata)¶ Parameters: - ifile :: dataset file path [character] [1]
- idata :: map structure to be readed. See Structure Fields. [1]
Return: - ndims :: number of dimensions of variable
- nlons :: number of longitudes
- nlats :: number of latitudes
- ntimes :: number of times
[3d and 4d datasets]
- nlevels :: number of levels
[4d datasets]
- lonunits :: longitude units
- latunits :: latitude units
- timeunits :: time units
[3d and 4d datasets]
- levelunits :: level units
[4d datasets]
- vartype :: variable type
- varunits :: variable units
- long_name :: long name
- _FillValue :: fill value
Call : griddims(ifile,idata)
[1] | (1, 2) Defined by user |
[Code example] Read dataset information¶
Get the number of latitudes and longitudes of a file.
program main
use fpl
implicit none
! Source: UNIDATA
! file: test_echam_spectral.nc
!download: http://www.unidata.ucar.edu/software/netcdf/examples/files.html
!Set float datatype 3d dataset with, longitude and latitude and time in double datatype
type(nc3d_float_lld_td) :: spectral
!Input and Output declarations
character(100) :: inputpath, outputpath
inputpath = "database/test_echam_spectral.nc"
outputpath = "database/spectral.nc"
!Set necessary parameters for read the data
spectral%varname = "albedo_nir"
spectral%timename = "time"
spectral%lonname = "lon"
spectral%latname = "lat"
!Call function to read the data (readgrid(input_data_path, defined_data_structure))
call readgrid(inputpath, spectral)
write(*,*) "====== Dataset Information ======="
write(*,*) "=================================="
!Get data information using pointer to structures
write(*,*) "Grid 4d info ================================="
write(*,100) "varname : ", spectral%varname
write(*,100) "timename : ", spectral%timename
write(*,100) "latname : ", spectral%latname
write(*,100) "lonname : ", spectral%lonname
write(*,100) "long_name : ", spectral%long_name
write(*,100) "varunits : ", spectral%varunits
write(*,100) "timeunits : ", spectral%timeunits
write(*,100) "lonunits : ", spectral%lonunits
write(*,100) "latunits : ", spectral%latunits
write(*,102) "nlons : ", spectral%nlons
write(*,102) "nlats : ", spectral%nlats
write(*,102) "ntimes : ", spectral%ntimes
write(*,102) "ndims : ", spectral%ndims
write(*,102) "vartype : ", spectral%vartype
write(*,'(a13,f10.4)') "FillValue : ", spectral%FillValue
100 format(a13,a25)
101 format(a13,3a20)
102 format(a13,i4)
103 format(a13,3i4)
!Write the data on file
call writegrid(outputpath, spectral)
end program main
#RedHat based systems
gfortran -o griddims.out griddims.f90 -I/usr/lib64/gfortran/modules/ -lFPL
#Debian based systems
gfortran -o griddims.out griddims.f90 -I/usr/include/ -lFPL
Important
-I<dir>
This option specifies where to put .mod files for compiled modules. It is also added to the list of directories to Influencing the linking step. See the GNU Fortran Compiler Documentation .
<dir>
is defined in Makefile as $(FPL_moddir)
. See Build Library.
After compilation run the program ./griddims.out