! netcdf_f77.f90 - netCDF original interface module
! Copyright (C) GFD Dennou Club, 2000.  All rights reserved
! ex: set sw=4:

! 2000-01-10 豊田英司        初版

!
! 本モジュール群は netCDF オリジナルの netcdf.inc の代わりに
! 利用すべきものである。netcdf.inc への参照はしていない。
!

module netcdf_f77

    use dc_types, only: NF_KIND_INT1, NF_KIND_INT2

    implicit none

!
! --- symbols ---
!

    !
    ! external netCDF data type ID
    !

    integer, parameter:: NF_BYTE = 1
    integer, parameter:: NF_INT1 = NF_BYTE
    integer, parameter:: NF_CHAR = 2
    integer, parameter:: NF_SHORT = 3
    integer, parameter:: NF_INT2 = NF_SHORT
    integer, parameter:: NF_INT = 4
    integer, parameter:: NF_FLOAT = 5
    integer, parameter:: NF_REAL = NF_FLOAT
    integer, parameter:: NF_DOUBLE = 6

    !
    ! default fill values
    !

    integer, parameter:: NF_FILL_BYTE = -127
    integer, parameter:: NF_FILL_INT1 = NF_FILL_BYTE
    integer, parameter:: NF_FILL_CHAR = 0
    integer, parameter:: NF_FILL_SHORT = -32767
    integer, parameter:: NF_FILL_INT2 = NF_FILL_SHORT
    integer, parameter:: NF_FILL_INT = -2147483647
    real, parameter:: NF_FILL_FLOAT = 9.9692099683868690e+36
    real, parameter:: NF_FILL_REAL = NF_FILL_FLOAT
    double precision, parameter:: &
            & NF_FILL_DOUBLE = 9.9692099683868690e+36

    !
    ! mode flags for opening and creating a netcdf dataset:
    !

    integer, parameter:: NF_NOWRITE = 0
    integer, parameter:: NF_WRITE = 1
    integer, parameter:: NF_CLOBBER = 0
    integer, parameter:: NF_NOCLOBBER = 4
    integer, parameter:: NF_FILL = 0
    integer, parameter:: NF_NOFILL = 256
    integer, parameter:: NF_LOCK = 1024
    integer, parameter:: NF_SHARE = 2048
    integer, parameter:: NF_SIZEHINT_DEFAULT = 0
    integer, parameter:: NF_ALIGN_CHUNK = -1

    !
    ! size argument for defining an unlimited dimension:
    !

    integer, parameter:: NF_UNLIMITED = 0

    !
    ! global attribute id:
    !

    integer, parameter:: NF_GLOBAL = 0

    !
    ! implementation limits:
    !

    integer, parameter:: NF_MAX_DIMS = 100
    integer, parameter:: NF_MAX_ATTRS = 2000
    integer, parameter:: NF_MAX_VARS = 2000
    integer, parameter:: NF_MAX_NAME = 128
    integer, parameter:: NF_MAX_VAR_DIMS = NF_MAX_DIMS

    !
    ! error codes:
    !

    integer, parameter:: NF_NOERR = 0
    integer, parameter:: NF_EBADID = -33
    integer, parameter:: NF_EEXIST = -35
    integer, parameter:: NF_EINVAL = -36
    integer, parameter:: NF_EPERM = -37
    integer, parameter:: NF_ENOTINDEFINE = -38
    integer, parameter:: NF_EINDEFINE = -39
    integer, parameter:: NF_EINVALCOORDS = -40
    integer, parameter:: NF_EMAXDIMS = -41
    integer, parameter:: NF_ENAMEINUSE = -42
    integer, parameter:: NF_ENOTATT = -43
    integer, parameter:: NF_EMAXATTS = -44
    integer, parameter:: NF_EBADTYPE = -45
    integer, parameter:: NF_EBADDIM = -46
    integer, parameter:: NF_EUNLIMPOS = -47
    integer, parameter:: NF_EMAXVARS = -48
    integer, parameter:: NF_ENOTVAR = -49
    integer, parameter:: NF_EGLOBAL = -50
    integer, parameter:: NF_ENOTNC = -51
    integer, parameter:: NF_ESTS = -52
    integer, parameter:: NF_EMAXNAME = -53
    integer, parameter:: NF_EUNLIMIT = -54
    integer, parameter:: NF_ENORECVARS = -55
    integer, parameter:: NF_ECHAR = -56
    integer, parameter:: NF_EEDGE = -57
    integer, parameter:: NF_ESTRIDE = -58
    integer, parameter:: NF_EBADNAME = -59
    integer, parameter:: NF_ERANGE = -60
    integer, parameter:: NF_ENOMEM = -61

    !
    ! error handling modes:
    !

    integer, parameter:: NF_FATAL = 1
    integer, parameter:: NF_VERBOSE = 2

