text:
   function nf90_put_var_OneByteInt(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_put_var_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_put_var_OneByteInt = nf_put_var1_int1(ncid, varid, localIndex, values)
   end function nf90_put_var_OneByteInt

   function nf90_put_var_TwoByteInt(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_put_var_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_put_var_TwoByteInt = nf_put_var1_int2(ncid, varid, localIndex, values)
   end function nf90_put_var_TwoByteInt

   function nf90_put_var_FourByteInt(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_put_var_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_put_var_FourByteInt = nf_put_var1_int(ncid, varid, localIndex, int(values))
   end function nf90_put_var_FourByteInt

   function nf90_put_var_FourByteReal(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_put_var_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_put_var_FourByteReal = nf_put_var1_real(ncid, varid, localIndex, values)
   end function nf90_put_var_FourByteReal

   function nf90_put_var_EightByteReal(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_put_var_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_put_var_EightByteReal = nf_put_var1_double(ncid, varid, localIndex, values)
   end function nf90_put_var_EightByteReal

   function nf90_get_var_OneByteInt(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), intent(out) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_get_var_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_get_var_OneByteInt = nf_get_var1_int1(ncid, varid, localIndex, values)
   end function nf90_get_var_OneByteInt

   function nf90_get_var_TwoByteInt(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), intent(out) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_get_var_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_get_var_TwoByteInt = nf_get_var1_int2(ncid, varid, localIndex, values)
   end function nf90_get_var_TwoByteInt

   function nf90_get_var_FourByteInt(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), intent(out) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_get_var_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localIndex
     integer                               :: defaultInteger

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_get_var_FourByteInt = nf_get_var1_int(ncid, varid, localIndex, defaultInteger)
     values = defaultInteger
   end function nf90_get_var_FourByteInt

   function nf90_get_var_FourByteReal(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), intent(out) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_get_var_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_get_var_FourByteReal = nf_get_var1_real(ncid, varid, localIndex, values)
   end function nf90_get_var_FourByteReal

   function nf90_get_var_EightByteReal(ncid, varid, values, start)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), intent(out) :: values
     integer, dimension(:), optional, intent( in) :: start
     integer                                      :: nf90_get_var_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localIndex

     ! Set local arguments to default values
     localIndex(:) = 1
     if(present(start)) localIndex(:size(start)) = start(:)

     nf90_get_var_EightByteReal = nf_get_var1_double(ncid, varid, localIndex, values)
   end function nf90_get_var_EightByteReal

   function nf90_put_var_1D_OneByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), dimension(:), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_1D_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_1D_OneByteInt = &
          nf_put_varm_int1(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_1D_OneByteInt = &
          nf_put_vars_int1(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_1D_OneByteInt = &
          nf_put_vara_int1(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_1D_OneByteInt

   function nf90_put_var_2D_OneByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), dimension(:, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_2D_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_2D_OneByteInt = &
          nf_put_varm_int1(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_2D_OneByteInt = &
          nf_put_vars_int1(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_2D_OneByteInt = &
          nf_put_vara_int1(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_2D_OneByteInt

   function nf90_put_var_3D_OneByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), dimension(:, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_3D_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_3D_OneByteInt = &
          nf_put_varm_int1(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_3D_OneByteInt = &
          nf_put_vars_int1(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_3D_OneByteInt = &
          nf_put_vara_int1(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_3D_OneByteInt

   function nf90_put_var_4D_OneByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), dimension(:, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_4D_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_4D_OneByteInt = &
          nf_put_varm_int1(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_4D_OneByteInt = &
          nf_put_vars_int1(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_4D_OneByteInt = &
          nf_put_vara_int1(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_4D_OneByteInt

   function nf90_put_var_5D_OneByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), dimension(:, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_5D_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_5D_OneByteInt = &
          nf_put_varm_int1(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_5D_OneByteInt = &
          nf_put_vars_int1(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_5D_OneByteInt = &
          nf_put_vara_int1(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_5D_OneByteInt

   function nf90_put_var_6D_OneByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), dimension(:, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_6D_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_6D_OneByteInt = &
          nf_put_varm_int1(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_6D_OneByteInt = &
          nf_put_vars_int1(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_6D_OneByteInt = &
          nf_put_vara_int1(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_6D_OneByteInt

   function nf90_put_var_7D_OneByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = OneByteInt), dimension(:, :, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_7D_OneByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_7D_OneByteInt = &
          nf_put_varm_int1(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_7D_OneByteInt = &
          nf_put_vars_int1(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_7D_OneByteInt = &
          nf_put_vara_int1(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_7D_OneByteInt

   function nf90_put_var_1D_TwoByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), dimension(:), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_1D_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_1D_TwoByteInt = &
          nf_put_varm_int2(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_1D_TwoByteInt = &
          nf_put_vars_int2(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_1D_TwoByteInt = &
          nf_put_vara_int2(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_1D_TwoByteInt

   function nf90_put_var_2D_TwoByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), dimension(:, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_2D_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_2D_TwoByteInt = &
          nf_put_varm_int2(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_2D_TwoByteInt = &
          nf_put_vars_int2(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_2D_TwoByteInt = &
          nf_put_vara_int2(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_2D_TwoByteInt

   function nf90_put_var_3D_TwoByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), dimension(:, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_3D_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_3D_TwoByteInt = &
          nf_put_varm_int2(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_3D_TwoByteInt = &
          nf_put_vars_int2(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_3D_TwoByteInt = &
          nf_put_vara_int2(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_3D_TwoByteInt

   function nf90_put_var_4D_TwoByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), dimension(:, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_4D_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_4D_TwoByteInt = &
          nf_put_varm_int2(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_4D_TwoByteInt = &
          nf_put_vars_int2(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_4D_TwoByteInt = &
          nf_put_vara_int2(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_4D_TwoByteInt

   function nf90_put_var_5D_TwoByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), dimension(:, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_5D_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_5D_TwoByteInt = &
          nf_put_varm_int2(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_5D_TwoByteInt = &
          nf_put_vars_int2(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_5D_TwoByteInt = &
          nf_put_vara_int2(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_5D_TwoByteInt

   function nf90_put_var_6D_TwoByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), dimension(:, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_6D_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_6D_TwoByteInt = &
          nf_put_varm_int2(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_6D_TwoByteInt = &
          nf_put_vars_int2(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_6D_TwoByteInt = &
          nf_put_vara_int2(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_6D_TwoByteInt

   function nf90_put_var_7D_TwoByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = TwoByteInt), dimension(:, :, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_7D_TwoByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_7D_TwoByteInt = &
          nf_put_varm_int2(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_7D_TwoByteInt = &
          nf_put_vars_int2(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_7D_TwoByteInt = &
          nf_put_vara_int2(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_7D_TwoByteInt

   function nf90_put_var_1D_FourByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), dimension(:), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_1D_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_1D_FourByteInt = &
          nf_put_varm_int(ncid, varid, localStart, localCount, localStride, localMap, int(values))
     else if(present(stride)) then
       nf90_put_var_1D_FourByteInt = &
          nf_put_vars_int(ncid, varid, localStart, localCount, localStride, int(values))
     else
       nf90_put_var_1D_FourByteInt = &
          nf_put_vara_int(ncid, varid, localStart, localCount, int(values))
     end if
   end function nf90_put_var_1D_FourByteInt

   function nf90_put_var_2D_FourByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), dimension(:, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_2D_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
        localMap   (:size(map))    = map(:)
        nf90_put_var_2D_FourByteInt = &
             nf_put_varm_int(ncid, varid, localStart, localCount, localStride, localMap, int(values))
     else if(present(stride)) then
        nf90_put_var_2D_FourByteInt = &
             nf_put_vars_int(ncid, varid, localStart, localCount, localStride, int(values))
     else
        nf90_put_var_2D_FourByteInt = &
             nf_put_vara_int(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_2D_FourByteInt

   function nf90_put_var_3D_FourByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), dimension(:, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_3D_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_3D_FourByteInt = &
          nf_put_varm_int(ncid, varid, localStart, localCount, localStride, localMap, int(values))
     else if(present(stride)) then
       nf90_put_var_3D_FourByteInt = &
          nf_put_vars_int(ncid, varid, localStart, localCount, localStride, int(values))
     else
       nf90_put_var_3D_FourByteInt = &
          nf_put_vara_int(ncid, varid, localStart, localCount, int(values))
     end if
   end function nf90_put_var_3D_FourByteInt

   function nf90_put_var_4D_FourByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), dimension(:, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_4D_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_4D_FourByteInt = &
          nf_put_varm_int(ncid, varid, localStart, localCount, localStride, localMap, int(values))
     else if(present(stride)) then
       nf90_put_var_4D_FourByteInt = &
          nf_put_vars_int(ncid, varid, localStart, localCount, localStride, int(values))
     else
       nf90_put_var_4D_FourByteInt = &
          nf_put_vara_int(ncid, varid, localStart, localCount, int(values))
     end if
   end function nf90_put_var_4D_FourByteInt

   function nf90_put_var_5D_FourByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), dimension(:, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_5D_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_5D_FourByteInt = &
          nf_put_varm_int(ncid, varid, localStart, localCount, localStride, localMap, int(values))
     else if(present(stride)) then
       nf90_put_var_5D_FourByteInt = &
          nf_put_vars_int(ncid, varid, localStart, localCount, localStride, int(values))
     else
       nf90_put_var_5D_FourByteInt = &
          nf_put_vara_int(ncid, varid, localStart, localCount, int(values))
     end if
   end function nf90_put_var_5D_FourByteInt

   function nf90_put_var_6D_FourByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), dimension(:, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_6D_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_6D_FourByteInt = &
          nf_put_varm_int(ncid, varid, localStart, localCount, localStride, localMap, int(values))
     else if(present(stride)) then
       nf90_put_var_6D_FourByteInt = &
          nf_put_vars_int(ncid, varid, localStart, localCount, localStride, int(values))
     else
       nf90_put_var_6D_FourByteInt = &
          nf_put_vara_int(ncid, varid, localStart, localCount, int(values))
     end if
   end function nf90_put_var_6D_FourByteInt

   function nf90_put_var_7D_FourByteInt(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     integer (kind = FourByteInt), dimension(:, :, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_7D_FourByteInt

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_7D_FourByteInt = &
          nf_put_varm_int(ncid, varid, localStart, localCount, localStride, localMap, int(values))
     else if(present(stride)) then
       nf90_put_var_7D_FourByteInt = &
          nf_put_vars_int(ncid, varid, localStart, localCount, localStride, int(values))
     else
       nf90_put_var_7D_FourByteInt = &
          nf_put_vara_int(ncid, varid, localStart, localCount, int(values))
     end if
   end function nf90_put_var_7D_FourByteInt

    function nf90_put_var_1D_FourByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), dimension(:), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_1D_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_1D_FourByteReal = &
          nf_put_varm_real(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_1D_FourByteReal = &
          nf_put_vars_real(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_1D_FourByteReal = &
          nf_put_vara_real(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_1D_FourByteReal

   function nf90_put_var_2D_FourByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), dimension(:, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_2D_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_2D_FourByteReal = &
          nf_put_varm_real(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_2D_FourByteReal = &
          nf_put_vars_real(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_2D_FourByteReal = &
          nf_put_vara_real(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_2D_FourByteReal

   function nf90_put_var_3D_FourByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), dimension(:, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_3D_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_3D_FourByteReal = &
          nf_put_varm_real(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_3D_FourByteReal = &
          nf_put_vars_real(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_3D_FourByteReal = &
          nf_put_vara_real(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_3D_FourByteReal

   function nf90_put_var_4D_FourByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), dimension(:, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_4D_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_4D_FourByteReal = &
          nf_put_varm_real(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_4D_FourByteReal = &
          nf_put_vars_real(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_4D_FourByteReal = &
          nf_put_vara_real(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_4D_FourByteReal

   function nf90_put_var_5D_FourByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), dimension(:, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_5D_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_5D_FourByteReal = &
          nf_put_varm_real(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_5D_FourByteReal = &
          nf_put_vars_real(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_5D_FourByteReal = &
          nf_put_vara_real(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_5D_FourByteReal

   function nf90_put_var_6D_FourByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), dimension(:, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_6D_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_6D_FourByteReal = &
          nf_put_varm_real(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_6D_FourByteReal = &
          nf_put_vars_real(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_6D_FourByteReal = &
          nf_put_vara_real(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_6D_FourByteReal

   function nf90_put_var_7D_FourByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = FourByteReal), dimension(:, :, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_7D_FourByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_7D_FourByteReal = &
          nf_put_varm_real(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_7D_FourByteReal = &
          nf_put_vars_real(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_7D_FourByteReal = &
          nf_put_vara_real(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_7D_FourByteReal

   function nf90_put_var_1D_EightByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), dimension(:), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_1D_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_1D_EightByteReal = &
          nf_put_varm_double(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_1D_EightByteReal = &
          nf_put_vars_double(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_1D_EightByteReal = &
          nf_put_vara_double(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_1D_EightByteReal

   function nf90_put_var_2D_EightByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), dimension(:, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_2D_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_2D_EightByteReal = &
          nf_put_varm_double(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_2D_EightByteReal = &
          nf_put_vars_double(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_2D_EightByteReal = &
          nf_put_vara_double(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_2D_EightByteReal

   function nf90_put_var_3D_EightByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), dimension(:, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_3D_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_3D_EightByteReal = &
          nf_put_varm_double(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_3D_EightByteReal = &
          nf_put_vars_double(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_3D_EightByteReal = &
          nf_put_vara_double(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_3D_EightByteReal

   function nf90_put_var_4D_EightByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), dimension(:, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_4D_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_4D_EightByteReal = &
          nf_put_varm_double(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_4D_EightByteReal = &
          nf_put_vars_double(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_4D_EightByteReal = &
          nf_put_vara_double(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_4D_EightByteReal

   function nf90_put_var_5D_EightByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), dimension(:, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_5D_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_5D_EightByteReal = &
          nf_put_varm_double(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_5D_EightByteReal = &
          nf_put_vars_double(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_5D_EightByteReal = &
          nf_put_vara_double(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_5D_EightByteReal

   function nf90_put_var_6D_EightByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), dimension(:, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_6D_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_6D_EightByteReal = &
          nf_put_varm_double(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_6D_EightByteReal = &
          nf_put_vars_double(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_6D_EightByteReal = &
          nf_put_vara_double(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_6D_EightByteReal

   function nf90_put_var_7D_EightByteReal(ncid, varid, values, start, count, stride, map)
     integer,                         intent( in) :: ncid, varid
     real (kind = EightByteReal), dimension(:, :, :, :, :, :, :), &
                                      intent( in) :: values
     integer, dimension(:), optional, intent( in) :: start, count, stride, map
     integer                                      :: nf90_put_var_7D_EightByteReal

     integer, dimension(nf90_max_var_dims) :: localStart, localCount, localStride, localMap
     integer                               :: numDims, counter

     ! Set local arguments to default values
     numDims                 = size(shape(values))
     localStart (:         ) = 1
     localCount (:numDims  ) = shape(values)
     localCount (numDims+1:) = 1
     localStride(:         ) = 1
     localMap   (:numDims  ) = (/ 1, (product(localCount(:counter)), counter = 1, numDims - 1) /)

     if(present(start))  localStart (:size(start) )  = start(:)
     if(present(count))  localCount (:size(count) )  = count(:)
     if(present(stride)) localStride(:size(stride)) = stride(:)
     if(present(map))  then
       localMap   (:size(map))    = map(:)
       nf90_put_var_7D_EightByteReal = &
          nf_put_varm_double(ncid, varid, localStart, localCount, localStride, localMap, values)
     else if(present(stride)) then
       nf90_put_var_7D_EightByteReal = &
          nf_put_vars_double(ncid, varid, localStart, localCount, localStride, values)
     else
       nf90_put_var_7D_EightByteReal = &
          nf_put_vara_double(ncid, varid, localStart, localCount, values)
     end if
   end function nf90_put_var_7D_EightByteReal

max_stars_repo_name: MuellerSeb/netcdf-fortran

max_issues_repo_name: MuellerSeb/netcdf-fortran

max_forks_repo_name: MuellerSeb/netcdf-fortran


text:
      SUBROUTINE loop5_F77(N, x, a, b)
      INTEGER i, N
      REAL*8 x(N), a(N), b(N)

      DO i=1,N
          x(i) = a(i)+b(i);
      END DO
      RETURN
      END

      SUBROUTINE loop5_F77Overhead(N, x, a, b)
      INTEGER i, N
      REAL*8 x(N), a(N), b(N)
      RETURN
      END

ext: f

max_stars_repo_name: fraguela/depspawn

max_issues_repo_name: MSV-Project/IBAMR

max_forks_repo_name: MSV-Project/IBAMR


text:
! Modern Fortran statistical computations module
module stats
contains
   ! function returns real mean of all array elements
   function mean(x, n) result(s)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function result location
      real :: s
      ! local variables
      integer :: i
      ! processing
      s = 0.
      do i = 1, n
         s = ((i-1)*s+x(i))/i
      end do
   end function mean

   ! function returns real population variance of x
   function popvar(x, n, m) result(var)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), optional :: m
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: var
      ! local variables
      integer :: i
      real :: mu
      ! processing
      if (present(m)) then
         mu = m
      else
         mu = mean(x, n)
      end if
      var = 0.
      do i = 1, n
         var = (((i-1)*var)+(x(i)-mu)**2)/i
      end do
   end function popvar

   ! function returns real sample variance of x
   function samvar(x, n) result(var)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: var
      ! local variables
      integer :: i
      real :: m
      ! processing
      m = mean(x, n)
      var = 0.
      do i = 1, n
         var = var + (x(i) - m)**2
      end do
      var = var / (n - 1)
   end function samvar

   ! function returns real population standard deviation of x
   function popstd(x, n) result(std)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: std
      ! processing
      std = sqrt(popvar(x, n))
   end function popstd

   ! function returns real sample standard deviation of x
   function samstd(x, n) result(std)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: std
      ! processing
      std = sqrt(samvar(x, n))
   end function samstd

   ! functions returns index of kth element of x
   ! C. A. R. Hoare's algorithm
   ! implementation works on index array only - preserves data set array
   function quickselect(k, n, x) result(v)
      implicit none
      ! dummy arguments
      integer, intent(in) :: k, n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: v
      ! local variables
      integer :: i, j, left, right, tmp
      integer, dimension(n) :: idx
      real :: pivot
      ! processing
      do i=1,n
         idx(i)=i
      end do
      left=1
      right=n
      do while (left < right)
         pivot=x(idx(k))
         i=left
         j=right
         do
            do while (x(idx(i)) < pivot)
               i=i+1
            end do
            do while (pivot < x(idx(j)))
               j=j-1
            end do
            if (i <= j) then
               tmp=idx(i)
               idx(i)=idx(j)
               idx(j)=tmp
               i=i+1
               j=j-1
            end if
            if (i > j) exit
         end do
         if (j < k) left=i
         if (k < i) right=j
      end do
      v=x(idx(k))
   end function quickselect

   ! function returns median of x
   function median(x, n) result(mdn)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: mdn
      ! processing
      if (mod(n, 2) == 1) then
         mdn=quickselect(n/2+1, n, x)
      else
         mdn=(quickselect(n/2, n, x) + quickselect(n/2+1, n, x))/2
      end if
   end function median

   !funcition returns median absolute deviation of x
   function median_deviation(x, n) result(mad)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: mad
      ! local variables
      integer :: i
      real :: mdn
      real, dimension(n) :: y
      ! processing
      mdn = median(x, n)
      do i = 1, n
         y(i) = abs(mdn - x(i))
      end do
      mad = median(y, n)
   end function median_deviation

   ! function computes the mean absolute deviation of x
   function mean_deviation(x, n) result(aad)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: aad
      ! local variables
      integer :: i
      real :: m
      ! processing
      m = mean(x, n)
      aad = 0.
      do i=1,n
         aad = aad + abs(x(i) - m)
      end do
      aad = aad / n
   end function mean_deviation

   ! function computes the skewness of x (expected value 1/N)
   function skewness(x, n) result(skw)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, intent(in), dimension(n) :: x
      ! function return location
      real :: skw
      ! local variables
      integer :: i
      real :: m, s
      ! processing
      m = mean(x, n)
      s = 0.
      do i = 1, n
         s = s + ((x(i) - m)**3) / n
      end do
      skw = s / samstd(x, n)**3
   end function skewness

   ! nonparametric skew
   function nonparametric_skew(x, n) result(s)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(in) :: x
      ! function result location
      real :: s
      ! processing
      s = (mean(x, n) - median(x, n)) / popstd(x, n)
   end function nonparametric_skew

   ! function computes the covariance of data sets x and y
   function covar(x, y, n) result(cov)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(in) :: x, y
      ! function return location
      real :: cov
      ! local variables
      integer :: i
      real mx, my, dx, dy
      ! processing
      mx = mean(x, n)
      my = mean(y, n)
      cov = 0.
      do i = 1, n
         dx = x(i) - mx
         dy = y(i) - my
         cov = cov + dx * dy
      end do
      cov = cov / n
   end function covar

   function correlation_coefficient(x, y, n) result(rho)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(in) :: x, y
      ! function return location
      real :: rho
      ! processing
      rho = covar(x, y, n) / (samstd(x, n) * samstd(y, n))
   end function correlation_coefficient

   ! iterative merge sort algorithm (fastest stable iterative?)
   subroutine mergesort(x, n)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(inout) :: x
      ! local variables and arrays
      integer :: i, j, l, m, r
      real, dimension(n) :: work
      ! processing
      j = 1
      do
         if (j >= n) exit
         do i = 1, n, 2*j
            l = i
            m = min(i + j - 1, n)
            r = min(i + 2*j - 1, n)
            if ( l >= n .or. m >= n .or. r > n) exit
            call mergearr(x(l:m), x(m+1:r), work(l:r), j, r-m)
            x(l:r) = work(l:r)
         end do
         j = 2 * j
      end do
      x = work
   end subroutine mergesort

   ! subroutine merges two sorted arrays into a third sorted array
   subroutine mergearr(A, B, C, na, nb)
      implicit none
      ! dummy arguments
      integer, intent(in) :: na, nb
      real, dimension(na), intent(in) :: A
      real, dimension(nb), intent(in) :: B
      real, dimension(na+nb), intent(out) :: C
      ! local variables
      integer :: i, j, k
      ! processing
      i = 1
      j = 1
      k = 1
      do
         if (i > na .or. j > nb) exit
         if (A(i) < B(j)) then
            C(k) = A(i)
            i = i + 1
         else
            C(k) = B(j)
            j = j + 1
         end if
         k = k + 1
      end do
      do
         if (i > na) exit
         C(k) = A(i)
         k = k + 1
         i = i + 1
      end do
      do
         if (j > nb) exit
         C(k) = B(j)
         k = k + 1
         j = j + 1
      end do
   end subroutine mergearr

   ! subroutine fills array with uniformly distributed rand
   subroutine uniform(x, n)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(out) :: x
      ! local variables
      integer :: i
      ! processing
      do i = 1, n
         x(i) = rand()
      end do
   end subroutine uniform

   ! subroutine fills array with standard normal distribution
   subroutine normal(x, n)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(out) :: x
      ! local variables
      integer :: i
      real, parameter :: pi = 4.*atan(1.)
      real :: mu, sd
      ! processing
      mu = n/2.
      sd = n/6.018
      do i = 1, n
         x(i) = sd*(1./(sd*sqrt(2.*pi)))*exp(-.5*((i-mu)/sd)**2)
      end do
   end subroutine normal

   ! box-muller normally distributed mapping of rands
   subroutine box_muller(x, n)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(out) :: x
      ! local variables
      real, parameter :: pi = 4.*atan(1.)
      integer :: i
      ! processing
      do i = 1, n
         if (mod(i,2) == 0) then
            x(i) = sqrt(-2.*log(rand()))*sin(2.*pi*rand())
         else
            x(i) = sqrt(-2.*log(rand()))*cos(2.*pi*rand())
         end if
      end do
   end subroutine box_muller

   ! subroutine randnorm is normally distributed analog of
   subroutine randnorm(x, n)
      implicit none
      ! dummy arguments
      integer, intent(in) :: n
      real, dimension(n), intent(out) :: x
      ! local variables
      real :: a, b, c, d, r
      ! processing
      call box_muller(x, n)
      a = minval(x, 1)
      b = maxval(x, 1)
      c = max(-a, b)
      r = 2*c
      d = (r-(b-a))/2.
      x = (x-a+d)/r
   end subroutine
end module stats

max_stars_repo_name: joshroybal/fortran-stats

max_issues_repo_name: joshroybal/fortran-stats

max_forks_repo_name: joshroybal/fortran-stats


text:
!!  Copyright (C)  Stichting Deltares, 2012-2016.
!!
!!  This program is free software: you can redistribute it and/or modify
!!  it under the terms of the GNU General Public License version 3,
!!  as published by the Free Software Foundation.
!!
!!  This program is distributed in the hope that it will be useful,
!!  but WITHOUT ANY WARRANTY; without even the implied warranty of
!!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!!  GNU General Public License for more details.
!!
!!  You should have received a copy of the GNU General Public License
!!  along with this program. If not, see <http://www.gnu.org/licenses/>.
!!
!!  contact: delft3d.support@deltares.nl
!!  Stichting Deltares
!!  P.O. Box 177
!!  2600 MH Delft, The Netherlands
!!
!!  All indications and logos of, and references to registered trademarks
!!  of Stichting Deltares remain the property of Stichting Deltares. All
!!  rights reserved.

!    Date:       4 Nov 1992
!    Time:       14:23
!    Program:    MAXGRO.FOR
!    Version:    1.0
!    Programmer: Hans Los
!    Previous version(s):
!    0.0 -- 21 Feb 1992 --  8:47 -- Operating System: DOS
!
!  *********************************************************************
!  *      SUBROUTINE TO CALCULATE MAXIMUM ATTAINABLE EQUILIBRIUM       *
!  *            VALUES BASED UPON THE INITIAL GROWTH RATE              *
!  *********************************************************************
!
!    Module revision november 1992.
!    Use the TOTAL depth and the TOTAL extinction to compute the
!    growth rate of inhomogeously mixed species. To that purpose
!    "DEP" was added to the parameter list.
!    Corrected (old) error in format 99995.
!
!    Module revision december 1991 and february 1992.
!    Two important modifications:
!    1. All types of a species now have the same KMAX, but a different
!       objective function. (See also BLOOM.FOR).
!    2. Use XINIT for the growth constraint if the total extinction
!       gets too large; NO extra biomass reduction.
!
      SUBROUTINE MAXGRO(XINIT,ROOT,EXTTOT,EADJ,J,ISKMAX,DEP)

      USE DATA_3DL

      IMPLICIT REAL*8 (A-H,O-Z)
      INCLUDE 'blmdim.inc'
      INCLUDE 'putin1.inc'
      INCLUDE 'size.inc'
      INCLUDE 'phyt1.inc'
      INCLUDE 'phyt2.inc'
      INCLUDE 'cal1.inc'
      INCLUDE 'matri.inc'
      INCLUDE 'dynam.inc'
      INCLUDE 'arran.inc'
      INCLUDE 'ioblck.inc'
      REAL*8 ROOT(*),XINIT(*)
!----------------------------------------------------------------------
! Purpose of this subroutine: find the growth efficiency EFFI for each
! phytoplankton species at the current total extinction level EXTTOT.
!
!  get average efficiency over the layers
!
      IF ( IFIX_3DL(IT2(J,1)) .LT. 0 ) THEN
         EFFI = EFFIC_3DL(ISKMAX,ISEG_3DL)
      ELSE
         CALL EFFI_3DL(EFFI,ISKMAX)
      ENDIF
!
!  Check whether ROOT(2) (UKmax) is larger than EXTTOT.
!
      IF (ROOT(2) .LE. EXTTOT) THEN
!
!  Kmax {=ROOT(2)} is smaller than the total extinction, indicating that
!  the species cannot maintain its current biomass.
!  We do need the average efficiency
!  EFFI, however, to compute the coefficients for the objective
!  function.
!  When Kmax is negative for a species, its biomass should approach
!  zero as quickly as possible. Therefore put 0.01 in the objective
!  function.
!  Note: do not use a negative number because the mortality constraint
!  of the species could be positive, indicating that it should be
!  included in the final solution.
!
         IF (ROOT(2) .LE. 0.0) THEN
            EFFI = 0.01
         END IF
         IF (LGROCH .EQ. 1) THEN
!
! Compute the right hand side of the growth constraint for a species,
! whose Kmax < EXTTOT of previous time-step. Normally we might put ANY
! value into the growth constraint as long as it exceeds the energy
! limitation level: the biomass will most likely get energy limited.
! However, as an extra precaution for dealing with infeasible
! solutions put XINIT into the growth constraint: whatever
! is done with the other constraints, this particular type will not
! increase in biomass.
! Check and correct for growth constraints which are lower than the
! mortality constraints.
!
            GRLIM = XINIT(J)
            IF (LMORCH .EQ. 0) THEN
               B(J+NUEXRO) = GRLIM
               RETURN
            END IF
            IF (GRLIM .GT. B(J+NUEXRO+NUECOG)) THEN
               B(J+NUEXRO) = GRLIM
            ELSE
               B(J+NUEXRO) = B(J+NUEXRO+NUECOG)
            END IF
         END IF
      ELSE
!
!  Compute value BT for the growth constraint.
!
         BT=DEXP( ( (PMAX(ISKMAX)-LPMORT*RMORT(ISKMAX))*EFFI - FLUSH
     *              - RESP(ISKMAX) ) *TSTEP*MI)
         BT = BT*XINIT(J)
!
! Set the growth constraint to 0.0 when BT is negative.
!
         IF (BT .LT. 0.0) THEN
            WRITE(IOU(6), 99995) BT, GRNAME(J)
            BT = 0.0D0
         END IF
!
!  Store growth constraint value in B-vector. Optionally print results
!  to unit IOU(6).
!
         B(J+NUEXRO)=BT
         IF (IDUMP .EQ. 1) WRITE (IOU(6),99990) GRNAME(J),EFFI,
     *                     EFFI*PMAX(ISKMAX),B(J+NUEXRO)
!
      END IF
!
! Store the nett growth rate of each phytoplankton type in the row
! for the objective function if growth is maximized.
!
      IF (LOBFUN .EQ. 1) THEN
         DO K = IT2(J,1),IT2(J,2)
            C(K) = DMAX1 ((EFFI * PMAX(K) - RESP(K)), 1.0D-6)
         END DO
      END IF
!
99995 FORMAT (' Warning from MAXGRO: negative growth constraint of ',
     1        ' species ',A8,' = ',F10.5,/,' replaced by 0.0')
99990 FORMAT ('  Species ',A8,' EFFI = ',F5.2,' Growth rate = ',F5.2,
     1        ' B-value = ',F7.3)
      RETURN
      END

max_stars_repo_name: liujiamingustc/phd

max_issues_repo_name: liujiamingustc/phd

max_forks_repo_name: liujiamingustc/phd


text:
     SUBROUTINE DCTSV( N, NRHS, DL, D, DU, B, LDB, INFO )
     USE OMP_LIB
     IMPLICIT NONE
!      PURPOSE solves the cyclic/periodic tridiagonal system, see LAPACK routine DGTSV for comparison
!      Copyright (c) 2021   Anthony M de Beus
       INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision
!      Arguments copied/modified from dgtsv.f *  -- LAPACK routine (version 3.1) --
!      Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
!      November 2006
!
!  N       (input) INTEGER
!          The order of the matrix A.  N >= 4.
!
!  NRHS    (input) INTEGER
!          The number of right hand sides, i.e., the number of columns
!          of the matrix B.  NRHS >= 0.
!
!  DL      (input) working precision array, dimension (N)
!          On entry, DL must contain the sub-diagonal elements of A. The first term
!          wraps around to the last column first row
!
!  D       (input) working precision array, dimension (N)
!          On entry, D must contain the diagonal elements of A.
!
!  DU      (input) working precision array, dimension (N)
!          On entry, DU must contain the super-diagonal elements
!          of A. The last term wraps around to the first column last row
!
!  B       (input/output) working precision array, dimension (LDB,NRHS)
!          On entry, the N by NRHS matrix of right hand side matrix B.
!          On exit, if INFO = 0, the N by NRHS solution matrix X.
!
!  LDB     (input) INTEGER
!          The leading dimension of the array B.  LDB >= max(1,N).
!
!  INFO    (output) INTEGER
!          = 0: successful exit
!          < 0: if INFO = -i, the i-th argument had an illegal value
!          > 0: if INFO = i, a determinant is exactly zero, and the solution
!               has not been computed.
!  Further Details
!  ===============
!
!  The band storage scheme is illustrated by the following example, when
!  N = 9
!              D1  DU1 0   0   0   0   0   0   DL1
!              DL2 D2  DU2 0   0   0   0   0   0
!              0   DL3 D3  DU3 0   0   0   0   0
!              0   0   DL4 D4  DU4 0   0   0   0
!              0   0   0   DL5 D5  DU5 0   0   0
!              0   0   0   0   DL6 D6  DU6 0   0
!              0   0   0   0   0   DL7 D7  DU7 0
!              0   0   0   0   0   0   DL8 D8  DU8
!              DU9 0   0   0   0   0   0   DL9 D9
!
!      .. Scalar Arguments ..
       INTEGER, INTENT(IN) :: LDB, N, NRHS
       INTEGER, INTENT(OUT) :: INFO
!      ..
!      .. Array Arguments ..
       REAL(wp), INTENT(IN) :: D( N ), DL( N ), DU( N )  ! no output no LU factors
       REAL(wp), INTENT(INOUT) :: B( LDB, NRHS )         ! on entry RHS, on exit, solution

!      make a copy to avoid data blocking
       REAL(wp) :: DR( N ), DLR( N ), DUR( N )  ! no output no LU factors
       REAL(wp) :: BR( N, NRHS )                ! on entry RHS, on exit, solution
!      ..
       REAL(wp) :: udR(2,2,N/4:N/2+1),ueR(2,N/4:N/2+1,NRHS),DET2  ! udR is my set of matrices Aj(bar) ueR is my vectors vj(bar)
       REAL(wp) :: ud(2,2,0:N/4+1),ue(2,0:N/4+1,NRHS),DET         !  ud is my set of matrices Aj ue is my vectors vj

       INTEGER :: i,j,k,p,L,thread

!      needed for f90+ calling of f77 routines
       INTERFACE
          SUBROUTINE XERBLA( SRNAME, INFO )
!         .. Scalar Arguments ..
          CHARACTER*6        SRNAME          !CHARACTER(6)
          INTEGER            INFO
          END SUBROUTINE XERBLA
       END INTERFACE

!      INFO handling copied/modified from dgtsv.f *  -- LAPACK routine (version 3.1) --
!      Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
!      November 2006
       INFO = 0
       IF( N.LT.4 ) THEN
         INFO = -1
       ELSE IF( NRHS.LT.0 ) THEN
         INFO = -2
       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
         INFO = -7
       END IF
       IF( INFO.NE.0 ) THEN
         CALL XERBLA( 'DCTSV ', -INFO )
!         RETURN
       END IF
!       IF( N.EQ.0 ) RETURN
!      End INFO handling

       DR=D
       DLR=DL
       DUR=DU
       BR=B

       p=mod(N,2)
       L=(N-p)/4

!      FIRST EQUATION ud(0)=((0,1),(1,0) & ue(0) = (0,0)
       ud(:,:,0)=0
       ud(1,2,0)=1
       ud(2,1,0)=1
       ue(:,0,:)=0

!      FIRST EQUATION
!       udR(0)=((0,1),(1,0) & ueR(0) = (0,0) when p==0
       if (p == 0) then
        udR(:,:,N/2+1)=0
        udR(1,2,N/2+1)=1
        udR(2,1,N/2+1)=1
        ueR(:,N/2+1,:)=0
       else
        if ( D((N+1)/2) /= 0) then
        udR(1,1,(N+1)/2)=-DL((N+1)/2)/D((N+1)/2)
        udR(1,2,(N+1)/2)=-DU((N+1)/2)/D((N+1)/2)
        udR(2,1,(N+1)/2)=-DL((N+1)/2)/D((N+1)/2)
        udR(2,2,(N+1)/2)=-DU((N+1)/2)/D((N+1)/2)
        ueR(1,(N+1)/2,1:NRHS)=B((N+1)/2,1:NRHS)/D((N+1)/2)
        ueR(2,(N+1)/2,1:NRHS)=B((N+1)/2,1:NRHS)/D((N+1)/2)
        else
         INFO=(N+1)/2
         CALL XERBLA( 'DCTSV ', -INFO )
!         RETURN
        endif
       endif

!$OMP PARALLEL num_threads(2) PRIVATE(thread)
!      separate iterative parts into subroutines so each thread can work in parallel
       thread = omp_get_thread_num()
       if (thread==0) then
        call forward_dctsv(N, NRHS, DL, D, DU, B, LDB, INFO, UD, UE)
       else
        call backward_dctsv(N, NRHS, DLR, DR, DUR, BR, LDB, INFO, UDR, UER)
       endif
!$OMP END PARALLEL

!      LAST EQUATIONS for both is at L
       j=L
!      B(j)=Inverse[IDENT-matmul(udR(:,:,j),ud(:,:,j-1))][udR(:,:,j)*ue(j-1)+ueR(j)]

       DET=(1-udR(1,1,j)*ud(1,1,j-1)-udR(1,2,j)*ud(2,1,j-1))*&
            (1-udR(2,1,j)*ud(1,2,j-1)-udR(2,2,j)*ud(2,2,j-1))-&
              (udR(1,1,j)*ud(1,2,j-1)+udR(1,2,j)*ud(2,2,j-1))*&
              (udR(2,1,j)*ud(1,1,j-1)+udR(2,2,j)*ud(2,1,j-1))

       DET2=(1-ud(1,1,j-1)*udR(1,1,j)-ud(1,2,j-1)*udR(2,1,j))*&
            (1-ud(2,1,j-1)*udR(1,2,j)-ud(2,2,j-1)*udR(2,2,j))-&
              (ud(1,1,j-1)*udR(1,2,j)+ud(1,2,j-1)*udR(2,2,j))*&
              (ud(2,1,j-1)*udR(1,1,j)+ud(2,2,j-1)*udR(2,1,j))

        IF (DET /= 0 .AND. DET2 /= 0) THEN

         B(j,1:NRHS) = ((1-udR(2,1,j)*ud(1,2,j-1)-udR(2,2,j)*ud(2,2,j-1))*&
               (udR(1,1,j)*ue(1,j-1,1:NRHS)+udR(1,2,j)*ue(2,j-1,1:NRHS)+ ueR(1,j,1:NRHS))+&
               (udR(1,1,j)*ud(1,2,j-1)+udR(1,2,j)*ud(2,2,j-1))*(udR(2,1,j)*ue(1,j-1,1:NRHS)&
               +udR(2,2,j)*ue(2,j-1,1:NRHS)+ ueR(2,j,1:NRHS)))/DET

         B(N-j+1,1:NRHS) = ((1-udR(1,1,j)*ud(1,1,j-1)-udR(1,2,j)*ud(2,1,j-1))*&
               (udR(2,1,j)*ue(1,j-1,1:NRHS)+udR(2,2,j)*ue(2,j-1,1:NRHS)+ ueR(2,j,1:NRHS))+&
               (udR(2,1,j)*ud(1,1,j-1)+udR(2,2,j)*ud(2,1,j-1))*(udR(1,1,j)*ue(1,j-1,1:NRHS)&
               +udR(1,2,j)*ue(2,j-1,1:NRHS)+ ueR(1,j,1:NRHS)))/DET

        if (L > 1 ) then
        B(j-1,1:NRHS) = ((1-ud(2,1,j-1)*udR(1,2,j)-ud(2,2,j-1)*udR(2,2,j))*&
               (ud(1,1,j-1)*ueR(1,j,1:NRHS)+ud(1,2,j-1)*ueR(2,j,1:NRHS)+ ue(1,j-1,1:NRHS))+&
               (ud(1,1,j-1)*udR(1,2,j)+ud(1,2,j-1)*udR(2,2,j))*(ud(2,1,j-1)*ueR(1,j,1:NRHS)&
               +ud(2,2,j-1)*ueR(2,j,1:NRHS)+ ue(2,j-1,1:NRHS)))/DET2

         B(N-j+2,1:NRHS) = ((1-ud(1,1,j-1)*udR(1,1,j)-ud(1,2,j-1)*udR(2,1,j))*&
               (ud(2,1,j-1)*ueR(1,j,1:NRHS)+ud(2,2,j-1)*ueR(2,j,1:NRHS)+ ue(2,j-1,1:NRHS))+&
               (ud(2,1,j-1)*udR(1,1,j)+ud(2,2,j-1)*udR(2,1,j))*(ud(1,1,j-1)*ueR(1,j,1:NRHS)&
               +ud(1,2,j-1)*ueR(2,j,1:NRHS)+ ue(1,j-1,1:NRHS)))/DET2
         endif

        ELSE

         INFO=j
         CALL XERBLA( 'DCTSV ', -INFO )
!         RETURN
        ENDIF

!     These are iterative and should have a problem with OMP, but apparently not with num_threads=2.

!      BACKSUBSTITUTION B(j-1)=UE(j-1)+UD(:,:,j-1)*B(j)
       do i=L-1,1,-1
        B(i,1:NRHS)=    ue(1,i,1:NRHS)+ud(1,1,i)*B(i+1,1:NRHS)+ud(1,2,i)*B(N-i,1:NRHS)
        B(N-i+1,1:NRHS)=ue(2,i,1:NRHS)+ud(2,1,i)*B(i+1,1:NRHS)+ud(2,2,i)*B(N-i,1:NRHS)
       end do

!      BACKSUBSTITUTION B(j+1)=UER(j+1)+UDR(:,:,j+1)*B(j)
       do i=L,(N-p)/2-1
        B(i+1,1:NRHS)=ueR(1,i+1,1:NRHS)+udR(1,1,i+1)*B(i,1:NRHS)+udR(1,2,i+1)*B(N-i+1,1:NRHS)
        B(N-i,1:NRHS)=ueR(2,i+1,1:NRHS)+udR(2,1,i+1)*B(i,1:NRHS)+udR(2,2,i+1)*B(N-i+1,1:NRHS)
       end do

       if (p /=0) then  ! take the average for the middle value
        i=(N-p)/2
        B(i+1,1:NRHS)=(ueR(1,i+1,1:NRHS)+udR(1,1,i+1)*B(i,1:NRHS)+udR(1,2,i+1)*B(N-i+1,1:NRHS)+&
                       ueR(2,i+1,1:NRHS)+udR(2,1,i+1)*B(i,1:NRHS)+udR(2,2,i+1)*B(N-i+1,1:NRHS))/2
       endif

     end subroutine DCTSV

!     The two iterative loop routines follow

       subroutine forward_dctsv(N, NRHS, DL, D, DU, B, LDB, INFO, UD, UE)
       IMPLICIT NONE
!      PURPOSE forward iterative loop
!      Copyright (c) 2021   Anthony M de Beus
       INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision
       INTEGER, INTENT(IN) :: LDB, N, NRHS
       INTEGER, INTENT(OUT) :: INFO
!      ..
!      .. Array Arguments ..
       REAL(wp), INTENT(IN) :: D( * ), DL( * ), DU( * ), B( LDB, * )
       REAL(wp) :: ud(2,2,0:N/4+1),ue(2,0:N/4+1,NRHS)
!      ..
       REAL(wp) :: DET  !  ud is my set of matrices Aj ue is my vectors vj
       INTEGER :: i,j,p,L

       p=mod(N,2)
       L=(N-p)/4

!      ALL BUT THE LAST EQUATION
       do j=1,L
        DET=D(j)*D(1-j+N)+DL(j)*D(1-j+N)*ud(1,1,-1+j)-&
            DL(j)*DU(1-j+N)*ud(1,2,-1+j)*ud(2,1,-1+j)+&
            D(j)*DU(1-j+N)*ud(2,2,-1+j)+&
            DL(j)*DU(1-j+N)*ud(1,1,-1+j)*ud(2,2,-1+j)
        IF (DET /= 0) THEN
         ud(1,1,j)=-((DU(j)*(D(1-j+N)+DU(1-j+N)*ud(2,2,-1+j)))/DET)
         ud(1,2,j)=(DL(j)*DL(1-j+N)*ud(1,2,-1+j))/DET
         ud(2,1,j)=(DU(j)*DU(1-j+N)*ud(2,1,-1+j))/DET
         ud(2,2,j)=-((DL(1-j+N)*(D(j)+DL(j)*ud(1,1,-1+j)))/DET)
         ue(1,j,1:NRHS)=(-DL(j)*(B(1-j+N,1:NRHS)-DU(1-j+N)*ue(2,-1+j,1:NRHS))*ud(1,2,-1+j)+&
                (B(j,1:NRHS)-DL(j)*ue(1,-1+j,1:NRHS))*(D(1-j+N)+DU(1-j+N)*ud(2,2,-1+j)))/DET
         ue(2,j,1:NRHS)=((B(1-j+N,1:NRHS)-DU(1-j+N)*ue(2,-1+j,1:NRHS))*(D(j)+DL(j)*ud(1,1,-1+j))-&
                DU(1-j+N)*(B(j,1:NRHS)-DL(j)*ue(1,-1+j,1:NRHS))*ud(2,1,-1+j))/DET
        ELSE
         INFO=j
         CALL XERBLA( 'DCTSV ', INFO )
!         RETURN
        ENDIF
       end do
       end subroutine forward_dctsv

       subroutine backward_dctsv(N, NRHS, DL, D, DU, B, LDB, INFO, UDR, UER)
       IMPLICIT NONE
!      PURPOSE backward iterative loop
!      Copyright (c) 2021   Anthony M de Beus
       INTEGER, PARAMETER :: wp = KIND(0.0D0) ! working precision
       INTEGER, INTENT(IN) :: LDB, N, NRHS
       INTEGER, INTENT(OUT) :: INFO
!      ..
!      .. Array Arguments ..
       REAL(wp), INTENT(IN) :: D( * ), DL( * ), DU( * ), B( LDB, * )
       REAL(wp) :: udR(2,2,N/4:N/2+1),ueR(2,N/4:N/2+1,NRHS)
!      ..
       REAL(wp) :: DET  !  ud is my set of matrices Aj ue is my vectors vj
       INTEGER :: i,j,p,L

       p=mod(N,2)
       L=(N-p)/4

!      ALL BUT THE LAST EQUATION
       do j=(N-p)/2,L,-1
        DET=D(j)*D(1-j+N)+DU(j)*D(1-j+N)*udR(1,1,1+j)-&
            DU(j)*DL(1-j+N)*udR(1,2,1+j)*udR(2,1,1+j)+&
            D(j)*DL(1-j+N)*udR(2,2,1+j)+&
            DU(j)*DL(1-j+N)*udR(1,1,1+j)*udR(2,2,1+j)

        IF (DET /= 0) THEN
         udR(1,1,j)=-((DL(j)*(D(1-j+N)+DL(1-j+N)*udR(2,2,1+j)))/DET)
         udR(1,2,j)=(DU(j)*DU(1-j+N)*udR(1,2,1+j))/DET
         udR(2,1,j)=(DL(j)*DL(1-j+N)*udR(2,1,1+j))/DET
         udR(2,2,j)=-((DU(1-j+N)*(D(j)+DU(j)*udR(1,1,1+j)))/DET)
         ueR(1,j,1:NRHS)=(-DU(j)*(B(1-j+N,1:NRHS)-DL(1-j+N)*ueR(2,1+j,1:NRHS))*udR(1,2,1+j)+&
                (B(j,1:NRHS)-DU(j)*ueR(1,1+j,1:NRHS))*(D(1-j+N)+DL(1-j+N)*udR(2,2,1+j)))/DET
         ueR(2,j,1:NRHS)=((B(1-j+N,1:NRHS)-DL(1-j+N)*ueR(2,1+j,1:NRHS))*(D(j)+DU(j)*udR(1,1,1+j))-&
                DL(1-j+N)*(B(j,1:NRHS)-DU(j)*ueR(1,1+j,1:NRHS))*udR(2,1,1+j))/DET
        ELSE
         INFO=j
         CALL XERBLA( 'DCTSV ', -INFO )
!         RETURN
        ENDIF
       end do
       end subroutine backward_dctsv

max_stars_repo_name: mostlyharmlessone/cyclic-banded-matrix

max_issues_repo_name: mostlyharmlessone/cyclic-banded-matrix

max_forks_repo_name: mostlyharmlessone/cyclic-banded-matrix