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) ! filetype = 0, hdf5 ! filetype = 1, ascii ! filetype = 2, binary or unknown ! filetype = -1, unknown 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, isascii 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) filetype = MAPL_FILETYPE_UNK ! Unknown typehdf5 = .true. do i = 1, 8 if (iachar(TwoWords(i)) /= hdf5(i)) then typehdf5 = .false. exit end if end do if (typehdf5) then filetype = MAPL_FILETYPE_NC4 _RETURN(ESMF_SUCCESS) end if isascii = .true. do i = 1, 4 if (iachar(TwoWords(i)) < 7) then isascii = .false. exit end if end do if (isascii) then filetype = MAPL_FILETYPE_TXT _RETURN(ESMF_SUCCESS) endif filetype = MAPL_FILETYPE_BIN _RETURN(ESMF_SUCCESS) 100 continue _RETURN(ESMF_FAILURE) end subroutine MAPL_NCIOGetFileType