Unhelpful error message when setting logic variable incorrectly in inlist
While completing Earl Bellinger's Maxilab during the summer school, I incorrectly set the relax_initial_z and relax_initial_y variables (logic variables) to be floating point values in my inlist. I now know that this is because they are logic variables, but the following error was not very illustrative of the problem:
Failed while trying to read control namelist file: inlist_project
Perhaps the following runtime error message will help you find the problem.
At line 603 of file ../private/star_job_ctrls_io.f90
Fortran runtime error: Bad repeat count in item 3 of list input
Error termination. Backtrace:
#0 0x13b4ddde7
#1 0x13b4de997
#2 0x13b4df273
#3 0x13b5bfed3
#4 0x13b5c1183
#5 0x13b5c322f
#6 0x13b5c3f1f
#7 0x13b5cc1a3
#8 0x13b5cc457
#9 0x1035016cf
#10 0x103501b07
#11 0x103501d2b
#12 0x10350b0a3
#13 0x10351dad7
#14 0x10351d8e3
#15 0x102f80f83
#16 0x102f80fe7
Only raising this as an issue to see if is possible to improve the clarity of the error message.
Inlists and models Here is an example of the section of the inlist that caused the error:
&star_job
pgstar_flag = .true.
pause_before_terminate = .true.
relax_initial_z = 0.01 ! should be true/false
relax_initial_y = 0.01 ! should be true/false
new_z = 0.001
new_y = 0.2483
/
Only raising this as an issue to see if is possible to improve the clarity of the error message.
Possible? Probably. Worth the effort? I don't think so. With built-in functions, MESA can only infer whether the call to read the inlist worked. If not, it just calls it again and lets the runtime error stop the program. The part you see starting "At line 603..." is the compiler-dependent runtime error, not something that MESA is itself coded to output.
The lines
At line 603 of file ../private/star_job_ctrls_io.f90
Fortran runtime error: Bad repeat count in item 3 of list input
are somewhat helpful. The item number says which entry in the namelist causes the problems. Because each namelist is read by source in a different file, that and the preceding line together say that the problem is the third item in &star_job.
I don't think we can detect the specific problem (float instead of logical) unless we write a routine to parse the inlists or namelists ourselves, rather than using the built-in Fortran functions. That sounds like a lot of work that I don't think is worth it.
Seems like https://degenerateconic.com/namelist-error-checking.html suggest we could do:
read(iunit, nml=my_namelist, iostat=istat)
if (istat/=0) then
backspace(iunit)
read(iunit,fmt='(A)') line
write(error_unit,'(A)') &
'Invalid line in namelist: '//trim(line)
end if
To get an error like:
Invalid line in namelist: d = 3.0,
Basically we catch the error in istat, rewind one record backwards, and read the line in again manually. We wouldn't be able to tell why it failed but at least it would be clearer where it failed.