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

Home » Public Forums » archive » Re: Convert Integer to Text
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: Convert Integer to Text [message #25051] Mon, 14 May 2001 05:24 Go to next message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Dan Blair <vze2p88d@verizon.net> writes:

> Mark Hadfield wrote:
>
>> From: ""Mark Hadfield"" <m.hadfield@niwa.cri.nz>
>>
>>> You can add the prefix and suffix via the "+" operator like this...
>>>
>>> name = 'MC'+string(index,format='(I3.3)')+'.dcm'
>>>
>>> or within the format specifier like this...
>>>
>>> name = string(index,format='("MC",I3.3,".dcm"')'
>>
>> Of course you can also use printf-style format codes (new to IDL 5.4) like
>> this
>>
>> name = string(index,format='(%"MC%3.3d.dcm")')
>>
>> I suppose there must be somebody out there who actually *uses* this stuff?
>>
>> ---
>> Mark Hadfield

> A freind of mine wrote a nice thing for just this application. It's a
> function called
> padnumstring.pro
>
> here it is
>
> repeat begin
> if strlen(numstring) lt length then numstring='0'+numstring
> endrep until strlen(numstring) eq length

Not to blame you or your friend, but Mark's solution using the format qualifier is far superior and faster, too. You shouldn't use a loop in IDL when you can avoid it as easily as here.

Martin


--
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
[[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
[[ Bundesstr. 55, 20146 Hamburg [[
[[ phone: +49 40 41173-308 [[
[[ fax: +49 40 41173-298 [[
[[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
Re: Convert Integer to Text [message #25057 is a reply to message #25051] Sun, 13 May 2001 20:05 Go to previous messageGo to next message
Dan Blair is currently offline  Dan Blair
Messages: 5
Registered: May 2001
Junior Member
Mark Hadfield wrote:

> From: ""Mark Hadfield"" <m.hadfield@niwa.cri.nz>
>
>> You can add the prefix and suffix via the "+" operator like this...
>>
>> name = 'MC'+string(index,format='(I3.3)')+'.dcm'
>>
>> or within the format specifier like this...
>>
>> name = string(index,format='("MC",I3.3,".dcm"')'
>
> Of course you can also use printf-style format codes (new to IDL 5.4) like
> this
>
> name = string(index,format='(%"MC%3.3d.dcm")')
>
> I suppose there must be somebody out there who actually *uses* this stuff?
>
> ---
> Mark Hadfield
> m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
> National Institute for Water and Atmospheric Research
>
> --
> Posted from clam.niwa.cri.nz [202.36.29.1]
> via Mailgate.ORG Server - http://www.Mailgate.ORG

A freind of mine wrote a nice thing for just this application. It's a
function called
padnumstring.pro

here it is


copy all below this line
---------------------------


; Pad 0's at the beginning of a string to make it a
; certain number of characters.
;
; Meant only for integers !
;

function padnumstring, number, length

numstring = strcompress(string(number),/r)

if strlen(numstring) gt length then begin
print,'number is too big !'
stop
end

repeat begin
if strlen(numstring) lt length then numstring='0'+numstring
endrep until strlen(numstring) eq length

return, numstring

end

----------------------------
to above this line

just copy this and name it what I called it.

to make it work put it in a place where you can read idl files
usage:

to get a string from a two digit integer with 5 digits padded with zeros

idl> num = 10
idl> a = padnumstring(num,5)
idl> print,a
a = 00010

Best Dan

--
============================================================ ============
Daniel Blair Clark University
Nonlinear Dynamics Lab 508-793-7707
950 Main Street blair@nls1.clarku.edu
Worcester, MA 01610-1477 http://nls1.clarku.edu/~blair
============================================================ ============
Re: Convert Integer to Text [message #25058 is a reply to message #25057] Sun, 13 May 2001 15:13 Go to previous messageGo to next message
m.hadfield is currently offline  m.hadfield
Messages: 36
Registered: April 2001
Member
From: ""Mark Hadfield"" <m.hadfield@niwa.cri.nz>

> You can add the prefix and suffix via the "+" operator like this...
>
> name = 'MC'+string(index,format='(I3.3)')+'.dcm'
>
> or within the format specifier like this...
>
> name = string(index,format='("MC",I3.3,".dcm"')'

Of course you can also use printf-style format codes (new to IDL 5.4) like
this

name = string(index,format='(%"MC%3.3d.dcm")')

I suppose there must be somebody out there who actually *uses* this stuff?

---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research



--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
Re: Convert Integer to Text [message #25059 is a reply to message #25058] Sun, 13 May 2001 15:06 Go to previous messageGo to next message
m.hadfield is currently offline  m.hadfield
Messages: 36
Registered: April 2001
Member
From: "Emmler, Oliver" <Oliver.Emmler@med.uni-heidelberg.de>


> I want to convert Interger to Text to produce indexed filenames.
> Is there any help ?
>
> Files are like this:
>
> MC023.dcm
> MC024.dcm
> MC025.dcm
>
> I want to set up like: 'MC'+text+'.dcm'

Use formatted output. The "In.n" format descriptor will produce a string n
characters wide, padded with zeros.

You can add the prefix and suffix via the "+" operator like this...

name = 'MC'+string(index,format='(I3.3)')+'.dcm'

or within the format specifier like this...

name = string(index,format='("MC",I3.3,".dcm"')'

---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research



--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
Re: Convert Integer to Text [message #25324 is a reply to message #25051] Sat, 26 May 2001 07:15 Go to previous message
Emmler, Oliver is currently offline  Emmler, Oliver
Messages: 14
Registered: May 2001
Junior Member
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Great, thanx to all.

Marks hit works fine.

Special Thanx to Mark

Oliver

"Martin Schultz" <martin.schultz@dkrz.de> schrieb im Newsbeitrag
news:ylwitj4uni9.fsf@faxaelven.dkrz.de...
> Dan Blair <vze2p88d@verizon.net> writes:
>
>> Mark Hadfield wrote:
>>
>>> From: ""Mark Hadfield"" <m.hadfield@niwa.cri.nz>
>>>
>>>> You can add the prefix and suffix via the "+" operator like
>>>> this...
>>>>
>>>> name = 'MC'+string(index,format='(I3.3)')+'.dcm'
>>>>
>>>> or within the format specifier like this...
>>>>
>>>> name = string(index,format='("MC",I3.3,".dcm"')'
>>>
>>> Of course you can also use printf-style format codes (new to
>>> IDL 5.4) like this
>>>
>>> name = string(index,format='(%"MC%3.3d.dcm")')
>>>
>>> I suppose there must be somebody out there who actually *uses*
>>> this stuff?
>>>
>>> ---
>>> Mark Hadfield
>
>> A freind of mine wrote a nice thing for just this application.
>> It's a function called
>> padnumstring.pro
>>
>> here it is
>> [...]
>> repeat begin
>> if strlen(numstring) lt length then numstring='0'+numstring
>> endrep until strlen(numstring) eq length
>
> Not to blame you or your friend, but Mark's solution using the
> format qualifier is far superior and faster, too. You shouldn't use
> a loop in IDL when you can avoid it as easily as here.
>
> Martin
>
>
> --
> [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
> [[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[
> [[ Bundesstr. 55, 20146 Hamburg [[
> [[ phone: +49 40 41173-308 [[
> [[ fax: +49 40 41173-298 [[
> [[ martin.schultz@dkrz.de [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBOw+6Z7813a8W2dX3EQLo0ACfSfgzKze40vD2eOTUQex0nBGpdaUA oM7C
K4Ybuk+XTt3dg2zkfhY6eWau
=BXmC
-----END PGP SIGNATURE-----
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Determining circularity
Next Topic: Can't READ_DICOM without DIALOG_PICKFILE

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

Current Time: Wed Oct 08 17:11:44 PDT 2025

Total time taken to generate the page: 0.00736 seconds