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

Home » Public Forums » archive » Re: string manipulation
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: string manipulation [message #23876] Tue, 27 February 2001 02:40
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
Craig Markwardt wrote:
>
> I have been thinking about the following problem, but have been pretty
> frustrated.
>
> I have input keyword/value strings of the following form. People may
> recognize this from a FITS file.
>
> TTYPE2 = 'X1LSpecPcu0' / X1LSpecPcu0 : Histogram
> TUNIT2 = 'count '
> 1CTYP2 = 'CHANNEL '
> 1CPIX2 = '0~4,5:53,(54~135;2),(136~237;3),(238~249;4),250~255'
> 12CD2A = 1.25
> ^name^^ ^value^^^^^^^
>
> All of the keyword names have a trailing "2" which indicates that they
> are describing column number 2 in a FITS table. Note that in the name
> "12CD2A", only the *final* 2 refers to the column number.

...


Dear Craig,

I believe my replace_string is the right tool for your request

txt= ['TTYPE2' ,$
'TUNIT2', $
'1CTYP2', $
'1CPIX2' ,$
'12CD2A']

result=replace_string(txt,'2','50',pos=4,no_of_replaces=1)
print,result
TTYPE50 TUNIT50 1CTYP50 1CPIX50 12CD50A

http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_source/idl_ html/dbase/download/replace_string.tar.gz

For further routines and licensing please look at
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml


regards
Reimar


--
Reimar Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg1/
=============================================
a IDL library at ForschungsZentrum J�lich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml

http://www.fz-juelich.de/zb/text/publikation/juel3786.html
Re: string manipulation [message #23883 is a reply to message #23876] Mon, 26 February 2001 17:41 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
JD Smith <jdsmith@astro.cornell.edu> writes:
> Craig Markwardt wrote:
... deleted ...
>> I am able to find the string positions of the 2's, so that's not
>> really a problem. I do this by making a byte array of the strings,
>> and blanking out any alphabetic characters and any leading numeric
>> characters. Here I appreciate STRPOS is (partially) vectorized.
>>
>> However, when it comes to resubstituting the "50" back in, that's when
>> I get stymied. This is primarily because STRMID and STRPUT are not
>> vectorized at all. Well STRMID *is* vectorized, but not with a sane
>> behavior. For example, what I'd like to do is:
>>
>> NEWKEY = STRMID(KEY,0,P1) + '50' + STRMID(KEY,P2,100)
>>
>> Where KEY, P1, and P2 are vectors. Obviously this doesn't work. Any
>> ideas?
>
> I was going to come up with something using histogram, but I figured I'd
> be pressing my luck. I would probably use a loop and the
> sx{add,del,}par.pro routines from the nasalib. FITS has lots of rules
> about keyword length, total line length, etc. Best to waste some cycles
> and make sure it's done right.

Jah, that's what I do now, except I know they are valid header
keywords already, since they come from an already-existing file, and
I'd like to preserve the original formatting as much as possible. But
I guess a loop is just necessary.

[ I was looking for the magic HISTOGRAM bullet too ... ]

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: string manipulation [message #23886 is a reply to message #23883] Mon, 26 February 2001 16:20 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
JD Smith wrote:

> I was going to come up with something using histogram, but I figured I'd
> be pressing my luck. I would probably use a loop

Oh, no. I am losing my faith :-(

Pavel
Re: string manipulation [message #23893 is a reply to message #23886] Mon, 26 February 2001 15:34 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
Craig Markwardt wrote:
>
> I have been thinking about the following problem, but have been pretty
> frustrated.
>
> I have input keyword/value strings of the following form. People may
> recognize this from a FITS file.
>
> TTYPE2 = 'X1LSpecPcu0' / X1LSpecPcu0 : Histogram
> TUNIT2 = 'count '
> 1CTYP2 = 'CHANNEL '
> 1CPIX2 = '0~4,5:53,(54~135;2),(136~237;3),(238~249;4),250~255'
> 12CD2A = 1.25
> ^name^^ ^value^^^^^^^
>
> All of the keyword names have a trailing "2" which indicates that they
> are describing column number 2 in a FITS table. Note that in the name
> "12CD2A", only the *final* 2 refers to the column number.
>
> The interesting question happens when I want to change the column
> number, say from "2" to "50". Is there a straightforward way to do
> this in "vectoral" sort of way?
>
> I am able to find the string positions of the 2's, so that's not
> really a problem. I do this by making a byte array of the strings,
> and blanking out any alphabetic characters and any leading numeric
> characters. Here I appreciate STRPOS is (partially) vectorized.
>
> However, when it comes to resubstituting the "50" back in, that's when
> I get stymied. This is primarily because STRMID and STRPUT are not
> vectorized at all. Well STRMID *is* vectorized, but not with a sane
> behavior. For example, what I'd like to do is:
>
> NEWKEY = STRMID(KEY,0,P1) + '50' + STRMID(KEY,P2,100)
>
> Where KEY, P1, and P2 are vectors. Obviously this doesn't work. Any
> ideas?

I was going to come up with something using histogram, but I figured I'd
be pressing my luck. I would probably use a loop and the
sx{add,del,}par.pro routines from the nasalib. FITS has lots of rules
about keyword length, total line length, etc. Best to waste some cycles
and make sure it's done right.

Good luck,

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Congrid problem
Next Topic: NaN values

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

Current Time: Wed Oct 08 15:22:35 PDT 2025

Total time taken to generate the page: 0.00616 seconds