From d4dc9d03aea51d33f4c34e63070ad0a7c407eb20 Mon Sep 17 00:00:00 2001
From: Jean-Philippe Bernard <Jean-Philippe.Bernard@irap.omp.eu>
Date: Fri, 16 Sep 2022 16:23:04 +0200
Subject: [PATCH] setting angle values to undef when Q=U=0

---
 src/idl_misc/JPBLib_for_Dustemwrap/General/polar_iqu2ippsi.pro | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/idl_misc/JPBLib_for_Dustemwrap/General/polar_iqu2ippsi.pro b/src/idl_misc/JPBLib_for_Dustemwrap/General/polar_iqu2ippsi.pro
index d9341c8..7ffbcf8 100755
--- a/src/idl_misc/JPBLib_for_Dustemwrap/General/polar_iqu2ippsi.pro
+++ b/src/idl_misc/JPBLib_for_Dustemwrap/General/polar_iqu2ippsi.pro
@@ -1,4 +1,4 @@
-PRO polar_iqu2ippsi,I,Q,U,p,psi,p2=p2,help=help,lac=lac
+PRO polar_iqu2ippsi,I,Q,U,p,psi,p2=p2,help=help,lac=lac,largep=largep
 
 ;+
 ; NAME:
@@ -41,17 +41,23 @@ IF n_params(0) LE 4 THEN BEGIN
 ENDIF
 
 IF keyword_set(lac) THEN BEGIN
+  largep=la_power((la_add(la_power(Q,2.),la_power(U,2.))),0.5)
   p2=la_div(la_add(la_power(Q,2.),la_power(U,2.)),la_power(I,2.))
-  p=la_div(la_power((la_add(la_power(Q,2.),la_power(U,2.))),0.5),I)
+  p=la_div(largep,I)
   psi=0.5*atan(U,Q)/!dtor
   ind=where(U EQ la_undef() OR Q EQ la_undef(),count)
   IF count NE 0 THEN psi[ind]=la_undef()
 ENDIF ELSE BEGIN
+  largep=sqrt(Q^2+U^2)
   p2=(Q^2+U^2)/I^2
-  p=sqrt(Q^2+U^2)/I
+  p=largep/I
   psi=0.5*atan(U,Q)/!dtor
 ENDELSE
 
+;set polarization angle to undefined where P is 0
+ind=where(largep EQ 0.,count)
+IF count NE 0 THEN psi[ind]=la_undef()
+
 sortie:
 
 END
--
libgit2 0.21.2