MODULE netcdf_mod

#ifndef CPP_NO_IO

  USE netcdf
  LOGICAL,PARAMETER :: no_io = .FALSE.

#ifndef CPP_NETCDF4
  INTEGER ::  NF90_NETCDF4
  INTEGER ::  NF90_MPIIO
  INTEGER ::  NF90_CHUNKED
  
  INTEGER,EXTERNAL :: NF90_CREATE_PAR
  INTEGER,EXTERNAL :: NF90_DEF_VAR_CHUNKING 
#endif

#ifdef CPP_NF90_DEF_VAR_CHUNKING
  INTEGER,EXTERNAL :: NF90_DEF_VAR_CHUNKING 
#endif

END MODULE netcdf_mod

#ifndef CPP_NETCDF4
   SUBROUTINE NF90_CREATE_PAR
   END
   
   SUBROUTINE NF90_DEF_VAR_CHUNKING
   END
#endif

#ifdef CPP_NF90_DEF_VAR_CHUNKING
   SUBROUTINE NF90_DEF_VAR_CHUNKING
   END
#endif


#else

  LOGICAL,PARAMETER :: no_io = .TRUE.

  INTEGER ::  NF90_NETCDF4
  INTEGER ::  NF90_MPIIO
  INTEGER ::  NF90_CHUNKED
  
  INTEGER,EXTERNAL :: NF90_CREATE_PAR
  INTEGER,EXTERNAL :: NF90_DEF_VAR_CHUNKING 
  INTEGER,EXTERNAL :: NF90_CREATE
  INTEGER,EXTERNAL :: NF90_DEF_DIM
  INTEGER,EXTERNAL :: NF90_PUT_ATT
  INTEGER,EXTERNAL :: NF90_ENDDEF  
  INTEGER,EXTERNAL :: NF90_CLOSE
  INTEGER,EXTERNAL :: NF90_SYNC
  INTEGER,EXTERNAL :: NF90_OPEN
  INTEGER,EXTERNAL :: NF90_INQ_VARID
  INTEGER,EXTERNAL :: NF90_GET_ATT
  
  INTEGER :: NF90_NOERR
  INTEGER :: NF90_NOWRITE  
  INTEGER :: NF90_CLOBBER
  INTEGER :: NF90_UNLIMITED
  INTEGER :: NF90_DOUBLE
  INTEGER :: NF90_FLOAT
  INTEGER :: NF90_GLOBAL
  
  INTERFACE nf90_put_var
    MODULE PROCEDURE   nf90_put_var_int0, nf90_put_var_int1, nf90_put_var_int2, nf90_put_var_int3,&
                       nf90_put_var_real0, nf90_put_var_real1, nf90_put_var_real2, nf90_put_var_real3
  END INTERFACE nf90_put_var

  INTERFACE nf90_get_var
    MODULE PROCEDURE   nf90_get_var_int0, nf90_get_var_int1, nf90_get_var_int2, nf90_get_var_int3,&
                       nf90_get_var_real0, nf90_get_var_real1, nf90_get_var_real2, nf90_get_var_real3
  END INTERFACE nf90_get_var
  
 CONTAINS

   function nf90_strerror(ncerr)
        integer, intent(in) :: ncerr
        character(len = 80)  :: nf90_strerror
        nf90_strerror = "Option -no_io is activated."
   end function nf90_strerror

   function nf90_inquire_attribute(ncid, varid, name, xtype, len, attnum)
        integer,            intent(in)            :: ncid, varid
        character(len = *), intent(in)            :: name
        integer,            intent(out), optional :: xtype, len, attnum
        integer                                   :: nf90_inquire_attribute
        nf90_inquire_attribute = 0
   end function nf90_inquire_attribute

   function nf90_inquire_dimension(ncid, dimid, name, len)
        integer,                       intent(in)  :: ncid, dimid
        character (len = *), optional, intent(out) :: name
        integer,             optional, intent(out) :: len
        integer                                    :: nf90_inquire_dimension
        nf90_inquire_dimension = 0
   end function nf90_inquire_dimension

   function nf90_inquire_variable(ncid, varid, name, xtype, ndims, dimids, nAtts, &
       contiguous, chunksizes, deflate_level, shuffle, fletcher32, endianness, quantize_mode, nsd)
        integer, intent(in) :: ncid, varid
        character (len = *), optional, intent(out) :: name
        integer, optional, intent(out) :: xtype, ndims
        integer, dimension(:), optional, intent(out) :: dimids
        integer, optional, intent(out) :: nAtts
        logical, optional, intent(out) :: contiguous
        integer, optional, dimension(:), intent(out) :: chunksizes
        integer, optional, intent(out) :: deflate_level
        logical, optional, intent(out) :: shuffle, fletcher32
        integer, optional, intent(out) :: endianness
        integer, optional, intent(in) :: quantize_mode, nsd
        integer :: nf90_inquire_variable
        nf90_inquire_variable = 0
   end function nf90_inquire_variable

   function nf90_def_var(ncid, name, xtype, dimids, varid)
        integer,                         intent( in) :: ncid
        character (len = *),             intent( in) :: name
        integer,                         intent( in) :: xtype
        integer, dimension(:), optional, intent( in) :: dimids
        integer,                         intent(out) :: varid
        integer                                      :: nf90_def_var
        nf90_def_var = 0
    end function nf90_def_var
    
    function nf90_put_var_int0(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( in) :: values
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_int0
        nf90_put_var_int0 = 0
    end function nf90_put_var_int0

    function nf90_put_var_int1(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( in) :: values(:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_int1
        nf90_put_var_int1 = 0
    end function nf90_put_var_int1

    function nf90_put_var_int2(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( in) :: values(:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_int2
        nf90_put_var_int2 = 0
    end function nf90_put_var_int2

    function nf90_put_var_int3(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( in) :: values(:,:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_int3
        nf90_put_var_int3 = 0
    end function nf90_put_var_int3
    
    function nf90_put_var_real0(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( in) :: values
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_real0
        nf90_put_var_real0 = 0
   end function nf90_put_var_real0

    function nf90_put_var_real1(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( in) :: values(:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_real1
        nf90_put_var_real1 = 0
   end function nf90_put_var_real1

    function nf90_put_var_real2(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( in) :: values(:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_real2
        nf90_put_var_real2 = 0
   end function nf90_put_var_real2

    function nf90_put_var_real3(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( in) :: values(:,:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_put_var_real3
        nf90_put_var_real3 = 0
   end function nf90_put_var_real3
 
 
     function nf90_get_var_int0(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( out) :: values
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_int0
        nf90_get_var_int0 = 0
    end function nf90_get_var_int0

    function nf90_get_var_int1(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( out) :: values(:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_int1
        nf90_get_var_int1 = 0
    end function nf90_get_var_int1

    function nf90_get_var_int2(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( out) :: values(:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_int2
        nf90_get_var_int2 = 0
    end function nf90_get_var_int2

    function nf90_get_var_int3(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        integer,                          intent( out) :: values(:,:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_int3
        nf90_get_var_int3 = 0
    end function nf90_get_var_int3
    
    function nf90_get_var_real0(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( out) :: values
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_real0
        nf90_get_var_real0 = 0
   end function nf90_get_var_real0

    function nf90_get_var_real1(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( out) :: values(:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_real1
        nf90_get_var_real1 = 0
   end function nf90_get_var_real1

    function nf90_get_var_real2(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( out) :: values(:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_real2
        nf90_get_var_real2 = 0
   end function nf90_get_var_real2

    function nf90_get_var_real3(ncid, varid, values, start, count, stride, map)
        integer,                         intent( in) :: ncid, varid
        real,                              intent( out) :: values(:,:,:)
        integer, dimension(:), optional, intent( in) :: start, count, stride, map
        integer                                      :: nf90_get_var_real3
        nf90_get_var_real3 = 0
   end function nf90_get_var_real3
  
END MODULE netcdf_mod

  FUNCTION NF90_CREATE_PAR ()
    INTEGER ::  NF90_CREATE_PAR
    NF90_CREATE_PAR = 0
  END
  
 FUNCTION NF90_DEF_VAR_CHUNKING ()
    INTEGER ::  NF90_DEF_VAR_CHUNKING
    NF90_DEF_VAR_CHUNKING = 0
 END
 
 FUNCTION NF90_CREATE()
    INTEGER ::  NF90_CREATE
    NF90_CREATE = 0
 END
 
 FUNCTION  NF90_DEF_DIM ()
    INTEGER ::  NF90_DEF_DIM
    NF90_DEF_DIM = 0
 END
 
 FUNCTION NF90_PUT_ATT ()
    INTEGER ::  NF90_PUT_ATT
    NF90_PUT_ATT = 0
 END
 
 FUNCTION NF90_ENDDEF ()
    INTEGER ::  NF90_ENDDEF
    NF90_ENDDEF = 0
 END
  
 FUNCTION NF90_CLOSE ()
    INTEGER ::  NF90_CLOSE
    NF90_CLOSE = 0
 END
 
 FUNCTION NF90_SYNC ()
    INTEGER ::  NF90_SYNC
    NF90_SYNC = 0
 END
 
 FUNCTION NF90_OPEN ()
    INTEGER ::  NF90_OPEN
    NF90_OPEN = 0
 END
 
 FUNCTION NF90_INQ_VARID ()
    INTEGER ::  NF90_INQ_VARID
    NF90_INQ_VARID = 0
 END
 
 FUNCTION NF90_GET_ATT ()
    INTEGER ::  NF90_GET_ATT
    NF90_GET_ATT = 0
 END

#endif

