module_netcdf_nc_data.F90
Module netcdf_nc_data
! Data types and flags for Fortran2003 interfaces to NetCDF C routines
!
! Written by: Richard Weed, Ph.D.
! Center for Advanced Vehicular Systems
! Mississippi State University
! rweed@cavs.msstate.edu
! License (and other Lawyer Language)
! This software is released under the Apache 2.0 Open Source License. The
! full text of the License can be viewed at :
!
! http:www.apache.org/licenses/LICENSE-2.0.html
!
! The author grants to the University Corporation for Atmospheric Research
! (UCAR), Boulder, CO, USA the right to revise and extend the software
! without restriction. However, the author retains all copyrights and
! intellectual property rights explicitly stated in or implied by the
! Apache license
! Version 1.: Sept. 2005 - Initial Cray X1 version
! Version 2.: May 2006 - Updated to support g95
! Version 3.: June 2006 - Updated to include netCDF 4 functions
! Version 4.: July 2007 - Modified to work with 3.6.2 build system
! Version 5.: April 2009 - Updated to NetCDF 4.0.1
! Version 6.: April 2010 - Updated to NetCDF 4.1.1
! Version 7.: Feb. 2012 - Added support for F2008 Intrinsic kinds
! Version 8.: Feb. 2013 - Updated for netcdf fortran-4.4
! Version 9.: April 2014 - Changed C_PTRDIFF_T to UCAR definitions
USE iso_c_binding ! All subsequent USE associations of netcdf_nc_data
! will inherit ISO_C_BINDING data
! The following will allow us to use the Fortran 2008 default intrinsic
! kind variables contained in Fortran 2008 ISO_FORTRAN_ENV module when
! compilers support it. Actually most of the major compilers (and even
! the latest gfortran) support these now (Feb. 2012)
#ifdef HAVE_F2008
USE iso_fortran_env, ONLY: real32, real64, int8, int16, int32, int64
#endif
Implicit NONE
#include "nfconfig.inc"
#ifndef HAVE_F2008
! Create our own REAL32, REAL64, INT8, INT16, INT32, INT64 if we don't have F2008
! ISO_FORTRAN_ENV module
Integer, Parameter, PRIVATE :: real32 = selected_real_kind(p=6, r=37) ! float
Integer, Parameter, PRIVATE :: real64 = selected_real_kind(p=13, r=307) ! double
Integer, Parameter, PRIVATE :: int8 = selected_int_kind( 2)
Integer, Parameter, PRIVATE :: int16 = selected_int_kind( 4)
Integer, Parameter, PRIVATE :: int32 = selected_int_kind( 9) ! int
Integer, Parameter, PRIVATE :: int64 = selected_int_kind(18) ! long long
#endif
! Set KIND parameters to shorter names used in f03 interface routines etc.
Integer, Parameter :: rk4 = real32
Integer, Parameter :: rk8 = real64
Integer, Parameter :: ik1 = int8
Integer, Parameter :: ik2 = int16
Integer, Parameter :: ik4 = int32
Integer, Parameter :: ik8 = int64
! Define processor/compiler dependent parameters for ptrdiff_t, signed char,
! and short types. Note prtdiff_t was not defined in the FORTRAN 2003
! standard as an interoperable type in ISO_C_BINDING but was added as part of
! the recent TS29113 Technical Specification "Futher Interoperability with C"
! passed in 2012. For now we will make our own using C_INT32_T or C_INT64_T
! but allow users to use the default definition for compilers that support
! TS29113 (like gfortran 4.8). Default will be C_INTPTR_T
#ifndef HAVE_TS29113_SUPPORT
#if (SIZEOF_PTRDIFF_T == 4)
Integer, Parameter :: c_ptrdiff_t = c_int32_t
#elif (SIZEOF_PTRDIFF_T == 8)
Integer, Parameter :: c_ptrdiff_t = c_int64_t
#else
Integer, Parameter :: c_ptrdiff_t = c_intptr_t
#endif
#endif
! Set KIND parameters for 1 and 2 byte integers if the system
! supports them based on what is set by configure in nfconfig.inc.
! The routines that use these values will issue an EBADTYPE error
! and exit if C_SIGNED_CHAR and C_SHORT are not supported in
! ISO_C_BINDING
! Set the KINDs to default integers otherwise.
! INT1 KINDs
#ifdef NF_INT1_IS_C_SIGNED_CHAR
Integer, Parameter :: cint1 = c_signed_char
Integer, Parameter :: nfint1 = ik1
#elif NF_INT1_IS_C_SHORT
Integer, Parameter :: cint1 = c_short
Integer, Parameter :: nfint1 = ik2
#elif NF_INT1_IS_C_INT
Integer, Parameter :: cint1 = c_int
Integer, Parameter :: nfint1 = ik4
#elif NF_INT1_IS_C_LONG
Integer, Parameter :: cint1 = c_long
Integer, Parameter :: nfint1 = ik8
#else
Integer, Parameter :: cint1 = c_signed_char
Integer, Parameter :: nfint1 = ik1
#endif
! INT2 KINDs
#ifdef NF_INT2_IS_C_SHORT
Integer, Parameter :: cint2 = c_short
Integer, Parameter :: nfint2 = ik2
#elif NF_INT2_IS_C_INT
Integer, Parameter :: cint2 = c_int
Integer, Parameter :: nfint2 = ik4
#elif NF_INT2_IS_C_LONG
Integer, Parameter :: cint2 = c_long
Integer, Parameter :: nfint2 = ik8
#else
Integer, Parameter :: cint2 = c_short
Integer, Parameter :: nfint2 = ik2
#endif
! Set Fortran default integer kind. This
! should take care of the case were default
! integer is a 64 bit int (ala prehistoric
! CRAYS)
#ifdef NF_INT_IS_C_LONG
Integer, Parameter :: cint = c_long
Integer, Parameter :: nfint = ik8
#else
Integer, Parameter :: cint = c_int
Integer, Parameter :: nfint = ik4
#endif
! Set Fortran default real kind. This should
! take care of the case were the default real
! type is a 64 bit real (ala prehistoric CRAYs)
#ifdef NF_REAL_IS_C_DOUBLE
Integer, Parameter :: nfreal = rk8
#else
Integer, Parameter :: nfreal = rk4
#endif
!--------- Define default C interface parameters from netcdf.h ---------------
! This is not a complete impementation of the C header files but
! defines NC_ values equivalent to the values in the netcdf.inc files
! excludeing the V2 values
! NETCDF3 data
!
! Define enumerator nc_type data as integers
Integer(KIND=C_INT), Parameter :: nc_nat = 0
Integer(KIND=C_INT), Parameter :: nc_byte = 1
Integer(KIND=C_INT), Parameter :: nc_char = 2
Integer(KIND=C_INT), Parameter :: nc_short = 3
Integer(KIND=C_INT), Parameter :: nc_int = 4
Integer(KIND=C_INT), Parameter :: nc_float = 5
Integer(KIND=C_INT), Parameter :: nc_double = 6
! Default fill values
Character(KIND=C_CHAR), Parameter :: nc_fill_char = c_null_char
Integer(KIND=C_SIGNED_CHAR), Parameter :: nc_fill_byte = -127_c_signed_char
Integer(KIND=C_SHORT), Parameter :: nc_fill_short = -32767_c_short
Integer(KIND=C_INT), Parameter :: nc_fill_int = -2147483647_c_int
Real(KIND=C_FLOAT), Parameter :: nc_fill_float = 9.9692099683868690e+36
Real(KIND=C_DOUBLE), Parameter :: nc_fill_double = 9.9692099683868690d+36
! Mode flags for opening and creating datasets
Integer(KIND=C_INT), Parameter :: nc_nowrite = 0
Integer(KIND=C_INT), Parameter :: nc_write = 1
Integer(KIND=C_INT), Parameter :: nc_clobber = 0
Integer(KIND=C_INT), Parameter :: nc_noclobber = 4
Integer(KIND=C_INT), Parameter :: nc_fill = 0
Integer(KIND=C_INT), Parameter :: nc_nofill = 256
Integer(KIND=C_INT), Parameter :: nc_lock = 1024
Integer(KIND=C_INT), Parameter :: nc_share = 2048
Integer(KIND=C_INT), Parameter :: nc_strict_nc3 = 8
Integer(KIND=C_INT), Parameter :: nc_64bit_offset = 512
Integer(KIND=C_INT), Parameter :: nc_sizehint_default = 0
Integer(KIND=C_INT), Parameter :: nc_align_chunk = -1
Integer(KIND=C_INT), Parameter :: nc_format_classic = 1
Integer(KIND=C_INT), Parameter :: nc_format_64bit = 2
Integer(KIND=C_INT), Parameter :: nc_diskless = 8
Integer(KIND=C_INT), Parameter :: nc_mmap = 16
! Unlimited dimension size argument and global attibute ID
Integer(KIND=C_INT), Parameter :: nc_unlimited = 0
Integer(KIND=C_INT), Parameter :: nc_global = 0
! Implementation limits (WARNING! SHOULD BE THE SAME AS C INTERFACE)
Integer(KIND=C_INT), Parameter :: nc_max_dims = 1024
Integer(KIND=C_INT), Parameter :: nc_max_attrs = 8192
Integer(KIND=C_INT), Parameter :: nc_max_vars = 8192
Integer(KIND=C_INT), Parameter :: nc_max_name = 256
Integer(KIND=C_INT), Parameter :: nc_max_var_dims = nc_max_dims
! Error codes
Integer(KIND=C_INT), Parameter :: nc_noerr = 0
Integer(KIND=C_INT), Parameter :: nc2_err = -1
Integer(KIND=C_INT), Parameter :: nc_syserr = -31
Integer(KIND=C_INT), Parameter :: nc_exdr = -32
Integer(KIND=C_INT), Parameter :: nc_ebadid = -33
Integer(KIND=C_INT), Parameter :: nc_ebfile = -34
Integer(KIND=C_INT), Parameter :: nc_eexist = -35
Integer(KIND=C_INT), Parameter :: nc_einval = -36
Integer(KIND=C_INT), Parameter :: nc_eperm = -37
Integer(KIND=C_INT), Parameter :: nc_enotindefine = -38
Integer(KIND=C_INT), Parameter :: nc_eindefine = -39
Integer(KIND=C_INT), Parameter :: nc_einvalcoords = -40
Integer(KIND=C_INT), Parameter :: nc_emaxdims = -41
Integer(KIND=C_INT), Parameter :: nc_enameinuse = -42
Integer(KIND=C_INT), Parameter :: nc_enotatt = -43
Integer(KIND=C_INT), Parameter :: nc_emaxatts = -44
Integer(KIND=C_INT), Parameter :: nc_ebadtype = -45
Integer(KIND=C_INT), Parameter :: nc_ebaddim = -46
Integer(KIND=C_INT), Parameter :: nc_eunlimpos = -47
Integer(KIND=C_INT), Parameter :: nc_emaxvars = -48
Integer(KIND=C_INT), Parameter :: nc_enotvar = -49
Integer(KIND=C_INT), Parameter :: nc_eglobal = -50
Integer(KIND=C_INT), Parameter :: nc_enotnc = -51
Integer(KIND=C_INT), Parameter :: nc_ests = -52
Integer(KIND=C_INT), Parameter :: nc_emaxname = -53
Integer(KIND=C_INT), Parameter :: nc_eunlimit = -54
Integer(KIND=C_INT), Parameter :: nc_enorecvars = -55
Integer(KIND=C_INT), Parameter :: nc_echar = -56
Integer(KIND=C_INT), Parameter :: nc_eedge = -57
Integer(KIND=C_INT), Parameter :: nc_estride = -58
Integer(KIND=C_INT), Parameter :: nc_ebadname = -59
Integer(KIND=C_INT), Parameter :: nc_erange = -60
Integer(KIND=C_INT), Parameter :: nc_enomem = -61
Integer(KIND=C_INT), Parameter :: nc_evarsize = -62
Integer(KIND=C_INT), Parameter :: nc_edimsize = -63
Integer(KIND=C_INT), Parameter :: nc_etrunc = -64
! Error handling codes
Integer(KIND=C_INT), Parameter :: nc_fatal = 1
Integer(KIND=C_INT), Parameter :: nc_verbose = 2
#ifdef USE_NETCDF4
! NETCDF4 data
Integer(KIND=C_INT), Parameter :: nc_format_netcdf4 = 3
Integer(KIND=C_INT), Parameter :: nc_format_netcdf4_classic = 4
Integer(KIND=C_INT), Parameter :: nc_netcdf4 = 4096
Integer(KIND=C_INT), Parameter :: nc_classic_model = 256
! extra netcdf4 types
Integer(KIND=C_INT), Parameter :: nc_long = nc_int
Integer(KIND=C_INT), Parameter :: nc_ubyte = 7
Integer(KIND=C_INT), Parameter :: nc_ushort = 8
Integer(KIND=C_INT), Parameter :: nc_uint = 9
Integer(KIND=C_INT), Parameter :: nc_int64 = 10
Integer(KIND=C_INT), Parameter :: nc_uint64 = 11
Integer(KIND=C_INT), Parameter :: nc_string = 12
Integer(KIND=C_INT), Parameter :: nc_vlen = 13
Integer(KIND=C_INT), Parameter :: nc_opaque = 14
Integer(KIND=C_INT), Parameter :: nc_enum = 15
Integer(KIND=C_INT), Parameter :: nc_compound = 16
!extra netcd4 fill values
Integer(KIND=C_INT), Parameter :: nc_fill_ubyte = 255
Integer(KIND=C_INT), Parameter :: nc_fill_ushort = 65535
Integer(KIND=C_LONG_LONG), Parameter :: nc_fill_uint = 4294967295_c_long_long
Integer(KIND=C_LONG_LONG), Parameter :: nc_fill_int64 = -9223372036854775806_c_long_long
! extra netcdf4 variable flags
Integer(KIND=C_INT), Parameter :: nc_chunk_seq = 0
Integer(KIND=C_INT), Parameter :: nc_chunk_sub = 1
Integer(KIND=C_INT), Parameter :: nc_chunk_sizes = 2
Integer(KIND=C_INT), Parameter :: nc_endian_native = 0
Integer(KIND=C_INT), Parameter :: nc_endian_little = 1
Integer(KIND=C_INT), Parameter :: nc_endian_big = 2
Integer(KIND=C_INT), Parameter :: nc_chunked = 0
Integer(KIND=C_INT), Parameter :: nc_notcontiguous = 0
Integer(KIND=C_INT), Parameter :: nc_contiguous = 1
Integer(KIND=C_INT), Parameter :: nc_nochecksum = 0
Integer(KIND=C_INT), Parameter :: nc_fletcher32 = 1
Integer(KIND=C_INT), Parameter :: nc_noshuffle = 0
Integer(KIND=C_INT), Parameter :: nc_shuffle = 1
Integer(KIND=C_INT), Parameter :: nc_independent = 0
Integer(KIND=C_INT), Parameter :: nc_collective = 1
! flags for parallel i/o
Integer(KIND=C_INT), Parameter :: nc_mpiio = 8192
Integer(KIND=C_INT), Parameter :: nc_mpiposix = 16384
Integer(KIND=C_INT), Parameter :: nc_pnetcdf = 32768
Integer(KIND=C_INT), Parameter :: nc_szip_ec_option_mask = 4
Integer(KIND=C_INT), Parameter :: nc_szip_nn_option_mask = 32
! extra netcdf4 error flags
Integer(KIND=C_INT), Parameter :: nc_ehdferr = -101
Integer(KIND=C_INT), Parameter :: nc_ecantread = -102
Integer(KIND=C_INT), Parameter :: nc_ecantwrite = -103
Integer(KIND=C_INT), Parameter :: nc_ecantcreate = -104
Integer(KIND=C_INT), Parameter :: nc_efilemeta = -105
Integer(KIND=C_INT), Parameter :: nc_edimmeta = -106
Integer(KIND=C_INT), Parameter :: nc_eattmeta = -107
Integer(KIND=C_INT), Parameter :: nc_evarmeta = -108
Integer(KIND=C_INT), Parameter :: nc_enocompound = -109
Integer(KIND=C_INT), Parameter :: nc_eattexists = -110
Integer(KIND=C_INT), Parameter :: nc_enotnc4 = -111
Integer(KIND=C_INT), Parameter :: nc_estrictnc3 = -112
Integer(KIND=C_INT), Parameter :: nc_enotnc3 = -113
Integer(KIND=C_INT), Parameter :: nc_enopar = -114
Integer(KIND=C_INT), Parameter :: nc_eparinit = -115
Integer(KIND=C_INT), Parameter :: nc_ebadgrpid = -116
Integer(KIND=C_INT), Parameter :: nc_ebadtypid = -117
Integer(KIND=C_INT), Parameter :: nc_etypdefined = -118
Integer(KIND=C_INT), Parameter :: nc_ebadfield = -119
Integer(KIND=C_INT), Parameter :: nc_ebadclass = -120
Integer(KIND=C_INT), Parameter :: nc_emaptype = -121
Integer(KIND=C_INT), Parameter :: nc_elatefill = -122
Integer(KIND=C_INT), Parameter :: nc_elatedef = -123
Integer(KIND=C_INT), Parameter :: nc_edimscale = -124
Integer(KIND=C_INT), Parameter :: nc_enogrp = -125
#endif
!------------------------------------------------------------------------------
End Module netcdf_nc_data

Return to the Main Unidata NetCDF page.