<div dir="ltr">Dear Leonid, DiFX users,<div><br></div><div>I would avoid applying this specific patch because it introduces a subtle bug, which may result in a segmentation fault at best and producing incorrect polarization label for polarization B without crashing at worst.</div><div><br></div><div>This specific piece of the code exposes a subtlety in the C/C++ languages. </div><div>The effect is that the second</div><div>+       if ( D->nPolar == 1 )<br>+       {<br>+             polTypeA = D->polPair[0];<br>+             polTypeB = '?'; /* Mark missing polarization */<br>+        }        </div><div>Note the missing "else" here. The is syntactically valid C/C++ but the the net effect is that, because there is no "else" keyword, the following piece of code:</div><div>+        {<br></div><div>+             polTypeA = D->polPair[0];<br>+             polTypeB = D->polPair[1];<br>+        }<br></div><div><br></div><div>will be executed *unconditionally*. Syntactically speaking, the compiler only sees the open/close braces as starting a new, temporary, context, without any conditions. All statements inside the block are executed.</div><div>Thus, if D->nPolar is, in fact, just 1 (single polarization) then the variable polTypeB will be unconditionally overwritten with whatever D->polPair[1] contains.</div><div><br></div><div>If you're lucky D->polPair is length one in that case and you're addressing outside array bounds and *maybe* get a segmentation violation.</div><div>But chances are better than average that that memory location is not initialized or contains unknown content which is unconditionally transferred to polTypeB.</div><div><br></div><div>Cheers,</div><div>h</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 11 Apr 2019 at 05:41, Leonid Petrov <<a href="mailto:Leonid.Petrov@lpetrov.net">Leonid.Petrov@lpetrov.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear colleagues,<br>
<br>
  DiFX has a bug and does not propagate polarization labels to the <br>
output FITS-IDI. The fix is rather trivial. <br>
<br>
  However when I discussed this issue with Rick Perley, he pointed out <br>
that another fix is needed as well. According to famous AIPS 114 memo, <br>
page 8, horizontal and vertical polarizations shall be labeled X and Y:<br>
<br>
X Horizontal linear<br>
Y Vertical linear<br>
<br>
i.e. fixed in the topo-centric, site-dependent coordinate system.<br>
<br>
  This is contrary to the IAU 1976 resolution that defines X polarization<br>
along direction to the Northern Pole and Y polarization along the <br>
right ascension axis (East), i.e. rotating in the topo-centric, <br>
site-dependent coordinate system.<br>
<br>
  I suggest to rename the polarizations recorded at the VLBI stations as <br>
<br>
H Horizontal linear<br>
V Vertical linear<br>
<br>
  and reserve X and Y labels for space telescopes.<br>
<br>
  In addition to just complying with the IAU nomenclature, it reduces chances <br>
of misunderstanding in communication with station personnel: who knows which <br>
polarization a station guy considers as "X", but unless he is operating an <br>
orbiting VLBI telescope, horizontal and vertical polarizations are unambiguous.<br>
<br>
  Any objections? Other thoughts?<br>
<br>
  Since we only started using FITS-IDI data with lin-pol, this change will<br>
be relatively painless.<br>
<br>
Leonid<br>
2019.04.10_23:34:51<br>
<br>
------------------------------------ Patch ---------------------------------<br>
<br>
--- applications/difx2fits/src/fitsAN.c~        2019-04-06 21:14:14.733263707 -0400<br>
+++ applications/difx2fits/src/fitsAN.c 2019-04-06 21:44:13.932896491 -0400<br>
@@ -106,8 +106,22 @@<br>
        stop  = D->mjdStop  - (int)D->mjdStart; <br>
<br>
        arrayId1 = 1;<br>
-       polTypeA = 'R';<br>
+       polTypeA = 'R'; /* Default */<br>
        polTypeB = 'L';<br>
+       if ( D->nPolar == 1 )<br>
+       {<br>
+             polTypeA = D->polPair[0];<br>
+             polTypeB = '?'; /* Mark missing polarization */<br>
+        }        <br>
+        {<br>
+             polTypeA = D->polPair[0];<br>
+             polTypeB = D->polPair[1];<br>
+        }<br>
+        if ( polTypeA == 'X' ) { polTypeA = 'H'; } /* Rename linear polarizations */<br>
+        if ( polTypeA == 'Y' ) { polTypeA = 'V'; }<br>
+        if ( polTypeB == 'X' ) { polTypeB = 'H'; }<br>
+        if ( polTypeB == 'Y' ) { polTypeB = 'V'; }<br>
+<br>
        time = 0.5 * (stop + start);<br>
        timeInt = stop - start;<br>
        for(bandId = 0; bandId < nBand; ++bandId)<br>
<br>
_______________________________________________<br>
Difx-users mailing list<br>
<a href="mailto:Difx-users@listmgr.nrao.edu" target="_blank">Difx-users@listmgr.nrao.edu</a><br>
<a href="https://listmgr.nrao.edu/mailman/listinfo/difx-users" rel="noreferrer" target="_blank">https://listmgr.nrao.edu/mailman/listinfo/difx-users</a><br>
</blockquote></div>