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

Home » Public Forums » archive » Re: Padding numbers
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: Padding numbers [message #42309] Thu, 03 February 2005 05:50 Go to next message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Michael Wallace wrote:
> I've got a program which prints out the current time, but when it prints
> out the minutes or seconds, there's no 0 padding if the number is in the
> range 0 - 9.
>
> print, systime(/JULIAN), $
> FORMAT = '(C(CDI, X, CMoA, X, CYI, X, CHI, ":", CMI, ":", CSI))'
> 3 Feb 2005 1:53:47
>
> This looks good, but just wait until those seconds roll over.
>
>
> print, systime(/JULIAN), $
> FORMAT = '(C(CDI, X, CMoA, X, CYI, X, CHI, ":", CMI, ":", CSI))'
> 3 Feb 2005 1:54: 2
>
> Not so good. How do I change the format to fill that empty space with a
> zero? Same goes for minutes when they roll over. Thanks.

IDL> print,systime(/JULIAN), FORMAT = $
IDL> '(C(CDI, X, CMoA, X, CYI, X, CHI2.2, ":", CMI2.2, ":", CSI2.2))'
3 Feb 2005 08:49:40
Re: Padding numbers [message #42439 is a reply to message #42309] Thu, 03 February 2005 15:19 Go to previous messageGo to next message
Michael Wallace is currently offline  Michael Wallace
Messages: 409
Registered: December 2003
Senior Member
> IDL> print,systime(/JULIAN), FORMAT = $
> IDL> '(C(CDI, X, CMoA, X, CYI, X, CHI2.2, ":", CMI2.2, ":", CSI2.2))'
> 3 Feb 2005 08:49:40

Thanks, that did it. This is what I get for not being raised on FORTRAN
format codes. ;-)

-Mike
Re: Padding numbers [message #42733 is a reply to message #42439] Mon, 21 February 2005 09:13 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Thu, 03 Feb 2005 17:19:25 -0600, Michael Wallace wrote:

>> IDL> print,systime(/JULIAN), FORMAT = $
>> IDL> '(C(CDI, X, CMoA, X, CYI, X, CHI2.2, ":", CMI2.2, ":", CSI2.2))'
>> 3 Feb 2005 08:49:40
>
> Thanks, that did it. This is what I get for not being raised on FORTRAN
> format codes. ;-)

With IDL6.1, you can zero-pad like this as well:

IDL> print,FORMAT='(I02)',3
03

Why is this any better? Because you can do it with floating point
values too:

IDL> print,FORMAT='(F08.5)',!PI
03.14159

It also gracefully degrades to blank padding in versions <6.1.

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Zoom out of astronomical image preserving header info
Next Topic: Dynamically resizing arrays

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

Current Time: Sun Oct 12 09:16:56 PDT 2025

Total time taken to generate the page: 0.88303 seconds