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

Home » Public Forums » archive » How do I use FORMAT as I would SPRINTF?? Please Help!
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: How do I use FORMAT as I would SPRINTF?? Please Help! [message #32217 is a reply to message #32125] Thu, 19 September 2002 08:06 Go to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
Brian Huether wrote:
>
> I am quite perplexed by the IDL FORMAT keyword. I am used to MATLAB where I
> can quite simply use the sprintf command. For instance, in MATLAB, the
> command
>
> s = sprintf('IDL has been driving me crazy for the last %d days', 10)
>
> would result in a string that contains
>
> 'IDL has been driving me crazy for the last 10 days'
>
> What I really need to do is something like this:
>
> s = sprintf('SIZE(%s, /%s)', arrayname, somekeyword)
>
> So if arrayname is A and somekeyword is TYPE, then the resulting string
> would be
>
> 'SIZE(A, /TYPE)'
>
> It is a meaningless example but hopefully you see what I want to do (i.e. I
> need to execute IDL commands in a loop, where each time through, the command
> input parameters are varying and are specified by indexing arrays that
> contain the parameters)

IDL> arrayname = 'A'
IDL> somekeyword = 'TYPE'
IDL> s = 'SIZE(' + arrayname + ', /' + somekeyword + ')'
IDL> print,s
SIZE(A, /TYPE)

This technique is simple and straightforward, but doesn't work for
numbers; you need to convert them to strings. That's what the STRING()
function is for, and it takes a FORMAT argument. That format argument
uses the same codes as the 'print' command, which include C-like formats
such as %f.

s = STRING(arrayname, somekeyword, FORMAT='(%"SIZE(%s, /%s)")')

I strongly recommend reviewing the online help; look in the index for
'printf-style format codes'. The rules aren't quite the same as for C
(and presumably for MATLAB), often in vary frustrating ways.
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: How do I use FORMAT as I would SPRINTF?? Please Help!
Next Topic: Re: Displaying data in 3 coodinates

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

Current Time: Fri Oct 10 17:15:48 PDT 2025

Total time taken to generate the page: 0.71874 seconds