MAPL_NCIOGetFileType Subroutine

public subroutine MAPL_NCIOGetFileType(filename, filetype, RC)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filename
integer, intent(inout) :: filetype
integer, intent(out), optional :: RC

Calls

proc~~mapl_nciogetfiletype~~CallsGraph proc~mapl_nciogetfiletype MAPL_NCIOGetFileType proc~mapl_return MAPL_Return proc~mapl_nciogetfiletype->proc~mapl_return proc~mapl_verify MAPL_Verify proc~mapl_nciogetfiletype->proc~mapl_verify at at proc~mapl_return->at insert insert proc~mapl_return->insert proc~mapl_throw_exception MAPL_throw_exception proc~mapl_return->proc~mapl_throw_exception proc~mapl_verify->proc~mapl_throw_exception

Called by

proc~~mapl_nciogetfiletype~~CalledByGraph proc~mapl_nciogetfiletype MAPL_NCIOGetFileType proc~mapl_esmfstatereadfromfile MAPL_ESMFStateReadFromFile proc~mapl_esmfstatereadfromfile->proc~mapl_nciogetfiletype proc~mapl_genericinitialize MAPL_GenericInitialize proc~mapl_genericinitialize->proc~mapl_esmfstatereadfromfile proc~mapl_genericrefresh MAPL_GenericRefresh proc~mapl_genericrefresh->proc~mapl_esmfstatereadfromfile proc~mapl_genericrefresh->proc~mapl_genericrefresh proc~mapl_genericstaterestore MAPL_GenericStateRestore proc~mapl_genericstaterestore->proc~mapl_esmfstatereadfromfile proc~mapl_genericstaterestore->proc~mapl_genericstaterestore

Source Code

  subroutine MAPL_NCIOGetFileType(filename,filetype,rc)
   implicit none

   ! Arguments
   !----------
   character(len=*),  intent(IN   ) :: filename
   integer,           intent(INOUT) :: filetype
   integer, optional, intent(  OUT) :: RC

   ! ErrLog variables
   !-----------------

   integer                      :: STATUS

   character(len=1)             :: word(4)
   character(len=1)             :: TwoWords(8)
   integer, parameter           :: hdf5(8) = (/137, 72, 68, 70, 13, 10, 26, 10 /)
   integer                      :: irec
   integer                      :: unit
   integer                      :: i, cwrd
   logical                      :: typehdf5
   character(len=12)            :: fmt

   INQUIRE(IOLENGTH=IREC) WORD
   open (NEWUNIT=UNIT, FILE=FILENAME, FORM='unformatted', ACCESS='DIRECT', RECL=IREC, IOSTAT=status)
   _VERIFY(STATUS)

! Read first 8 characters and compare with HDF5 signature
   read (UNIT, REC=1, ERR=100) TwoWords(1:4)
   read (UNIT, REC=2, ERR=100) TwoWords(5:8)
   close(UNIT)

   typehdf5 = .true.
   filetype = -1 ! Unknown

   do i = 1, 8
      if (iachar(TwoWords(i)) /= hdf5(i)) then
         typehdf5 = .false.
         exit
      end if
   end do
   if (typehdf5) then
      filetype = 0 ! HDF5
      _RETURN(ESMF_SUCCESS)

   end if
   ! Attempt to identify as fortran binary
   cwrd = transfer(TwoWords(1:4), irec)
   ! check if divisible by 4
   irec = cwrd/4
   filetype = irec
   if (cwrd /= 4*irec) then
      _RETURN(ESMF_FAILURE)
   end if

   filetype = -1
   _RETURN(ESMF_SUCCESS)

100   continue
   _RETURN(ESMF_FAILURE)

  end subroutine MAPL_NCIOGetFileType