Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
I have an array called station_name, dimensioned (6,n). Each item is a string 6 characters long. I would like to quickly test station_name against a particular string variable, find_this_station, another string of dimension 6. Is there any way to do this without using loops? If I have to use loops, does anyone have a tip on the fastest way to do so? Is there are better way to configure the array station_name to make such tests (against a particular station name) faster? I shall appreciate any help anyone can provide. -Bill Moninger -- Bill Moninger, NOAA/Forecast Systems Laboratory. home: 303-494-1709, work: 303-497-6435
The example below is fine. It is often convenient,and a good idea, to use an additional argument to the WHERE function, since it returns the number of matches found, i.e. t = WHERE(a EQ 's4',n) & IF n NE 0 THEN ... Use of n is to my taste cleaner and easier to read. This is my first posting to any newsgroup; so apologies if for some reason it does not read well. ---------------------------- Jim Hamill hamill@ais.net ---------------------------- In article <DqBo3L.KL4@midway.uchicago.edu>, rivers@cars3.uchicago.edu wrote: > In article <moninger-2304960900010001@zirkle.fsl.noaa.gov>, moninger@fsl.noaa.gov (Bill Moninger) writes: >> I have an array called station_name, dimensioned (6,n). Each item is a >> string 6 characters long. I would like to quickly test station_name >> against a particular string variable, find_this_station, another string of >> dimension 6. >> >> Is there any way to do this without using loops? >> >> If I have to use loops, does anyone have a tip on the fastest way to do so? >> >> Is there are better way to configure the array station_name to make such >> tests (against a particular station name) faster? > > Here is how to do it: > > IDL> a = ['s1', 's2', 's3', 's4', 's5', 's6'] > IDL> t = where(a eq 's4') > IDL> print, t > 3 > > The where() function finds the index number of the string in the array which > matches your test string. It returns -1 if there is no match. > > ____________________________________________________________ > Mark Rivers (312) 702-2279 (office) > CARS (312) 702-9951 (secretary) > Univ. of Chicago (312) 702-5454 (FAX) > 5640 S. Ellis Ave. (708) 922-0499 (home) > Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)