integer function FindPopsfileVersion(iunithead)
integer, intent(in) :: iunithead
integer :: stat
character(255) :: FirstLine
! Default value
tRealPOPSfile = .true.
if (iProcIndex == root) then
rewind (iunithead)
read (iunithead, '(a255)') FirstLine
if (index(FirstLine, 'VERSION') == 0) then
FindPopsfileVersion = 1
else
rewind (iunithead)
read (iunithead, *) FirstLine, FirstLine, FirstLine, FindPopsfileVersion
endif
! We need to be able to deal with popsfiles created with the
! (old) integer version of the code
! --> No direct option was included for the output files to
! indicate if they used integers or real coefficients
! --> We need to take a (slight) guess...
if (FindPopsfileVersion == 4 .and. tBinPops) then
do while (.true.)
! Read until the end of the file.
read (iunithead, '(a255)', iostat=stat) FirstLine
if (stat < 0) exit
! If we have the line with PopSumNoatHF in it, check if
! the reported number is a real number. If it is, we know
! the popsfile was created by the realcoeff branch.
if (index(FirstLine, 'PopSumNoatHF=') /= 0) then
if (index(FirstLine, '.') /= 0) then
tRealPOPSfile = .true.
else
tRealPOPSfile = .false.
end if
exit
end if
end do
! Rewind to allow normal reading of the header.
rewind (iunithead)
read (iunithead, *) FirstLine, FirstLine, FirstLine, FindPopsfileVersion
end if
endif
call MPIBCast(FindPopsfileVersion)
call MPIBcast(tRealPOPSfile)
end function FindPopsfileVersion