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

Home » Public Forums » archive » Re: Strange behavior of function READ in a loop.
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: Strange behavior of function READ in a loop. [message #81541] Tue, 25 September 2012 10:46
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On Tuesday, September 25, 2012 1:10:45 PM UTC-4, Gerry Yu wrote:
> Hello everyone:
>
> I got a strange output with the function READ in a loop.
>
> A simplified example is as below:
>
> _______________________
>
> pro test
>
> print, "This is the first line.", format="(A30/)"
>
> for i=1,3 do begin
>
> read, a ,PROMPT="input:"
>
> print, i,": input is ",a
>
> endfor
>
> end
>
> ______________________________
>
> The expected output should be something like:
>
> ______________________________
>
> This is the first line.
>
> input:1
>
> 1: input is 1.0000
>
> input:2
>
> 2: input is 2.0000
>
> input:3
>
> 3: input is 3.0000
>
> ____________________________
>
> But what I get is (with IDL 7.1.1 on Win 7):
>
> ____________________________
>
> input:1
>
> This is the first line.
>
> input:2
>
>
>
> 1: input is 1.00000
>
> input:3
>
> 2: input is 2.00000
>
> 3: input is 3.00000
>
> _________________________________
>
> I am really confused by such a result.
>
> Do someone know what happens here?
>
>

Hi,

I don't have IDL hand test this out, but this looks like a buffering issue. Could you try adding the FLUSH command to your routine.

http://idlastro.gsfc.nasa.gov/idl_html_help/FLUSH.html

I think the command line is unit -1.

pro test
print, "This is the first line.", format="(A30/)"
for i=1,3 do begin
read, a ,PROMPT="input:"
print, i,": input is ",a
flush, -1
endfor
end

Cheers,
Ben
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Strange behavior of function READ in a loop.
Next Topic: read an irregularly structured ascii file.

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

Current Time: Wed Oct 08 15:10:53 PDT 2025

Total time taken to generate the page: 0.00475 seconds