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

Home » Public Forums » archive » Re: anything like sprintf?
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: anything like sprintf? [message #58815 is a reply to message #58814] Mon, 18 February 2008 05:35 Go to previous messageGo to previous message
lasse is currently offline  lasse
Messages: 48
Registered: February 2007
Member
On 18 Feb, 13:56, Yann Zoll <y_z2...@yahoo.de> wrote:
> Thx for all the sugestions.
>
> At the moment i use the if conditions. you need one if... per value:
>
> if for example the problem is the time:
>
>
[/color]
[color=blue]> [/color]
[color=blue]>  hh, mm, ss = hours, minutes, seconds[/color]
[color=blue]> [/color]
[color=blue]>  if hh lt 10 then hh = '0'+string(hh)[/color]
[color=blue]>  if mm lt 10 ....[/color]
[color=blue]>  if ss ...[/color]
[color=blue]> [/color]
[color=blue]>  time = strcompress(hh+':'+mm+':'ss',/REMOVE_ALL)[/color]
[color=blue]> [/color]
[color=blue]>  
[/color]
>
> if you encounter this problem in perl, the code looks like:
>
>
[/color]
[color=blue]> [/color]
[color=blue]>  time = sprintf("%02d.%02d.%02d",hh,mm,ss)[/color]
[color=blue]> [/color]
[color=blue]>  
[/color]
>
> ok, perl needs no explicit type casting as idl does so the "string()"
> command is necessary, but is it possible to assign the output of print
> (with the format keyword) to a variable?
>
> yann

No, but you can use a format code for the conversion of a number to a
string by specifying the format keyword, as in my example above.
Again, read the IDL help on format codes. IDL uses Fortran format
codes which are very similar to the stuff you already use in Perl with
sprintf. Your example in IDL with format codes would be

hour = 2
minute = 3
second=9
time = string([hour,minute,second],$
format='(I02,":",I02,":",I02)')

As you can see, the three numbers are converted to a string using the
STRING() function. Additionally, you can pass a format code, here I02.
"I" means that the output is an integer value, i.e. no positions after
the decimal point. "2" is the length of the output and "0" indicates
the padding with 0 if the integer output is shorter than the length.

Read here http://idlastro.gsfc.nasa.gov/idl_html_help/Format_Codes.htm l.
On that page you will see that IDL also supports C-style formatting
which is the formatting Perl uses.

So long
Lasse Clausen
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: anything like sprintf?
Next Topic: yaxisformat='exponent' in IDLgrGraphics

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

Current Time: Sun Oct 12 07:18:54 PDT 2025

Total time taken to generate the page: 6.74688 seconds