! Copyright (C) GFD Dennou Club, 2001.  All rights reserved

subroutine anvarputreal(var, start, count, stride, imap, siz, value, iostat)
    use an_types, only: an_variable
    use an_vartable, only: an_variable_entry, vtable_lookup
    use netcdf_f77, only: nf_noerr, nf_einval, nf_put_varm_real
    use an_file, only: anfiledatamode
    use dc_trace, only: beginsub, endsub, DbgMessage
    implicit none
    type(an_variable), intent(in):: var
    integer, intent(in):: start(:)
    integer, intent(in):: count(:)
    integer, intent(in):: stride(:)
    integer, intent(in):: imap(:)
    integer, intent(in):: siz
    real, intent(in):: value(siz)
    integer, intent(out):: iostat
    integer:: ndims
    type(an_variable_entry):: ent
    character(len = *), parameter:: subname = "anvarputreal"
continue
    call beginsub(subname)
    iostat = vtable_lookup(var, ent)
    if (iostat /= nf_noerr) goto 999
    ndims = 0
    if (associated(ent%dimids)) ndims = size(ent%dimids)
    if (min(size(start), size(count), size(stride), size(imap)) < ndims) then
        iostat = nf_einval
        goto 999
    endif
    call DbgMessage("f=%d v=%d sta=%*d c=%*d str=%*d imap=%*d", &
        & i=(/ent%fileid, ent%varid, start, count, stride, imap/), &
        & n=(/ndims, ndims, ndims, ndims/))
    iostat = anfiledatamode(ent%fileid)
    if (iostat /= nf_noerr) return
    iostat = nf_put_varm_real(ent%fileid, ent%varid, &
        & start, count, stride, imap, value)
999 continue
    call endsub(subname, "iostat=%d", i=(/iostat/))
end subroutine
