SUBROUTINE BDI_TYPE( ID, TYPE, STATUS )
*+
*  Name:
*     BDI_TYPE

*  Purpose:
*     Determine basic data type of a primitive or BinDS derived object

*  Language:
*     Starlink Fortran

*  Invocation:
*     CALL BDI_TYPE( ID, TYPE, STATUS )

*  Description:
*     {routine_description}

*  Arguments:
*     ID = INTEGER (given)
*        ADI identifier of file object
*     TYPE = CHARACTER*(*) (returned)
*        Basic data type of file object
*     STATUS = INTEGER (given and returned)
*        The global status.

*  Examples:
*     {routine_example_text}
*        {routine_example_description}

*  Pitfalls:
*     {pitfall_description}...

*  Notes:
*     {routine_notes}...

*  Prior Requirements:
*     {routine_prior_requirements}...

*  Side Effects:
*     {routine_side_effects}...

*  Algorithm:
*     {algorithm_description}...

*  Accuracy:
*     {routine_accuracy}

*  Timing:
*     {routine_timing}

*  External Routines Used:
*     {name_of_facility_or_package}:
*        {routine_used}...

*  Implementation Deficiencies:
*     {routine_deficiencies}...

*  {machine}-specific features used:
*     {routine_machine_specifics}...

*  {DIY_prologue_heading}:
*     {DIY_prologue_text}

*  References:
*     BDI Subroutine Guide : http://www.sr.bham.ac.uk/asterix-docs/Programmer/Guides/bdi.html

*  Keywords:
*     package:bdi, usage:public

*  Copyright:
*     Copyright (C) University of Birmingham, 1995

*  Authors:
*     DJA: David J. Allan (Jet-X, University of Birmingham)
*     {enter_new_authors_here}

*  History:
*     16 Jan 1995 (DJA):
*        Original version.
*     {enter_changes_here}

*  Bugs:
*     {note_any_bugs_here}

*-
      
*  Type Definitions:
      IMPLICIT NONE              ! No implicit typing

*  Global Constants:
      INCLUDE 'SAE_PAR'          ! Standard SAE constants
      INCLUDE 'DAT_PAR'

*  Arguments Given:
      INTEGER			ID			! File identifier

*  Arguments Returned:
      CHARACTER*(*)		TYPE			! Basic data type

*  Status:
      INTEGER 			STATUS             	! Global status

*  Local Variables:
      CHARACTER*(DAT__SZLOC)	LOC			! HDS file handle

      LOGICAL			PRIM			! Object is primitive?
      LOGICAL			THERE			! Component exists?
*.

*  Check inherited global status.
      IF ( STATUS .NE. SAI__OK ) RETURN

*  When the HDS/FITS interface is done properly, reinstate this line, and
*  delete the rest
C      CALL ADI_CGET0C( ID, 'TYPE', STATUS )

*  Get locator
      CALL ADI1_GETLOC( ID, LOC, STATUS )

*  Primitive?
      CALL DAT_PRIM( LOC, PRIM, STATUS )
      IF ( PRIM ) THEN
        CALL DAT_TYPE( LOC, TYPE, STATUS )

      ELSE
        CALL DAT_THERE( LOC, 'DATA_ARRAY', THERE, STATUS )
        IF ( THERE ) THEN
          CALL CMP_TYPE( LOC, 'DATA_ARRAY', TYPE, STATUS )
        ELSE 
          STATUS = SAI__ERROR
          CALL ERR_REP( ' ', 'Unable to obtain basic data type '/
     :                  /'from this object', STATUS )
        END IF

      END IF

*  Report any errors
      IF ( STATUS .NE. SAI__OK ) CALL AST_REXIT( 'BDI_TYPE', STATUS )

      END