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

Home » Public Forums » archive » Re: Print format question for the Experts
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: Print format question for the Experts [message #25980] Thu, 02 August 2001 15:51 Go to next message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
David Fanning wrote:
>
> To only print certain lines, you can do...
>
> PRO Example, K
; n*K-th lines only will be printed
> max_rec=20
> base = Widget_Base()
> text = Widget_Text(base, Value="", Scr_XSize=200, YSize=1)
> screenSize = Get_Screen_Size()
> xCenter = screenSize(0) / 2
> yCenter = screenSize(1) / 2
> geom = Widget_Info(base, /Geometry)
> xHalfSize = geom.Scr_XSize / 2
> yHalfSize = geom.Scr_YSize / 2
> Widget_Control, base, XOffset = xCenter-xHalfSize, $
> YOffset = yCenter-yHalfSize
> Widget_Control, base, /Realize
> maxnumber = StrTrim(max_rec, 2)
if n_elements(k) eq 0 then k=1
> for i=0,max_rec-1 do begin
> wait, 0.5 ; Or read a record or whatever.
if i mod k eq 0 then number = StrTrim(i, 2)
> Widget_Control, text, Set_Value='Record number ' + number + $
> ' out of ' + maxnumber + '.'
> endfor
> Widget_Control, base, /Destroy
> END

Cheers,
Pavel
Re: Print format question for the Experts [message #25983 is a reply to message #25980] Thu, 02 August 2001 13:56 Go to previous messageGo to next message
jmcfee is currently offline  jmcfee
Messages: 17
Registered: August 1995
Junior Member
Many thanks to Paul van Delst and David Fanning. Two different but cool
solutions. It would have taken me lots of time to figure out either on my own.

Thanks

John McFee

In article <MPG.15d35ad1b354565d989e4d@news.frii.com>,
david@dfanning.com (David Fanning) writes:
|> John McFee writes:
|>
|> > I have a question which I think should have a simple answer. Being a master
...

--
Dr. John E. McFee
Defence Research Establishment Suffield
Box 4000, Medicine Hat, AB Canada T1A 8K6
(403) 544-4739 (voice) 544-4704 (fax)
e-mail: John.McFee@dres.dnd.ca
--
____________
Dr. John E. McFee | John.McFee@dres.dnd.ca
Head Threat Detection Group | www.dres.dnd.ca, www.ccmat.gc.ca
Defence Research Establishment Suffield | PH: 403-544-4739
Re: Print format question for the Experts [message #25984 is a reply to message #25983] Thu, 02 August 2001 13:44 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
jmcfee@dres.dnd.ca (John McFee) writes:
>
> Because I can have several thousand records in a run, I do not want to have a
> flowing list like:
>
> ...
> Record number 1034 out of 1500
> Record number 1035 out of 1500
> Record number 1036 out of 1500
> ...etc.

If you are on an ANSI-type terminal (VT100, etc, perhaps even the DOS
window), you can check out STATUSLINE in my library for some pointers
on how to move the cursor around on the screen. The essence of the
script is that I use the various ANSI escape codes to push the cursor
to the desired place. I use it everyday to do exactly what you are
describing.

Craig



--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Print format question for the Experts [message #25986 is a reply to message #25984] Thu, 02 August 2001 12:41 Go to previous messageGo to next message
david[2] is currently offline  david[2]
Messages: 100
Registered: June 2001
Senior Member
John McFee writes:

> I have a question which I think should have a simple answer. Being a master of
> kludging code for physics problems, it's not surprising that I haven't been able
> to figure it out. I'm hoping the experts in this group can.
>
> I am using IDL to read records one at a time from a file and I want to print out
> a message that each record was successfully read, i.e., I would print something
> like the following for record 5:
>
> Record number 5 out of 1500
>
> Because I can have several thousand records in a run, I do not want to have a
> flowing list like:
>
> ...
> Record number 1034 out of 1500
> Record number 1035 out of 1500
> Record number 1036 out of 1500
> ...etc.
>
> but instead just want one line where the record number increments, i.e.,
>
> Record number n out of 1500 [where n changes at the same spot]
>
>
> To do that I tried the following code:
>
> i=0
> print, format='($,"Record number ",t19,i6,t27,"out of " , t28,i6)',i+1,max_rec
> for i=0,max_rec-1 do begin
> read_a_record_function
> print, format='($,tl42,i6)', i+1
> endfor
>
> What I get is something like:
>
> Record number 1 out of 1500 2 3 4 5 6 7 8 9 10 11 13 14
> 15....etc.
>
> In other words, the $ format character supresses the new line, but each new
> print sets the next line's "left-right" pointer at the right edge of the
> previous printed line.
>
> I've tried the t format char as well as the tl character with no more luck.
>
> Does anybody know how to do this?

How about this:

PRO Example
max_rec=20
base = Widget_Base()
text = Widget_Text(base, Value="", Scr_XSize=200, YSize=1)
screenSize = Get_Screen_Size()
xCenter = screenSize(0) / 2
yCenter = screenSize(1) / 2
geom = Widget_Info(base, /Geometry)
xHalfSize = geom.Scr_XSize / 2
yHalfSize = geom.Scr_YSize / 2
Widget_Control, base, XOffset = xCenter-xHalfSize, $
YOffset = yCenter-yHalfSize
Widget_Control, base, /Realize
maxnumber = StrTrim(max_rec, 2)
for I=0,max_rec-1 do begin
wait, 0.5 ; Or read a record or whatever.
number = StrTrim(I+1, 2)
Widget_Control, text, Set_Value='Record number ' + number + $
' out of ' + maxnumber + '.'
endfor
Widget_Control, base, /Destroy
END

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Print format question for the Experts [message #25987 is a reply to message #25986] Thu, 02 August 2001 12:24 Go to previous messageGo to next message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
John McFee wrote:
>
> I have a question which I think should have a simple answer. Being a master of
> kludging code for physics problems, it's not surprising that I haven't been able
> to figure it out. I'm hoping the experts in this group can.
>
> I am using IDL to read records one at a time from a file and I want to print out
> a message that each record was successfully read, i.e., I would print something
> like the following for record 5:
>
> Record number 5 out of 1500
>
> Because I can have several thousand records in a run, I do not want to have a
> flowing list like:
>
> ...
> Record number 1034 out of 1500
> Record number 1035 out of 1500
> Record number 1036 out of 1500
> ...etc.
>
> but instead just want one line where the record number increments, i.e.,
>
> Record number n out of 1500 [where n changes at the same spot]
>
> To do that I tried the following code:
>
> i=0
> print, format='($,"Record number ",t19,i6,t27,"out of " , t28,i6)',i+1,max_rec
> for i=0,max_rec-1 do begin
> read_a_record_function
> print, format='($,tl42,i6)', i+1
> endfor
>
> What I get is something like:
>
> Record number 1 out of 1500 2 3 4 5 6 7 8 9 10 11 13 14
> 15....etc.
>
> In other words, the $ format character supresses the new line, but each new
> print sets the next line's "left-right" pointer at the right edge of the
> previous printed line.
>
> I've tried the t format char as well as the tl character with no more luck.
>
> Does anybody know how to do this?

Let's see, I'm no expert, but your output string has:

1 2 3
123456789012345678901234567890

Record number 1034 out of 1500

30 characters and you want the repeat to start at character #15 - so that's 16 backspaces
from the end of the string. You can try:


; Create backspace array of required length
bksp = MAKE_ARRAY( 16, VALUE = 8B )

; Output "base" string of the correct length
; Record number XXXX out of XXXX
PRINT, FORMAT = '( 2x, "Record number ", $ )'

FOR i = 1, number_of_records_to_read DO BEGIN

PRINT, FORMAT = '( a, i4, " out of ", i4, $ )', $
STRING( bksp ), i, number_of_records_to_read

......etc etc.....

ENDFOR


This is a supa kludge. You gotta make sure that the length of the format strings are all
consistent, as well as how many backspaces etc. But it seems to work just fine for me. Of
course, any other output (e.g. from message or other print statements) will screw up the
output.

paulv

p.s. STRING(8B) == ASCII character set backspace character. So, if you're using IDL on a
machine that uses EBCDIC (if they still exist?), I have no ideer.

--
Paul van Delst A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274 There shallow draughts intoxicate the brain,
Fax:(301)763-8545 And drinking largely sobers us again.
Alexander Pope.
sec : U Re: Print format question for the Experts [message #26122 is a reply to message #25983] Thu, 02 August 2001 20:22 Go to previous message
Andrew Cool is currently offline  Andrew Cool
Messages: 219
Registered: January 1996
Senior Member
John McFee wrote:
>
> Many thanks to Paul van Delst and David Fanning. Two different but cool
> solutions. It would have taken me lots of time to figure out either on my own.
>

John,

Another "cool" answer, so to speak...

This bit of code works fine from the old TTY command line
environment as found on VMS and Unix boxes.

Doesn't work under IDLDE in the Output log window however,
in which case you need a van Delst or "von" Fanning solution.

HTH,

Andrew


pro trace_loop_test
for i = 0,100 do begin
trace_loop,i
end
end

pro trace_loop,i
cr = STRING(13B) ; ASCII Carriage-return Control Code
print,format='("Processing index Number ",i4,a,$)',i,cr
end

------------------------------------------------------------ ---------
Andrew D. Cool .->-.
Electromagnetics & Propagation Group `-<-'
Surveillance Systems Division Transmitted on
Defence Science & Technology Organisation 100% recycled
PO Box 1500, Salisbury electrons
South Australia 5108

Phone : 061 8 8259 5740 Fax : 061 8 8259 6673
Email : andrew.cool@dsto.defence.gov.au
------------------------------------------------------------ ---------
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: How to organize client-server IDL application?
Next Topic: Print format question for the Experts

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

Current Time: Wed Oct 08 14:52:26 PDT 2025

Total time taken to generate the page: 0.00439 seconds