Yes, you can read the entire line into a string. Then parse the string and replace the "NAN" with some special numeric value such as a large negative value. The intrinsic functions can help, e.g., index
. Then use an "internal read" to read from the string into the numeric variables.
See: Reading comment lines correctly in an input file using Fortran 90, Reading format in Fortran 90 and Prevent FORTRAN from closing when a character is inputed instead of a number