I am having issues with the file_lines()
function in IDL. I have a ASCII data file which has 27000 lines as I have verified within an emacs buffer and using the command grep -c "."
; however, file_lines()
returns a value of 81807 lines. The function is equivalent to this code (http://idlastro.gsfc.nasa.gov/idl_html_help/FILE_LINES.html)
FUNCTION file_lines, filename
OPENR, unit, filename, /GET_LUN
str = ''
count = 0ll
WHILE ~ EOF(unit) DO BEGIN
READF, unit, str
count = count + 1
ENDWHILE
FREE_LUN, unit
RETURN, count
END
My first instinct was that my rather long lines (max 231 characters) were truncating do to a limitation in the number of characters for an IDL string variable, but this does not seem to be the case as an IDL string can supposedly hold 2147483647 (2.1 GB) characters in length (http://idlastro.gsfc.nasa.gov/idl_html_help/Overview_of_Strings.html)
Any suggestions as to what might be wrong?
Your code works as expected on my linux system for a 27000 line input file, no matter the line length. Probably your file has non-ascii character codes: if you run your file_lines function on a small binary file, say /bin/bash
, you get a different answer than with grep -c "." /bin/bash
, or even wc -l /bin/bash
.