!
! --- interfaces ---
!

    interface

    !
    ! --- 雑多な関数 ---
    !

        ! netCDF ライブラリのバージョンを返す
        !
        function nf_inq_libvers(ncerr)
            character(len=80)::                nf_inq_libvers
            integer, intent(in)::        ncerr
        end function

        ! (ドキュメントされていない関数)
        ! エラーコードが netCDF ではなく C ライブラリによるとき真
        !
        logical function nf_issyserr(ncerr)
            integer, intent(in)::        ncerr
        end function

        ! エラーコードから netCDF のメッセージを返す
        !
        character(len=80) function nf_strerror(ncerr)
            integer, intent(in)::        ncerr
        end function

        ! (ドキュメントされていない関数)
        ! PE の操作らしい
        !
        integer function nf_inq_base_pe(ncid, pe)
            integer, intent(in)::        ncid, pe
        end function

        ! (ドキュメントされていない関数)
        ! PE の操作らしい
        !
        integer function nf_set_base_pe(ncid, pe)
            integer, intent(in)::        ncid, pe
        end function

    !
    ! --- ファイルを作る・開く・閉じる・基礎的操作 ---
    !

        ! ファイルを作成する (開かれた状態となる)
        !
        integer function nf_create(path, cmode, ncid)
            character(len=*), intent(in)::        path
            integer, intent(in)::                cmode
            integer, intent(out)::                ncid
        end function

        ! (ドキュメントされていない関数)
        integer function nf__create(path, cmode, initialsz, &
            & chunksizehint, ncid)
            character(len=*), intent(in)::        path
            integer, intent(in):: cmode, initialsz, chunksizehint
            integer, intent(out)::                ncid
        end function

        ! (ドキュメントされていない関数)
        integer function nf__create_mp(path, cmode, initialsz, &
            & basepe, chunksizehint, ncid)
            character(len=*), intent(in)::        path
            integer, intent(in):: cmode, initialsz, basepe, chunksizehint
            integer, intent(out)::                ncid
        end function

        ! ファイルを開く
        !
        integer function nf_open(path, cmode, ncid)
            character(len=*), intent(in)::        path
            integer, intent(in)::                cmode
            integer, intent(out)::                ncid
        end function

        ! (ドキュメントされていない関数)
        integer function nf__open(path, cmode, initialsz, &
            & chunksizehint, ncid)
            character(len=*), intent(in)::        path
            integer, intent(in):: cmode, initialsz, chunksizehint
            integer, intent(out)::                ncid
        end function

        ! (ドキュメントされていない関数)
        integer function nf__open_mp(path, cmode, initialsz, &
            & basepe, chunksizehint, ncid)
            character(len=*), intent(in)::        path
            integer, intent(in):: cmode, initialsz, basepe, chunksizehint
            integer, intent(out)::                ncid
        end function

        ! fill モードの設定/解除
        integer function nf_set_fill(ncid, fillmode, old_mode)
            integer, intent(in)::        ncid, fillmode
            integer, intent(out)::        old_mode
        end function

        ! 定義モードへの移行
        integer function nf_redef(ncid)
            integer, intent(in)::        ncid
        end function

        ! 定義モードからの脱出
        integer function nf_enddef(ncid)
            integer, intent(in)::        ncid
        end function

        ! 定義モードからの脱出
        ! (ドキュメントされていない関数)
        integer function nf__enddef(ncid, h_minfree, v_align, &
            & v_minfree, r_align)
            integer, intent(in)::        ncid
            integer, intent(in):: h_minfree, v_align, &
                & v_minfree, r_align
        end function

        ! 同期
        integer function nf_sync(ncid)
            integer, intent(in)::        ncid
        end function

        ! 閉じる
        integer function nf_close(ncid)
            integer, intent(in)::        ncid
        end function

        ! 閉じる際に定義モードにある場合に呼ばれる
        ! (ユーザが呼ぶ必要のない関数)
        integer function nf_abort(ncid)
            integer, intent(in)::        ncid
        end function

        ! MP用 ファイルの削除
        ! (ドキュメントされていない関数)
        integer function nf_delete(path)
            character(len=*), intent(in)::        path
        end function

    !
    ! --- ファイルの問い合わせ ---
    !

        ! 開かれたファイル ncid に対しすべての問い合わせを行う
        !
        integer function nf_inq(ncid, ndims, nvars, ngatts, unlimdimid)
            integer, intent(in)::        ncid
            integer, intent(out)::        ndims, nvars, ngatts
            integer, intent(out)::        unlimdimid
        end function

        ! 次元数 ndims を問い合わせる
        integer function nf_inq_ndims(ncid, ndims)
            integer, intent(in)::        ncid
            integer, intent(out)::        ndims
        end function

        ! 変数の数 nvars を問い合わせる
        integer function nf_inq_nvars(ncid, nvars)
            integer, intent(in)::        ncid
            integer, intent(out)::        nvars
        end function

        ! 大域属性の数 ngatts を問い合わせる
        integer function nf_inq_natts(ncid, ngatts)
            integer, intent(in)::        ncid
            integer, intent(out)::        ngatts
        end function

        ! 無制限次元のID unlimdimid を問い合わせる
        ! もしなければ 1 が返る
        integer function nf_inq_unlimdim(ncid, unlimdimid)
            integer, intent(in)::        ncid
            integer, intent(out)::        unlimdimid
        end function

    !
    ! --- 次元に関するルーチン ---
    !

        ! 名称 name, 長さ len を持つ次元を定義する
        ! 割り当てられた次元 ID (正の整数) が dimid に返される
        integer function nf_def_dim(ncid, name, len, dimid)
            integer, intent(in)::                ncid
            character(len=*), intent(in)::        name
            integer, intent(in)::                len
            integer, intent(out)::                dimid
        end function

        ! 名前に対する次元 ID を問い合わせる
        integer function nf_inq_dimid(ncid, name, dimid)
            integer, intent(in)::                ncid
            character(len=*), intent(in)::        name
            integer, intent(out)::                dimid
        end function

        ! 次元 ID から名前 name と長さ len を問い合わせる
        ! name には必要な長さがなければならない
        integer function nf_inq_dim(ncid, dimid, name, len)
            integer, intent(in)::                ncid
            integer, intent(in)::                dimid
            character(len=*), intent(out)::        name
            integer, intent(out)::                len
        end function

        ! 次元 ID から名前 name を問い合わせる
        ! name には必要な長さがなければならない
        integer function nf_inq_dimname(ncid, dimid, name)
            integer, intent(in)::                ncid
            integer, intent(in)::                dimid
            character(len=*), intent(out)::        name
        end function

        ! 次元 ID から長さ len を問い合わせる
        integer function nf_inq_dimlen(ncid, dimid, len)
            integer, intent(in)::                ncid
            integer, intent(in)::                dimid
            integer, intent(out)::                len
        end function

    !
    ! --- 属性 ---
    !
    ! 属性は文字型スカラ変数か、数値型配列である。
    ! 長さとは文字型では長さパラメタ、数値型では配列の大きさである。
    ! 属性は変数 varid に所属するか、大域属性となる。
    ! 大域属性の varid としては NF_GLOBAL を用いる。

        !
        ! --- 属性に関する問い合わせ ---
        !

        ! 変数 varid の属性 name の型 xtype と長さ len の問い合わせ
        integer function nf_inq_att(ncid, varid, name, xtype, len)
            integer, intent(in)::        ncid, varid
            character(len=*), intent(in):: name
            integer, intent(out)::        xtype
            integer, intent(out)::        len
        end function

        ! 変数 varid の属性 name の型 xtype の問い合わせ
        integer function nf_inq_atttype(ncid, varid, name, xtype)
            integer, intent(in)::        ncid, varid
            character(len=*), intent(in):: name
            integer, intent(out)::        xtype
        end function

        ! 変数 varid の属性 name の長さ len の問い合わせ
        integer function nf_inq_attlen(ncid, varid, name, len)
            integer, intent(in)::        ncid, varid
            character(len=*), intent(in):: name
            integer, intent(out)::        len
        end function

        ! 変数 varid の属性 name の番号 attnum の問い合わせ
        integer function nf_inq_attid(ncid, varid, name, attnum)
            integer, intent(in)::        ncid, varid
            character(len=*), intent(in):: name
            integer, intent(out)::        attnum
        end function

        ! 変数 varid の属性 attnum の名前 name の問い合わせ
        ! name には必要な長さがなければならない
        integer function nf_inq_attname(ncid, varid, attnum, name)
            integer, intent(in)::        ncid, varid
            integer, intent(in)::        attnum
            character(len=*), intent(out):: name
        end function

        !
        ! --- 属性の読み書き以外の操作 ---
        !

        integer function nf_copy_att(ncid_in, varid_in, name, &
        & ncid_out, varid_out)
            integer, intent(in)::                ncid_in, varid_in
            character(len=*), intent(in)::        name
            integer, intent(in)::                ncid_out, varid_out
        end function

        integer function nf_rename_att(ncid, varid, curname, newname)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        curname
            character(len=*), intent(in)::        newname
        end function

        integer function nf_del_att(ncid, varid, name)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
        end function

        !
        ! --- 属性の設定 ---
        !

        integer function nf_put_att_text(ncid, varid, name, len, text)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer, intent(in)::                len
            character(len=*), intent(in)::        text
        end function

        integer function nf_put_att_int1(ncid, varid, name, &
        & xtype, len, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer, intent(in)::                xtype, len
            integer(NF_KIND_INT1), intent(in):: i1vals(*)
        end function

        integer function nf_put_att_int2(ncid, varid, name, &
        & xtype, len, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer, intent(in)::                xtype, len
            integer(NF_KIND_INT2), intent(in):: i2vals(*)
        end function

        integer function nf_put_att_int(ncid, varid, name, &
        & xtype, len, ivals)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer, intent(in)::                xtype, len
            integer, intent(in)::                ivals(*)
        end function

        integer function nf_put_att_real(ncid, varid, name, &
        & xtype, len, rvals)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer, intent(in)::                xtype, len
            real, intent(in)::                        rvals(*)
        end function

        integer function nf_put_att_double(ncid, varid, name, &
        & xtype, len, dvals)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer, intent(in)::                xtype, len
            double precision, intent(in)::        dvals(*)
        end function

        !
        ! --- 属性の読み取り ---
        !

        integer function nf_get_att_text(ncid, varid, name, text)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            character(len=*), intent(out)::        text
        end function

        integer function nf_get_att_int1(ncid, varid, name, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer(NF_KIND_INT1), intent(in):: i1vals(*)
        end function

        integer function nf_get_att_int2(ncid, varid, name, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer(NF_KIND_INT2), intent(in):: i2vals(*)
        end function

        integer function nf_get_att_int(ncid, varid, name, ivals)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            integer, intent(in)::                ivals(*)
        end function

        integer function nf_get_att_real(ncid, varid, name, rvals)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            real, intent(in)::                        rvals(*)
        end function

        integer function nf_get_att_double(ncid, varid, name, dvals)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
            double precision, intent(in)::        dvals(*)
        end function

    !
    ! --- 変数 ---
    !
    ! 変数は次元によってきまる配列である。
    ! 定義した次元すべてを使わなくてはいけないわけではない。
    !

        ! 名前 name の変数を定義する。
        ! データ型 xtype, 次元数 ndims とし,
        ! 各次元の ID は dimids で与える。
        ! 変数 ID は varid に返される。
        integer function nf_def_var(ncid, name, &
        & xtype, ndims, dimids, varid)
            integer, intent(in)::                ncid
            character(len=*), intent(in)::        name
            integer, intent(in)::                xtype, ndims
            integer, intent(in)::                dimids(*)
            integer, intent(out)::                varid
        end function

        !
        ! --- 変数に関する問い合わせ ---
        !

        ! 変数名 name から ID varid を知る
        integer function nf_inq_varid(ncid, name, varid)
            integer, intent(in)::                ncid
            character(len=*), intent(in)::        name
            integer, intent(out)::                varid
        end function

        ! 変数 varid から何でも問いあわせ (以下の関数参照)
        ! dimids は必要な大きさがなければならない
        integer function nf_inq_var(ncid, varid, &
        & name, xtype, ndims, dimids, natts)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(out)::        name
            integer, intent(out)::                xtype, ndims, natts 
            integer, intent(out)::                dimids(*)
        end function

        ! 変数 varid から変数名 name を知る
        ! name には必要な長さがなければならない
        integer function nf_inq_varname(ncid, varid, name)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(out)::        name
        end function

        ! 変数 varid から型 xtype を知る
        integer function nf_inq_vartype(ncid, varid, xtype)
            integer, intent(in)::                ncid, varid
            integer, intent(out)::                xtype
        end function

        ! 変数 varid から次元数 ndims を知る
        integer function nf_inq_varndims(ncid, varid, ndims)
            integer, intent(in)::                ncid, varid
            integer, intent(out)::                ndims
        end function

        ! 変数 varid から次元ID 配列 dimids を得る
        integer function nf_inq_vardimid(ncid, varid, dimids)
            integer, intent(in)::                ncid, varid
            integer, intent(out)::                dimids(*)
        end function

        ! 変数 varid から属性数 natts を知る
        integer function nf_inq_varnatts(ncid, varid, natts)
            integer, intent(in)::                ncid, varid
            integer, intent(out)::                natts
        end function

        !
        ! --- 変数に関する読み書き以外の操作 ---
        !

        ! 変数 varid を name に改名する
        integer function nf_rename_var(ncid, varid, name)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        name
        end function

        ! 変数 varid を別の netCDF データセット ncid_out にコピーする
        integer function nf_copy_var(ncid, varid, ncid_out)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                ncid_out
        end function

    !
    ! --- 変数の書き込み ---
    !

        !
        ! 変数の単要素書き込み
        !

        integer function nf_put_var1_text(ncid, varid, index, chval)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            character, intent(in)::                chval
        end function

        integer function nf_put_var1_int1(ncid, varid, index, i1val)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            integer(NF_KIND_INT1), intent(in):: i1val
        end function

        integer function nf_put_var1_int2(ncid, varid, index, i2val)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            integer(NF_KIND_INT2), intent(in):: i2val
        end function

        integer function nf_put_var1_int(ncid, varid, index, ival)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            integer, intent(in)::                 ival
        end function

        integer function nf_put_var1_real(ncid, varid, index, rval)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            real, intent(in)::                         rval
        end function

        integer function nf_put_var1_double(ncid, varid, index, dval)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            double precision, intent(in)::         dval
        end function

        !
        ! 変数の全体書き込み
        !

        integer function nf_put_var_text(ncid, varid, text)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(in)::        text
        end function

        integer function nf_put_var_int1(ncid, varid, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer(NF_KIND_INT1), intent(in):: i1vals(*)
        end function

        integer function nf_put_var_int2(ncid, varid, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer(NF_KIND_INT2), intent(in):: i2vals(*)
        end function

        integer function nf_put_var_int(ncid, varid, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                 ivals(*)
        end function

        integer function nf_put_var_real(ncid, varid, rvals)
            integer, intent(in)::                ncid, varid
            real, intent(in)::                         rvals(*)
        end function

        integer function nf_put_var_double(ncid, varid, dvals)
            integer, intent(in)::                ncid, varid
            double precision, intent(in)::         dvals(*)
        end function

        !
        ! 変数の部分配列書き込み
        !

        integer function nf_put_vara_text(ncid, varid, &
        & start, count, text)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            character(len=*), intent(in)::        text
        end function

        integer function nf_put_vara_int1(ncid, varid, &
        & start, count, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer(NF_KIND_INT1), intent(in):: i1vals(*)
        end function

        integer function nf_put_vara_int2(ncid, varid, &
        & start, count, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer(NF_KIND_INT2), intent(in):: i2vals(*)
        end function

        integer function nf_put_vara_int(ncid, varid, &
        & start, count, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                 ivals(*)
        end function

        integer function nf_put_vara_real(ncid, varid, &
        & start, count, rvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            real, intent(in)::                         rvals(*)
        end function

        integer function nf_put_vara_double(ncid, varid, &
        start, count, dvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            double precision, intent(in)::         dvals(*)
        end function

        !
        ! 変数の標本配列書き込み
        !
        ! 各次元ごとに標本間隔 stride(i) ごとに書き込み点を選ぶ
        !

        integer function nf_put_vars_text(ncid, varid, &
        & start, count, stride, text)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            character(len=*), intent(in)::        text
        end function

        integer function nf_put_vars_int1(ncid, varid, &
        & start, count, stride, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            integer(NF_KIND_INT1), intent(in):: i1vals(*)
        end function

        integer function nf_put_vars_int2(ncid, varid, &
        & start, count, stride, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            integer(NF_KIND_INT2), intent(in):: i2vals(*)
        end function

        integer function nf_put_vars_int(ncid, varid, &
        & start, count, stride, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            integer, intent(in)::                 ivals(*)
        end function

        integer function nf_put_vars_real(ncid, varid, &
        & start, count, stride, rvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            real, intent(in)::                         rvals(*)
        end function

        integer function nf_put_vars_double(ncid, varid, &
        & start, count, stride, dvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            double precision, intent(in)::         dvals(*)
        end function

        !
        ! 変数の写像配列書き込み
        !
        ! 標本配列書き込み機能に加え次元を並べ替える機能が付く
        !

        integer function nf_put_varm_text(ncid, varid, &
        & start, count, stride, imap, text)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            character(len=*), intent(in)::        text
        end function

        integer function nf_put_varm_int1(ncid, varid, &
        & start, count, stride, imap, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            integer(NF_KIND_INT1), intent(in):: i1vals(*)
        end function

        integer function nf_put_varm_int2(ncid, varid, &
        & start, count, stride, imap, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            integer(NF_KIND_INT2), intent(in):: i2vals(*)
        end function

        integer function nf_put_varm_int(ncid, varid, &
        & start, count, stride, imap, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            integer, intent(in)::                 ivals(*)
        end function

        integer function nf_put_varm_real(ncid, varid, &
        & start, count, stride, imap, rvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            real, intent(in)::                         rvals(*)
        end function

        integer function nf_put_varm_double(ncid, varid, &
        & start, count, stride, imap, dvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            double precision, intent(in)::         dvals(*)
        end function


    !
    ! --- 変数の読み取り ---
    !

        !
        ! 変数の単要素読み取り
        !

        integer function nf_get_var1_text(ncid, varid, index, chval)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            character, intent(out)::                chval
        end function

        integer function nf_get_var1_int1(ncid, varid, index, i1val)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            integer(NF_KIND_INT1), intent(out):: i1val
        end function

        integer function nf_get_var1_int2(ncid, varid, index, i2val)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            integer(NF_KIND_INT2), intent(out):: i2val
        end function

        integer function nf_get_var1_int(ncid, varid, index, ival)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            integer, intent(out)::                 ival
        end function

        integer function nf_get_var1_real(ncid, varid, index, rval)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            real, intent(out)::                 rval
        end function

        integer function nf_get_var1_double(ncid, varid, index, dval)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                index(*)
            double precision, intent(out)::         dval
        end function

        !
        ! 変数の全体読み取り
        !

        integer function nf_get_var_text(ncid, varid, text)
            integer, intent(in)::                ncid, varid
            character(len=*), intent(out)::        text
        end function

        integer function nf_get_var_int1(ncid, varid, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer(NF_KIND_INT1), intent(out):: i1vals(*)
        end function

        integer function nf_get_var_int2(ncid, varid, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer(NF_KIND_INT2), intent(out):: i2vals(*)
        end function

        integer function nf_get_var_int(ncid, varid, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(out)::                 ivals(*)
        end function

        integer function nf_get_var_real(ncid, varid, rvals)
            integer, intent(in)::                ncid, varid
            real, intent(out)::                 rvals(*)
        end function

        integer function nf_get_var_double(ncid, varid, dvals)
            integer, intent(in)::                ncid, varid
            double precision, intent(out)::         dvals(*)
        end function

        !
        ! 変数の部分配列読み取り
        !

        integer function nf_get_vara_text(ncid, varid, &
        & start, count, text)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            character(len=*), intent(out)::        text
        end function

        integer function nf_get_vara_int1(ncid, varid, &
        & start, count, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer(NF_KIND_INT1), intent(out):: i1vals(*)
        end function

        integer function nf_get_vara_int2(ncid, varid, &
        & start, count, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer(NF_KIND_INT2), intent(out):: i2vals(*)
        end function

        integer function nf_get_vara_int(ncid, varid, &
        & start, count, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(out)::                 ivals(*)
        end function

        integer function nf_get_vara_real(ncid, varid, &
        & start, count, rvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            real, intent(out)::                 rvals(*)
        end function

        integer function nf_get_vara_double(ncid, varid, &
        start, count, dvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            double precision, intent(out)::         dvals(*)
        end function

        !
        ! 変数の標本配列読み取り
        !

        integer function nf_get_vars_text(ncid, varid, &
        & start, count, stride, text)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            character(len=*), intent(out)::        text
        end function

        integer function nf_get_vars_int1(ncid, varid, &
        & start, count, stride, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            integer(NF_KIND_INT1), intent(out):: i1vals(*)
        end function

        integer function nf_get_vars_int2(ncid, varid, &
        & start, count, stride, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            integer(NF_KIND_INT2), intent(out):: i2vals(*)
        end function

        integer function nf_get_vars_int(ncid, varid, &
        & start, count, stride, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            integer, intent(out)::                 ivals(*)
        end function

        integer function nf_get_vars_real(ncid, varid, &
        & start, count, stride, rvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            real, intent(out)::                 rvals(*)
        end function

        integer function nf_get_vars_double(ncid, varid, &
        & start, count, stride, dvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*)
            double precision, intent(out)::         dvals(*)
        end function

        !
        ! 変数の写像配列読み取り
        !

        integer function nf_get_varm_text(ncid, varid, &
        & start, count, stride, imap, text)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            character(len=*), intent(out)::        text
        end function

        integer function nf_get_varm_int1(ncid, varid, &
        & start, count, stride, imap, i1vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            integer(NF_KIND_INT1), intent(out):: i1vals(*)
        end function

        integer function nf_get_varm_int2(ncid, varid, &
        & start, count, stride, imap, i2vals)
            use dc_types
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            integer(NF_KIND_INT2), intent(out):: i2vals(*)
        end function

        integer function nf_get_varm_int(ncid, varid, &
        & start, count, stride, imap, ivals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            integer, intent(out)::                 ivals(*)
        end function

        integer function nf_get_varm_real(ncid, varid, &
        & start, count, stride, imap, rvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            real, intent(out)::                 rvals(*)
        end function

        integer function nf_get_varm_double(ncid, varid, &
        & start, count, stride, imap, dvals)
            integer, intent(in)::                ncid, varid
            integer, intent(in)::                start(*), count(*)
            integer, intent(in)::                stride(*), imap(*)
            double precision, intent(out)::         dvals(*)
        end function

    end interface
end module netcdf_f77
