If condition is met, variable needs to be within a specific range

65 Views Asked by At

I am brand new to IDL, and find that the documentation online is lacking in comparison to other languages. This is also my very first post on stackoverflow, so I will do my best to include the proper information necessary to answer my question. I'm doing research on the spectra of galaxies. In the code I am working on, we have 5 different indices, 0 through 4. Each index is for a different spectral feature. I am trying to input into the code that if the index is 4 (ff EQ 4) then 0.02 < z < 0.03 or z > 0.04, but no other values of z should be allowed for this specific feature.

**How can I input this condition for this index properly? **

I have tried: if (ff EQ 4) then (z GT 0.02 AND z LT 0.03) OR (z GT 0.04)

and: for ff=4 do begin z GT 0.02 AND z LT 0.03 OR z GT 0.04

and a couple of variations of the above. I put the 'endfor' or the 'endif' a little further down the code. Neither of these approaches have worked for me. I thought that maybe the if statement could only handle two statements after the condition, but I also tried: if (ff EQ 4) then z GT 0.03 AND z LT 0.03

which also did not work. The errors have almost all been syntax errors.

Is there a way to make a statement similar to this: if (ff EQ 4) then begin 0.02<z<0.03 OR z>0.04 ??

I just need the variable 'z' to meet those conditions whenever the index is 4. Any help would be greatly appreciated. I really hope this makes sense and that I have included the proper information. If not, please let me know what else I can include to help you better understand my problem. I also want to apologize in advance for my naivety when it comes to IDL.

1

There are 1 best solutions below

2
mgalloy On

I think you want something like this, where && is the logical and operator and || is the logical or operator:

if ((ff eq 4) && ((z gt 0.02 && z lt 0.03) || (z gt 0.04))) then begin
  ; do whatever it is
endif