Re: Can't find the end of a text file [message #83114] |
Wed, 06 February 2013 11:26 |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
I might convert the string to bytes and look for control characters. For example, when IDL prints a blank line, is it really blanks (32B) or is it a line feed (10b) or carriage return (13b)? Possibly your editor ignores the control characters but IDL doesn't -- just a guess. --Wayne
On Wednesday, February 6, 2013 1:30:01 PM UTC-5, kisCA wrote:
> I already try to do as you suggest: reading lines as a string but that is where the "extra" weird blank line I told you about in my first post come in ...
|
|
|
|
Re: Can't find the end of a text file [message #83121 is a reply to message #83119] |
Wed, 06 February 2013 10:00  |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
The way your code is written, IDL will try to read 7 numbers, even if it has to continue over multiple lines. So if your file has 7 numbers per line, and ends in a blank line, then IDL will give an "end of file" error, since it can't read 7 numbers in the last line.
I would read each line into string, to be sure you are reading one line at time.
--Wayne
P.S. I would suggest the following coding changes for the loop -- the most important change being subscripting with square brackets!
while ~EOF(Unit) do begin
readf,Unit,temp
data[0,count]=temp
count++
endwhile
On Wednesday, February 6, 2013 12:13:59 PM UTC-5, kisCA wrote:
> Hi there,
>
> I got a weird problem. I am trying to read a text file with a six lines header and then a number of lines that I tried to know with:
>
> count=0
>
> mxnum=7000
>
> temp=fltarr(7)
>
> data=fltarr(7,mxnum)
>
> while EOF(Unit) eq 0 do begin
>
> readf,Unit,temp
>
> data(*,count)=temp(*)
>
> count=count+1
>
> endwhile
>
> In the middle of the loop, I got this error
>
> READF: End of file encountered.
>
>
>
> The problem is solved when I delete the last empty line of the file.
>
> And by the way, when I read and print line by line there is an empty line every two lines that I don't see when I open the file with Notepad.
>
>
>
> Anyone had this problem before ?
>
>
>
> Thank you for your help
|
|
|