comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Problem reading data from stdin using EOF(0) in version 6.0 and 7.0
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Problem reading data from stdin using EOF(0) in version 6.0 and 7.0 [message #64395] Mon, 22 December 2008 07:52 Go to next message
Allan Whiteford is currently offline  Allan Whiteford
Messages: 117
Registered: June 2006
Senior Member
kiwing.to@gmail.com wrote:
> I am not sure if the EOF() function in IDL version newer than 5.2
> really has some problem or some setting has to be adjusted.
>
> I just want to read data from the stdin and automatically stop at
> the end-of-file. The following codes work for version 5.2 but not
> for version 6.0 nor version 7.0.
>
> Just want to know if anyway around it ?
>
> #######################
> ;--- test_eof.pro -----------------
> pro test_eof
> a=float(1)
> while not eof(0) do begin
> read, a
> print, a
> endwhile
> end
> ;---- end of 'test_eof.pro' -----
>
> #######################
> ;---- test_eof.idl ----------------
> .compile test_eof
> .run test_eof
> exit
> ;---- end of 'test_eof.idl' ------
> #######################
>
> When I ran it using "idl test_eof.idl"
> I got error at the end of my input.
>
> ############################################################ #
> IDL Version 7.0 (linux x86 m32). (c) 2007, ITT Visual Information
> Solutions
> Installation number: 60188.
> Licensed for use by: Academia Sinica
>
> % Compiled module: $MAIN$.
> % Compiled module: $MAIN$.
> : 1
> 1.00000
> : 2
> 2.00000
> : ^D
> % READ: Error encountered reading from file. Unit: 0
> File: <stdin>
> % Execution halted at: $MAIN$ 3 /home/ericto/test_eof.pro
> ############################################################ ##

You can't check for eof(0) when you're giving input from the keyboard.

It can't know what you're going to type next so it returns a 0 and then
control passes to your "read, a" statement which subsequently fails when
you pass it an EOF character. The eof function never gets to see that
you typed Ctrl-D.

If you read from a file like this:

idl test_eof.idl < file.dat

then all will be well.

I don't know why it worked on IDL5.2 - I can only find versions 5.1 and
5.3 (typical!) and in both of them I see the same behaviour.

Maybe in IDL5.2 the EOF function detected it was attached to a keyboard
and blocked until it got another byte from the keyboard? It seems
unlikely but I think that's the only way the above example would have
worked in 5.2.

Thanks,

Allan
Re: Problem reading data from stdin using EOF(0) in version 6.0 and 7.0 [message #64404 is a reply to message #64395] Mon, 22 December 2008 00:32 Go to previous messageGo to next message
Wout De Nolf is currently offline  Wout De Nolf
Messages: 194
Registered: October 2008
Senior Member
On Sun, 21 Dec 2008 03:48:31 -0800 (PST), "kiwing.to@gmail.com"
<kiwing.to@gmail.com> wrote:

> % Compiled module: $MAIN$.
> % Compiled module: $MAIN$.
> : 1
> 1.00000
> : 2
> 2.00000
> : ^D
> % READ: Error encountered reading from file. Unit: 0
> File: <stdin>
> % Execution halted at: $MAIN$ 3 /home/ericto/test_eof.pro
> ############################################################ ##


I works for me (IDL7.0 Windows x86_64), except for the fact that there
is no way of stopping the loop. Does it always happen after the third
line and what was the character you used (^D)?
Re: Problem reading data from stdin using EOF(0) in version 6.0 and 7.0 [message #64456 is a reply to message #64395] Wed, 24 December 2008 00:15 Go to previous message
kiwing.to@gmail.com is currently offline  kiwing.to@gmail.com
Messages: 2
Registered: December 2008
Junior Member
On 12月22日, 下午11時52分, Allan Whiteford
<allan.rem...@phys.remove.strath.ac.remove.uk> wrote:
> kiwing...@gmail.com wrote:
>> I am not sure if theEOF() function in IDL version newer than 5.2
>> really has some problem or some setting has to be adjusted.
>
>> I just want to read data from the stdin and automatically stop at
>> the end-of-file. The following codes work for version 5.2 but not
>> for version 6.0 nor version 7.0.
>
>> Just want to know if anyway around it ?
>
>> #######################
>> ;--- test_eof.pro -----------------
>> pro test_eof
>> a=float(1)
>> while noteof(0) do begin
>> read, a
>> print, a
>> endwhile
>> end
>> ;---- end of 'test_eof.pro' -----
>
>> #######################
>> ;---- test_eof.idl ----------------
>> .compile test_eof
>> .run test_eof
>> exit
>> ;---- end of 'test_eof.idl' ------
>> #######################
>
>> When I ran it using "idl test_eof.idl"
>> I got error at the end of my input.
>
>> ############################################################ #
>> IDL Version 7.0 (linux x86 m32). (c) 2007, ITT Visual Information
>> Solutions
>> Installation number: 60188.
>> Licensed for use by: Academia Sinica
>
>> % Compiled module: $MAIN$.
>> % Compiled module: $MAIN$.
>> : 1
>> 1.00000
>> : 2
>> 2.00000
>> : ^D
>> % READ: Error encountered reading from file. Unit: 0
>> File: <stdin>
>> % Execution halted at: $MAIN$ 3 /home/ericto/test_eof.pro
>> ############################################################ ##
>
> You can't check foreof(0) when you're giving input from the keyboard.
>
> It can't know what you're going to type next so it returns a 0 and then
> control passes to your "read, a" statement which subsequently fails when
> you pass it anEOFcharacter. Theeoffunction never gets to see that
> you typed Ctrl-D.
>
> If you read from a file like this:
>
> idl test_eof.idl < file.dat
>
> then all will be well.
>
> I don't know why it worked on IDL5.2 - I can only find versions 5.1 and
> 5.3 (typical!) and in both of them I see the same behaviour.
>
> Maybe in IDL5.2 theEOFfunction detected it was attached to a keyboard
> and blocked until it got another byte from the keyboard? It seems
> unlikely but I think that's the only way the above example would have
> worked in 5.2.
>
> Thanks,
>
> Allan

Dear Allan,

Thanks for your information. I tried your suggestion :

idl test_eof.idl < datafile

and it works in version 5.2 as well as version 7.0

However, when it is used as filter, like the following command :

cat datafile | idl test_eof.idl

it only works in version 5.2 but not in version 7.0.

some error reported :

% READ: End of file encountered. Unit: 0, File: <stdin>
% Execution halted at: $MAIN$

Any comments and suggestions are welcomed.

Thanks again.

;---- file : test_eof.idl ----
while not eof(0) do begin & read, a & print, a & endwhile
exit
;---- end of test_eof.idl ----
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Approximate convolution - for loop problem
Next Topic: inverse gradient

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:55:00 PDT 2025

Total time taken to generate the page: 0.00609 seconds