Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | filename | |||
integer, | intent(inout) | :: | filetype | |||
integer, | intent(out), | optional | :: | RC |
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