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

Home » Public Forums » archive » Formatting strings to coordinates
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
Formatting strings to coordinates [message #20144] Fri, 19 May 2000 00:00 Go to next message
Simon de Vet is currently offline  Simon de Vet
Messages: 36
Registered: May 2000
Member
The data analysis adventure continues... I have read in the data, and am
now working on the various plots.

I have a string array, taken from the text file, of coordinates.
However, they are in the form "43.92�S" ,and "176.50�W".

I would like to be able to take this array of strings and convert it to
a numerical array or real latitudes and longitudes, from -90 to 90 and 0
to 360 so that they can eventually be plotted onto a globe.

I've figured out how to use strings to generate numerical values (ie:
'Jan' -> 1, 'Feb' -> 2, etc..), but not how to handle parts of strings
to modify the other parts.

Any suggestions? This group has been a major help so far!

Thanks,

Simon
Re: Formatting string [message #52014 is a reply to message #20144] Fri, 22 December 2006 06:43 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mati Meron writes:

> There is always more than one way to skin a cat:-)

Indeed. I always do this like this:

IDL> var = 312
IDL> Print, String(var, Format='(I4.4)')
0312

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: Formatting string [message #52017 is a reply to message #20144] Fri, 22 December 2006 01:58 Go to previous message
mmeron is currently offline  mmeron
Messages: 44
Registered: October 2003
Member
In article <cc9no2dh8nn363kh6jnac5roul71gqg835@4ax.com>, Wox <nomail@hotmail.com> writes:
> Never looked at it that way :-). I always do padding like this:
>
> IDL> var='312'
> IDL> print,string(var,format='(I04)')
> 0312
>
> On Fri, 22 Dec 2006 08:39:24 GMT, mmeron@cars3.uchicago.edu wrote:
>
>> newvar = strmid('0000'+var,3,4,/reverse)
>
There is always more than one way to skin a cat:-)

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: Formatting string [message #52018 is a reply to message #20144] Fri, 22 December 2006 01:32 Go to previous message
Wox is currently offline  Wox
Messages: 184
Registered: August 2006
Senior Member
Never looked at it that way :-). I always do padding like this:

IDL> var='312'
IDL> print,string(var,format='(I04)')
0312

On Fri, 22 Dec 2006 08:39:24 GMT, mmeron@cars3.uchicago.edu wrote:

> newvar = strmid('0000'+var,3,4,/reverse)
Re: Formatting string [message #52019 is a reply to message #20144] Fri, 22 December 2006 00:56 Go to previous message
mmeron is currently offline  mmeron
Messages: 44
Registered: October 2003
Member
In article <1166777066.340722.90420@a3g2000cwd.googlegroups.com>, "Erik" <janssen.e@gmail.com> writes:
> mme...@cars3.uchicago.edu wrote:
>> In article <1166775977.998673.214070@42g2000cwt.googlegroups.com>, "Erik" <janssen.e@gmail.com> writes:
>>> Hi everyone,
>>>
>>> I have a question about formatting a string in IDL. I have a var-string
>>> which contains an integer value (like this '12' or '312').
>>> Unfortunately I need a string with four characters. If the integer
>>> value isn't four characters long, I want some 0's in front of it (like
>>> this; '0012' or '0312'). Is there any simple way of doing this, without
>>> parsing the string?
>>>
>> Sure. Assuming your var_string is called var, you get the padded one
>> by
>>
>> newvar = strmid('0000'+var,3,4,/reverse)
>>
>> var can be an array in this expression.
>>
>> Mati Meron | "When you argue with a fool,
>> meron@cars.uchicago.edu | chances are he is doing just the same"
>
>
> Thanks! It works! Never knew that strmid has such capabilitys. I only
> thought it was used for cutting strings.
>
Well, in principle yes, but by combining padding and cutting you can
do quite a lot.

> Have a nice Christmas :P
>
Thanks, you too.

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
Re: Formatting string [message #52020 is a reply to message #20144] Fri, 22 December 2006 00:44 Go to previous message
Erik[1] is currently offline  Erik[1]
Messages: 23
Registered: December 2006
Junior Member
mme...@cars3.uchicago.edu wrote:
> In article <1166775977.998673.214070@42g2000cwt.googlegroups.com>, "Erik" <janssen.e@gmail.com> writes:
>> Hi everyone,
>>
>> I have a question about formatting a string in IDL. I have a var-string
>> which contains an integer value (like this '12' or '312').
>> Unfortunately I need a string with four characters. If the integer
>> value isn't four characters long, I want some 0's in front of it (like
>> this; '0012' or '0312'). Is there any simple way of doing this, without
>> parsing the string?
>>
> Sure. Assuming your var_string is called var, you get the padded one
> by
>
> newvar = strmid('0000'+var,3,4,/reverse)
>
> var can be an array in this expression.
>
> Mati Meron | "When you argue with a fool,
> meron@cars.uchicago.edu | chances are he is doing just the same"


Thanks! It works! Never knew that strmid has such capabilitys. I only
thought it was used for cutting strings.

Have a nice Christmas :P
Re: Formatting string [message #52021 is a reply to message #20144] Fri, 22 December 2006 00:39 Go to previous message
mmeron is currently offline  mmeron
Messages: 44
Registered: October 2003
Member
In article <1166775977.998673.214070@42g2000cwt.googlegroups.com>, "Erik" <janssen.e@gmail.com> writes:
> Hi everyone,
>
> I have a question about formatting a string in IDL. I have a var-string
> which contains an integer value (like this '12' or '312').
> Unfortunately I need a string with four characters. If the integer
> value isn't four characters long, I want some 0's in front of it (like
> this; '0012' or '0312'). Is there any simple way of doing this, without
> parsing the string?
>
Sure. Assuming your var_string is called var, you get the padded one
by

newvar = strmid('0000'+var,3,4,/reverse)

var can be an array in this expression.

Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ENVI and the IDL Virtual Machine
Next Topic: Re: XVOLUME in batch?

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

Current Time: Wed Oct 08 18:57:04 PDT 2025

Total time taken to generate the page: 0.00890 seconds