if(~(dp>0) & ~(dp<0) ) disp('NaN'); return; end
if(dp<1d-4) break; end
could be written as
if isnan(dp), disp('NaN'); return; end
if(dp<1E-4), break; end
'd' for the exponent letter is MATLAB carryover from Fortran syntax; "e" is single precision, "d" is double. MATLAB uses default double precision for all numeric values unless specifically cast to something else and "e" is interpreted the same as "d". Upper/lower case are also allowable and mean the same; I think written as a literal constant the uppercase is more legible but it's personal taste.
In Fortran, however, the two forms are different -- 1.0E-4 is a single precision value; 1.0D-4 is double precision. For values which can be represented identically as the above, the end result on assignment is the same; numbers which are not, however, like 0.2, are in fact different if stored in a double precision variable. The D form will have full precision; the E form will be a single precision result zero-extended to double; it will still have the single precision precision stored in the double variable.
However, unlike Fortran, MATLAB and C i/o does not support the "dD" form for double precision constants other than as literal constants in source code as written above.
NB: the constant written with D fails with either floating point format string.
The writer of the above code would appear to have had a FORTRAN background and to not be terribly familiar with MATLAB syntax.
ADDENDUM: Or perhaps the code was translated from old FORTRAN, maybe, and just implemented verbatim on a line-by-line basis.