comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Where and lists of regions

Where and lists of regions
type: item
description: Hi, I'm in the middle of trying to simplify a large body of code which I inherited a few years ago and have been mangling ever since. Among other things, I'd be interested in anyone's thoughts on simplfying the case statement I use (full code below). Basically I have a list of regions which I want to remove from a vector. At the moment I use CASE to call WHERE to remove the regions elements (case to choose how many where statements are required). This is fine for a few regions, but I'm sure there must be a neater way, as when I need 10 regions, or even 20, this code is going to look terrible... I've written a code with EXECUTE, but I may want to use VM in the future so I'd like to avoid it if possible. Many Thanks, Ben CODE: function em_screen, wave, em_string ; returns a list of indes which are to be included. EXCLUDED regions ; are contained in a string with the format: ; '4400-5000,6500-6700,8000-8900' ; The ranges must be monotonic print, 'Emission line regions:'+em_string if em_string[0] eq 'none' then output=wave else begin em_list=strsplit(em_string, ',', /extract) n_region=n_elements(em_list) em=intarr(n_region,2) case n_region of 1: begin for i=0,n_region-1 do em[i,*]=strsplit(em_list[i], '-', /extract) output=where((wave le em[0,0]) or (wave ge em[0,1])) end 2: begin for i=0,n_region-1 do em[i,*]=strsplit(em_list[i], '-', /extract) output=where((wave le em[0,0]) or ((wave ge em[0,1]) and (wave le em[1,0])) or (wave ge em[1,1])) end 3: begin for i=0,n_region-1 do em[i,*]=strsplit(em_list[i], '-', /extract) output=where((wave le em[0,0]) or ((wave ge em[0,1]) and (wave le em[1,0])) or ((wave ge em[1,1]) and (wave le em[2,0])) or (wave ge em[2,1])) end 4: begin for i=0,n_region-1 do em[i,*]=strsplit(em_list[i], '-', /extract) output=where((wave le em[0,0]) or ((wave ge em[0,1]) and (wave le em[1,0])) or ((wave ge em[1,1]) and (wave le em[2,0])) or ((wave ge em[2,1]) and (wave le em[3,0])) or (wave ge em[3,1])) end 5: begin for i=0,n_region-1 do em[i,*]=strspl…
creator: Ben Panter
date: 2004-10-11T12:47:23-00:00