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

SUBROUTINE GTVARPUTDOUBLE(VAR, VALUE, NVALUE, ERR)
    USE GTDATA_TYPES, ONLY: GT_VARIABLE
    USE GT_MAP, ONLY: VAR_CLASS, VTB_CLASS_NETCDF, &
        & MAP_TO_INTERNAL_SPECS
    USE AN_GENERIC, ONLY: PUT, AN_VARIABLE
    USE DC_ERROR
    USE DC_TRACE, ONLY: BEGINSUB, ENDSUB
    IMPLICIT NONE
    TYPE(GT_VARIABLE), INTENT(IN):: VAR
    INTEGER, INTENT(IN):: NVALUE
    DOUBLE PRECISION, INTENT(IN):: VALUE(NVALUE)
    LOGICAL, INTENT(OUT), OPTIONAL:: ERR
    INTEGER:: CLASS, CID, STAT, NDIMS
    INTEGER, POINTER:: SPECS(:, :)
    CHARACTER(LEN = *), PARAMETER:: SUBNAME = "GTVARPUTDOUBLE"
CONTINUE
    CALL BEGINSUB(SUBNAME, 'VAR.MAPID=%d', I=(/VAR%MAPID/))
    CALL VAR_CLASS(VAR, CLASS, CID)
    CALL MAP_TO_INTERNAL_SPECS(VAR, SPECS, NDIMS)
    IF (CLASS == VTB_CLASS_NETCDF) THEN
        CALL PUT(AN_VARIABLE(CID), START=SPECS(:, 1), COUNT=SPECS(:, 2), &
            & STRIDE=SPECS(:, 3), IMAP=SPECS(:, 4), VALUE=VALUE, &
            & SIZ=NVALUE, IOSTAT=STAT)
    ELSE
        STAT = GT_EFAKE
    ENDIF
    CALL STOREERROR(STAT, "gtvarputDOUBLE", ERR=ERR)
    DEALLOCATE(SPECS)
    CALL ENDSUB(SUBNAME)
END SUBROUTINE
