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

subroutine GTVarGetReal(var, value, nvalue, err)
    use gtdata_types, only: gt_variable
    use gt_map, only: var_class, vtb_class_netcdf, &
        & map_to_internal_specs, gtvar_dump
    use an_generic, only: get, an_variable
    use dc_trace, only: beginsub, endsub
    use dc_error
    implicit none
    type(gt_variable), intent(inout)        :: var
    real,              intent(out)          :: value(*)
    integer,           intent(in)           :: nvalue
    logical,           intent(out), optional:: err
    integer:: class, cid, stat
    integer, pointer:: specs(:, :)
    call var_class(var, class, cid)
    call beginsub('GTVarGetReal')
    call gtvar_dump(var)
    call map_to_internal_specs(var, specs)
    if (class == vtb_class_netcdf) then
        call get(an_variable(cid), start=specs(:, 1), count=specs(:, 2), &
            & stride=specs(:, 3), imap=specs(:, 4), siz=nvalue, value=value, &
            & iostat=stat)
    else
        stat = gt_efake
    endif
    if (associated(specs)) deallocate(specs)
    call storeerror(stat, "GTVarGetReal", err)
    call endsub('GTVarGetReal', 'stat=%d', i=(/stat/))
end subroutine
