Re: Padding numbers [message #42309] |
Thu, 03 February 2005 05:50  |
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   |
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  |
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
|
|
|