Re: Printing to command line without a new line [message #78217] |
Thu, 03 November 2011 01:56 |
Nikola
Messages: 53 Registered: November 2009
|
Member |
|
|
Here is another nice example of how to show progress.
PRO PROGRESS, MSG, CUR, MAX
WRITEU, -1, STRING(FORMAT='(%"\R",A,": ",I3,"%")', $
MSG, ROUND(FLOAT(CUR)/MAX*100))
IF CUR EQ MAX THEN PRINT, ''
END
Cheers, NV
|
|
|
Re: Printing to command line without a new line [message #78218 is a reply to message #78217] |
Wed, 02 November 2011 22:15  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Nov 2, 3:19 pm, "jasmeervir...@gmail.com" <jasmeervir...@gmail.com>
wrote:
> On Nov 2, 6:48 pm, David Fanning <n...@dfanning.com> wrote:
>
>
>
>
>
>
>
>
>
>> jasmeervir...@gmail.com writes:
>>> I have a fairly simple question.
>>> My code takes a fair amount of time to run and I would like
>>> it to display a percentage number which updates to the
>>> command line without starting a new line.
>
>>> So using print one usually does:
>
>>> for i=0, 100-1, 1 do print, i, '%'
>
>>> but this creates a long list of numbers. How can I stop a newline
>>> being created by the print command
>
>>> I hope this is clear. Does anyone know how to do this?
>
>> http://www.idlcoyote.com/fileio_tips/lfsuppress.html
>
>> Like this:
>
>> IDL> for i=0, 15 do print, i, format='((x, I0),$)'
>> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Hi,
>
> Thanks for the response.
>
> It wasn't quite what I was looking for. This prints all the numbers in
> the for loop
> on a single line but what I want is the previous number to disappear
> and
> be replaced by the new number, so that I have one number which is
> constantly updated.
Greetings-- This is why I invented STATUSLINE!
Craig
P.S. It can be found here:
http://www.physics.wisc.edu/~craigm/idl/misc.html
|
|
|
Re: Printing to command line without a new line [message #78219 is a reply to message #78218] |
Wed, 02 November 2011 14:19  |
Russell[1]
Messages: 101 Registered: August 2011
|
Senior Member |
|
|
You need to use the C-style printing and use the ANSI escape
sequences. Here's a quick script I used, based on ITT's examples.
pro inline_print
for i=0,10 do begin
ii=strcompress(string(i,f='(I3)'),/rem)
print,f='(%"\33[1M I have %s monkeys\33[1A")',ii
wait,0.1
endfor
print,''
end
On Nov 2, 2:19 pm, "jasmeervir...@gmail.com" <jasmeervir...@gmail.com>
wrote:
> Hi all,
>
> I have a fairly simple question.
> My code takes a fair amount of time to run and I would like
> it to display a percentage number which updates to the
> command line without starting a new line.
>
> So using print one usually does:
>
> for i=0, 100-1, 1 do print, i, '%'
>
> but this creates a long list of numbers. How can I stop a newline
> being created by the print command
>
> I hope this is clear. Does anyone know how to do this?
>
> Cheers
|
|
|
Re: Printing to command line without a new line [message #78220 is a reply to message #78219] |
Wed, 02 November 2011 14:23  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 11/2/11 1:19 PM, jasmeervirdee@gmail.com wrote:
> On Nov 2, 6:48 pm, David Fanning<n...@dfanning.com> wrote:
>> jasmeervir...@gmail.com writes:
>>> I have a fairly simple question.
>>> My code takes a fair amount of time to run and I would like
>>> it to display a percentage number which updates to the
>>> command line without starting a new line.
>>
>>> So using print one usually does:
>>
>>> for i=0, 100-1, 1 do print, i, '%'
>>
>>> but this creates a long list of numbers. How can I stop a newline
>>> being created by the print command
>>
>>> I hope this is clear. Does anyone know how to do this?
>>
>> http://www.idlcoyote.com/fileio_tips/lfsuppress.html
>>
>> Like this:
>>
>> IDL> for i=0, 15 do print, i, format='((x, I0),$)'
>> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
>>
>> Cheers,
>>
>> David
>>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Hi,
>
> Thanks for the response.
>
> It wasn't quite what I was looking for. This prints all the numbers in
> the for loop
> on a single line but what I want is the previous number to disappear
> and
> be replaced by the new number, so that I have one number which is
> constantly updated.
>
> Cheers
>
>
If you are on a terminal that supports ANSI escape sequences, i.e., not
the Workbench, then you can use the following:
esc = string(27B)
for i = 0, 100 do begin
print, esc + '[4D' + esc + '[K', format='(A, $)'
print, i, format='(I3, "%", $)'
wait, 0.1
endfor
I've put the code for this example in a main-level program that you can
run with:
IDL> .run mg_cl_update_demo
The code is here:
http://michaelgalloy.com/wp-content/uploads/2011/11/mg_cl_up date_demo.pro
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL, A Guide to Learning IDL: http://modernidl.idldev.com
Research Mathematician
Tech-X Corporation
|
|
|
|
Re: Printing to command line without a new line [message #78225 is a reply to message #78222] |
Wed, 02 November 2011 12:19  |
jasmeervirdee@gmail.c
Messages: 2 Registered: November 2011
|
Junior Member |
|
|
On Nov 2, 6:48 pm, David Fanning <n...@dfanning.com> wrote:
> jasmeervir...@gmail.com writes:
>> I have a fairly simple question.
>> My code takes a fair amount of time to run and I would like
>> it to display a percentage number which updates to the
>> command line without starting a new line.
>
>> So using print one usually does:
>
>> for i=0, 100-1, 1 do print, i, '%'
>
>> but this creates a long list of numbers. How can I stop a newline
>> being created by the print command
>
>> I hope this is clear. Does anyone know how to do this?
>
> http://www.idlcoyote.com/fileio_tips/lfsuppress.html
>
> Like this:
>
> IDL> for i=0, 15 do print, i, format='((x, I0),$)'
> 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Hi,
Thanks for the response.
It wasn't quite what I was looking for. This prints all the numbers in
the for loop
on a single line but what I want is the previous number to disappear
and
be replaced by the new number, so that I have one number which is
constantly updated.
Cheers
|
|
|
Re: Printing to command line without a new line [message #78230 is a reply to message #78225] |
Wed, 02 November 2011 11:48  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
jasmeervirdee@gmail.com writes:
> I have a fairly simple question.
> My code takes a fair amount of time to run and I would like
> it to display a percentage number which updates to the
> command line without starting a new line.
>
> So using print one usually does:
>
> for i=0, 100-1, 1 do print, i, '%'
>
> but this creates a long list of numbers. How can I stop a newline
> being created by the print command
>
> I hope this is clear. Does anyone know how to do this?
http://www.idlcoyote.com/fileio_tips/lfsuppress.html
Like this:
IDL> for i=0, 15 do print, i, format='((x, I0),$)'
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|