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

Home » Public Forums » archive » Vectorized STRMID ( was Re: Selecting odd/even numbered files)
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
Vectorized STRMID ( was Re: Selecting odd/even numbered files) [message #30055] Wed, 03 April 2002 12:37
Wayne Landsman is currently offline  Wayne Landsman
Messages: 117
Registered: January 1997
Senior Member
David Fanning wrote

> where I was trying to use the slen array to select a different
> length for each possible filename (assuming they weren't
> all the same length, but that they all had 3 character
> extensions). In that case, the numbers variable kept
> coming out as a 4x4 element array, rather than the expected
> 4-element array.

To extract the last 3 characters of a string array with arbitary
(non-indentical) lengths, I'd use the
reverse_offset keyword and count from the end.

numbers = fix(strmid(files,2,3,/reverse))

The reason you were getting 4x4 output arrays is that the vectorized STRMID is
sometimes *too* powerful -- it can both extract many substrings from a single
string, and extract substrings from many strings. Therefore, the position
parameter has to be REFORMed into a 2-d array. So to do the vectorized
extraction without the /reverse keyword...

n = N_elements(files)
len = reform( strlen(files), 1, n)
numbers = fix( strmid( files, len-3, 3))

Cheers, --Wayne
landsman@mpb.gsfc.nasa.gov
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Selecting odd/even numbered files
Next Topic: Re: changing the color map without having to re-load an image

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

Current Time: Wed Oct 08 13:04:32 PDT 2025

Total time taken to generate the page: 0.58841 seconds