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 
Return to the default flat view Create a new topic Submit Reply
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 previous 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.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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 19:02:41 PDT 2025

Total time taken to generate the page: 0.00455 seconds