0

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.

mgalloy
  • 2,356
  • 1
  • 12
  • 10

1 Answers1

0

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
mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • This is very helpful to know -- thank you for the information!! However, I actually want something more along the lines of: "when (ff eq 4) then ((z gt 0.02 && lt 0.03) || (z gt 0.04))". I just need z to be within those ranges when ff is 4. I am not sure how to code that up here. – sufferinggradstudent Aug 14 '23 at 16:59
  • But z might not be in your ranges. An IF statement lets you do something if a condition is met. Do you want to print an error or crash or something if z is not in your ranges? – mgalloy Aug 23 '23 at 01:36