Hello,
I am trying to run an exercise using the mgdraw user routine from a FLUKA advanced course. The goal is to prepare a phase-space file containing antiproton parameters for a subsequent simulation. The required logic is relatively simple, but I am encountering an issue with Fortran formatting.
When I try to write only the two variables JTRACK and ETRACK, the program works fine:
ENTRY BXDRAW ( ICODE, MREG, NEWREG, XSCO, YSCO, ZSCO )
if (lfirst) then
call geon2r('ADTrgTi ', from_reg, ierr)
call geon2r('ADTrgDs ', to_reg, ierr)
OPEN(UNIT=99, FILE='aprots.txt', STATUS='UNKNOWN')
lfirst = .false.
end if
if (MREG == from_reg .and. NEWREG == to_reg .and. JTRACK == 1) then
write(99,'(I3,E15.7)') INT(JTRACK),SNGL(ETRACK)
end if
RETURN
but if I add any other variable to write, e.g. XTRACK:
write(99,'(I3,2E15.7)') INT(JTRACK),SNGL(ETRACK),SNGL(XTRACK)
end if
RETURN
the program ends up with a runtime error:
At line 83 of file mgdraw_ex1.f (unit = 99, file = 'aprots.txt')
Fortran runtime error: Expected INTEGER for item 4 in formatted transfer, got REAL
(I3,2E15.7)
^
The error indicates that item #4 is expected to be an integer, even though there does not appear to be a fourth item.
Using * instead of '(I3,2E15.7)' also works, but then the output file is not written with the correct formatting.
Could you please suggest what I am doing wrong and why this error occurs?
I am not very experienced in Fortran programming so I am somewhat stuck.
FLUKA: 4-5.2
Flair: 3.4-5.3
Operating system: ubuntu 24.04 LTS
mgdraw_ex1.f (10.5 KB)