file_lines() 函数有问题吗?
我在使用 IDL 中的 file_lines()
函数时遇到问题。我有一个 ASCII 数据文件,其中有 27000 行,我已在 emacs 缓冲区中使用命令 grep -c "."
进行了验证;但是,file_lines()
返回 81807 行的值。该功能相当于此代码(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
我的第一直觉是我相当长的行(最多 231 个字符)被截断为限制数量IDL 字符串变量的字符数,但情况似乎并非如此,因为 IDL 字符串的长度据称可以容纳 2147483647 (2.1 GB) 个字符(http://idlastro.gsfc.nasa.gov/idl_html_help/Overview_of_Strings.html)
对于可能出现的问题有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 27000 行输入文件,您的代码在我的 Linux 系统上按预期工作,无论行长度如何。可能您的文件具有非 ascii 字符代码:如果您在一个小二进制文件(例如
/bin/bash
)上运行 file_lines 函数,您会得到与grep -c " 不同的答案。 ” /bin/bash
,甚至是wc -l /bin/bash
。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 withgrep -c "." /bin/bash
, or evenwc -l /bin/bash
.