MIDI Pipeline Reference Manual  2.8.3
procFrgSP.c
1 /******************************************************************************
2 *******************************************************************************
3 * European Southern Observatory
4 * VLTI MIDI Data Reduction Software
5 *
6 * Module name: procFrgSP.c
7 * Description: Contains routines for Fringe Track data post processing
8 *
9 * History:
10 * 03-Feb-05 (csabet) Created
11 *******************************************************************************
12 ******************************************************************************/
13 
14 /******************************************************************************
15 * Compiler directives
16 ******************************************************************************/
17 
18 /******************************************************************************
19 * Include files
20 ******************************************************************************/
21 #include <stdio.h>
22 #include <cpl.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <math.h>
26 #include "midiGlobal.h"
27 #include "midiLib.h"
28 #include "memoryHandling.h"
29 #include "errorHandling.h"
30 #include "calibration.h"
31 #include "fitsAnalysisFrgSP.h"
32 #include "imageProcessing.h"
33 #include "createProdFrg.h"
34 #include "transferFunction.h"
35 #include "visibility.h"
36 #include "diagnostics.h"
37 #include "estimationFrg.h"
38 #include "photometry.h"
39 #include "preProcFrgSP.h"
40 #include "procFrgSP.h"
41 #include "procFrgHS.h"
42 #include "statistics.h"
43 
44 /**********************************************************
45 * Constant definitions
46 **********************************************************/
47 
48 /**********************************************************
49 * Global Variables
50 **********************************************************/
51 
52 /*============================ C O D E A R E A ===========================*/
53 
54 
55 
56 
57 /******************************************************************************
58 * European Southern Observatory
59 * VLTI MIDI Data Reduction Software
60 *
61 * Module name: procFrgSP
62 * Input/Output: See function arguments to avoid duplication
63 * Description: This is the main routine for processing the SCI_PHOT
64 * computation. If this is a SCI_PHOT_CALIB or SCI_PHOT_SCIENCE template
65 * then we exepect ony Interferometry files with the following
66 * configurations:
67 *
68 * DATA1 = Photometry A data
69 * DATA2 = Interferometry data
70 * DATA3 = Interferometry data
71 * DATA4 = Photometry B data
72 *
73 * History:
74 * 21-Jul-03 (csabet) Created
75 ******************************************************************************/
76 void procFrgSP (
77  MidiFiles *fileNames, // In: Pointer to midi files structure
78  UserOptions *options, // In: Pointer to user options
79  int *error, // Ou: Error status
80  cpl_parameterlist *parlist,
81  cpl_frameset *frameset)
82 {
83 
84  // Local Declarations
85  // ------------------
86  const char routine[] = "procFrgSP";
87  ImageFormat *formatInterf=NULL;
88  ImageFormat *formatPhotomA=NULL;
89  ImageFormat *formatPhotomB=NULL;
90  CompressedData *compressedInterf=NULL, *compressedPhotomA=NULL, *compressedPhotomB=NULL;
91  FilterData *filterInfo=NULL;
92  DispersedResult *dispResult=NULL;
93  CorrectedFrames *corrFrames=NULL;
94  // Algorithm
95  // ---------
96  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
97  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
98 
99  // Reset status
100  *error = 0;
101  if (options->processing == UNDISPERSED)
102  {
103  *error = 1;
104  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
105  "'UNDISPERSED' is an invalid processing request for SCI_PHOT data");
106  return;
107  }
108 
109  // Allocate memory
110  formatInterf = callocImageFormat ();
111  formatPhotomA = callocImageFormat ();
112  formatPhotomB = callocImageFormat ();
113  corrFrames = cpl_calloc (1, sizeof (CorrectedFrames));
114 
115  corrFrames->CorrInterf=0;
116  corrFrames->CorrPhotomA=0;
117  corrFrames->CorrPhotomB=0;
118 
119  // Analyse Input files
120  // -------------------
121  analyseFitsFrgSP (fileNames, formatInterf, formatPhotomA, formatPhotomB, error);
122  if (*error)
123  {
124  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot analyse FITS files");
125  freeImageFormat (formatInterf);
126  freeImageFormat (formatPhotomA);
127  freeImageFormat (formatPhotomB);
128  return;
129  }
130 
131  // Reduce Data
132  // -----------
133  // Allocate memory for data compression
134  compressedInterf = callocMidiCompressed (formatInterf);
135  compressedPhotomA = callocMidiCompressed (formatPhotomA);
136  compressedPhotomB = callocMidiCompressed (formatPhotomB);
137  badChannelList = (int *) calloc (formatInterf->iXWidth, sizeof (int));
138  filterInfo = callocFilterInfo();
139 
140 
141  // Preprocessing
142  preProcFrgSP (options, filterInfo, fileNames, compressedInterf,
143  compressedPhotomA, compressedPhotomB, formatInterf, formatPhotomA, formatPhotomB, error);
144  if (*error)
145  {
146  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot compress FITS files");
147  freeCompressedData (formatInterf, compressedInterf);
148  freeCompressedData (formatPhotomA, compressedPhotomA);
149  freeCompressedData (formatPhotomB, compressedPhotomB);
150  free (badChannelList);
151  freeImageFormat (formatInterf);
152  freeImageFormat (formatPhotomA);
153  freeImageFormat (formatPhotomB);
154  freeFilterInfo (filterInfo);
155  return;
156  }
157 
158  // Check Delay Lines for jumps within scans
159  checkDelayLineJumps ("INTERF", formatInterf, compressedInterf);
160  checkDelayLineJumps ("PHOTOMA", formatPhotomA, compressedPhotomA);
161  checkDelayLineJumps ("PHOTOMB", formatPhotomB, compressedPhotomB);
162 
163  // Check Delay Line Consistencies
164  checkDelayLineConsistencies ("INTERF", "PHOTOMA", compressedInterf, compressedPhotomA, formatInterf, formatPhotomA, error);
165  checkDelayLineConsistencies ("INTERF", "PHOTOMB", compressedInterf, compressedPhotomB, formatInterf, formatPhotomB, error);
166  if (*error)
167  {
168  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "SCI_PHOT processing abandonned");
169  freeCompressedData (formatInterf, compressedInterf);
170  freeCompressedData (formatPhotomA, compressedPhotomA);
171  freeCompressedData (formatPhotomB, compressedPhotomB);
172  free (badChannelList);
173  freeImageFormat (formatInterf);
174  freeImageFormat (formatPhotomA);
175  freeImageFormat (formatPhotomB);
176  freeFilterInfo (filterInfo);
177  return;
178  }
179 
180  // Check Chopping Statistics. for QCLOG diagnostics
181  // ------------------------------------------------
182  reportInterfChopping ("INTERF", formatInterf, compressedInterf);
183  reportPhotomChopping ("PHOTOMA", formatPhotomA, compressedPhotomA);
184  reportPhotomChopping ("PHOTOMB", formatPhotomB, compressedPhotomB);
185  displayInterfChoppingDisp ("INTERF", formatInterf, compressedInterf);
186  displayPhotomChoppingDisp ("PHOTOMA", formatPhotomA, compressedPhotomA);
187  displayPhotomChoppingDisp ("PHOTOMB", formatPhotomB, compressedPhotomB);
188 
189  // Remove Sky Background and display Target with Sky removed
190  dispResult = callocDispResult (formatInterf->iXWidth);
191  cleanupFrgSP (options->processing, formatInterf, formatPhotomA, formatPhotomB, compressedInterf,
192  compressedPhotomA, compressedPhotomB, error, corrFrames);
193  if (*error)
194  {
195  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "SCI_PHOT processing abandonned");
196  freeCompressedData (formatInterf, compressedInterf);
197  freeCompressedData (formatPhotomA, compressedPhotomA);
198  freeCompressedData (formatPhotomB, compressedPhotomB);
199  free (badChannelList);
200  freeImageFormat (formatInterf);
201  freeImageFormat (formatPhotomA);
202  freeImageFormat (formatPhotomB);
203  freeFilterInfo (filterInfo);
204  freeDispResult (dispResult);
205  return;
206  }
207 
208  // Display Waterfall data
209  prepareWaterfallDisplay (fileNames, formatInterf, compressedInterf);
210 
211  // Apply optical compensation using the available Transfer Ratios
212  applyOpticalCompensation (fileNames, formatInterf, compressedInterf,
213  compressedPhotomA, compressedPhotomB, error, parlist, frameset);
214 
215  // Frequency Calibration, if it is a CALIB batch
216  // ---------------------------------------------
217  if (strcmp (formatInterf->obsCatg, "CALIB") == 0)
218  calibrateWaveUsingPolynom (fileNames, formatInterf);
219 
220  // Create UNDISPERSED allSpectrum and dcLevels. For SCI_PHOT this is not necessary
221  // -------------------------------------------
222 // getUndispersedPowerSpectrum (formatInterf, compressedInterf);
223 
224  postProcFringe (fileNames, filterInfo, compressedInterf, compressedPhotomA,
225  compressedPhotomB, formatInterf, formatPhotomA,
226  formatPhotomB, dispResult, error,
227  parlist, frameset, corrFrames);
228  if (*error)
229  {
230  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "SCI_PHOT processing abandonned");
231  freeCompressedData (formatInterf, compressedInterf);
232  freeCompressedData (formatPhotomA, compressedPhotomA);
233  freeCompressedData (formatPhotomB, compressedPhotomB);
234  free (badChannelList);
235  freeImageFormat (formatInterf);
236  freeImageFormat (formatPhotomA);
237  freeImageFormat (formatPhotomB);
238  freeFilterInfo (filterInfo);
239  freeDispResult (dispResult);
240  return;
241  }
242 
243  // Release memory used in this batch
244  freeCompressedData (formatInterf, compressedInterf);
245  freeCompressedData (formatPhotomA, compressedPhotomA);
246  freeCompressedData (formatPhotomB, compressedPhotomB);
247  free (badChannelList);
248  freeImageFormat (formatInterf);
249  freeImageFormat (formatPhotomA);
250  freeImageFormat (formatPhotomB);
251  freeFilterInfo (filterInfo);
252  freeDispResult (dispResult);
253  cpl_free(corrFrames);
254  return;
255 }
256 /*****************************************************************************/
257 
258 
259 /******************************************************************************
260 * European Southern Observatory
261 * VLTI MIDI Data Reduction Software
262 *
263 * Module name: cleanupFrgSP
264 * Input/Output: See function arguments to avoid duplication
265 * Description: Removes sky etc from the data
266 *
267 * History:
268 * 06-Dec-05 (csabet) Created
269 ******************************************************************************/
270 void cleanupFrgSP (
271  enum ProcessingMode processing,
272  ImageFormat *formatInterf, // In: Interf size parameters
273  ImageFormat *formatPhotomA, // In: PhotA size parameters
274  ImageFormat *formatPhotomB, // In: PhotB size parameters
275  CompressedData *compressedInterf, // Ou: Pointer to the compressed interferometry data structure
276  CompressedData *compressedPhotomA, // Ou: Pointer to the compressed photom A data structure
277  CompressedData *compressedPhotomB, // Ou: Pointer to the compressed photom B data structure
278  int *error, // Ou: Error status
279  CorrectedFrames *corrFrames) // Corrected/removed frames
280 {
281 
282  // Local Declarations
283  // ------------------
284  const char routine[] = "cleanupFrgSP";
285  int transitions, f, R, X, n, localError;
286  double *array, fluxAve;
287  float *arrayF;
288  char *fileName, *title;
289 
290  // Algorithm
291  // ---------
292  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
293  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
294 
295  cpl_msg_info(cpl_func,"\nCleaning up SCI_PHOT files for batch %d \n", batchNumber);
296  cpl_msg_info(cpl_func,"------------------------------------ \n");
297  fprintf (midiReportPtr, "\nCleaning up SCI_PHOT files for batch %d \n", batchNumber);
298  fprintf (midiReportPtr, "------------------------------------ \n");
299 
300  // Initialise
301  localError = 0;
302  *error = 0;
303  transitions = 0;
304 
305  // Check Interferometry chopping cycle
306  // -----------------------------------
307  transitions = countTransitions ('T', formatInterf->numOfFrames, compressedInterf->tarType);
308  sprintf (midiMessage, "Target Transitions for Interf = %d", transitions);
309  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
310  if (transitions < 10)
311  {
312  sprintf (midiMessage, "Interferometry data is not chopped");
313  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
314  *error = 1;
315  }
316 
317  // Check PhotomA chopping cycle
318  // ----------------------------
319  transitions = countTransitions ('T', formatPhotomA->numOfFrames, compressedPhotomA->tarType);
320  sprintf (midiMessage, "Target Transitions for Photom A = %d", transitions);
321  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
322  if (transitions < 10)
323  {
324  sprintf (midiMessage, "Photometry A data is not chopped");
325  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
326  *error = 1;
327  }
328 
329  // Check PhotomB chopping cycle
330  // ----------------------------
331  transitions = countTransitions ('T', formatPhotomB->numOfFrames, compressedPhotomB->tarType);
332  sprintf (midiMessage, "Target Transitions for Photom B = %d", transitions);
333  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
334  if (transitions < 10)
335  {
336  sprintf (midiMessage, "Photometry B data is not chopped");
337  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
338  *error = 1;
339  }
340 
341  // if No error so far
342  if (!(*error))
343  {
344  formatInterf->chopped = 1;
345  formatPhotomA->chopped = 1;
346  formatPhotomB->chopped = 1;
347  }
348  else
349  {
350  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot cleanup SCI_PHOT files");
351  *error = 1;
352  return;
353  }
354 
355  // Correct benign tarType inconsistencies
356  // --------------------------------------
357 
358 
359 
360  corrFrames->CorrInterf=correctTarType("INTERF", compressedInterf->tarType,
361  compressedInterf->time, formatInterf->numOfFrames, &localError);
362  if (localError) *error = 1;
363 
364  corrFrames->CorrPhotomA=correctTarType("PHOTOMA", compressedPhotomA->tarType,
365  compressedPhotomA->time, formatPhotomA->numOfFrames, &localError);
366  if (localError) *error = 1;
367 
368  corrFrames->CorrPhotomB=correctTarType("PHOTOMB", compressedPhotomB->tarType,
369  compressedPhotomB->time, formatPhotomB->numOfFrames, &localError);
370  if (*error || localError)
371  {
372  *error = 1;
373  return;
374  }
375 
376  // Remove sky background
377  // ---------------------
378  removeSkyBackground ("INTERF", processing, formatInterf, compressedInterf, &localError);
379  if (localError) *error = 1;
380  removeSkyBackground ("PHOTOMA", processing, formatPhotomA, compressedPhotomA, &localError);
381  if (localError) *error = 1;
382  removeSkyBackground ("PHOTOMB", processing, formatPhotomB, compressedPhotomB, &localError);
383  if (formatInterf->numOfFrames != formatPhotomA->numOfFrames ||
384  formatInterf->numOfFrames != formatPhotomB->numOfFrames || *error || localError)
385  {
386  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Unequal numOfFrames");
387  *error = 1;
388  return;
389  }
390 
391  // Reject frames whose flux are <= 0 or are not 'T'
392  for (R = 0; R < formatInterf->numOfRegionsToProcess; R++)
393  {
394  for (X = 0; X < formatInterf->iXWidth; X++)
395  {
396  if (badChannelList[X])
397  continue;
398 
399  for (f = 0; f < formatInterf->numOfFrames; f++)
400  {
401 /* if ((compressedInterf->tarType[f] == 'T') && */
402 /* (((compressedInterf->iDispFringe)[R])[X])[f] <= 0.0) */
403 /* { */
404 /* compressedInterf->rejectList[X][f] |= BSL_DATA_ERROR; */
405 /* if (diagnostic > 3) */
406 /* { */
407 /* sprintf (midiMessage, "Negative Flux at: R %d X %3d F %4d Interf %10.2f", */
408 /* R, X, f, (((compressedInterf->iDispFringe)[R])[X])[f]); */
409 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
410 /* } */
411 /* } */
412  // Reject frames which are not 'T'
413  if (compressedInterf->tarType[f] != 'T')
414  compressedInterf->rejectList[X][f] |= BSL_SKY_SCAN;
415  }
416  }
417  }
418 
419  for (R = 0; R < formatPhotomA->numOfRegionsToProcess; R++)
420  {
421  for (X = 0; X < formatPhotomA->iXWidth; X++)
422  {
423  if (badChannelList[X])
424  continue;
425 
426  for (f = 0; f < formatPhotomA->numOfFrames; f++)
427  {
428 /* if ((compressedPhotomA->tarType[f] == 'T') && */
429 /* (((compressedPhotomA->iDispFringe)[R])[X])[f] <= 0.0) */
430 /* { */
431 /* compressedPhotomA->rejectList[X][f] |= BSL_DATA_ERROR; */
432 /* /\* If the photometry is bad in one of the channels, set also the interferometry to "BSL_DATA_ERROR" *\/ */
433 /* if(formatPhotomA->iXWidth == formatInterf->iXWidth && formatPhotomA->numOfFrames == formatInterf->numOfFrames) */
434 /* { */
435 /* compressedInterf->rejectList[X][f] |= BSL_DATA_ERROR; */
436 /* } */
437 /* if (diagnostic > 3) */
438 /* { */
439 /* sprintf (midiMessage, "Negative Flux at: R %d X %3d F %4d PhotomA %10.2f", */
440 /* R, X, f, (((compressedPhotomA->iDispFringe)[R])[X])[f]); */
441 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
442 /* } */
443 /* } */
444  // Reject frames which are not 'T'
445  if (compressedPhotomA->tarType[f] != 'T')
446  compressedPhotomA->rejectList[X][f] |= BSL_SKY_SCAN;
447  }
448  }
449  }
450 
451  for (R = 0; R < formatPhotomB->numOfRegionsToProcess; R++)
452  {
453  for (X = 0; X < formatPhotomB->iXWidth; X++)
454  {
455  if (badChannelList[X])
456  continue;
457 
458  for (f = 0; f < formatPhotomB->numOfFrames; f++)
459  {
460 /* if ((compressedPhotomB->tarType[f] == 'T') && */
461 /* (((compressedPhotomB->iDispFringe)[R])[X])[f] <= 0.0) */
462 /* { */
463 /* compressedPhotomB->rejectList[X][f] |= BSL_DATA_ERROR; */
464 /* /\* If the photometry is bad in one of the channels, set also the interferometry to "BSL_DATA_ERROR" *\/ */
465 /* if(formatPhotomB->iXWidth == formatInterf->iXWidth && formatPhotomB->numOfFrames == formatInterf->numOfFrames) */
466 /* { */
467 /* compressedInterf->rejectList[X][f] |= BSL_DATA_ERROR; */
468 /* } */
469 /* if (diagnostic > 3) */
470 /* { */
471 /* sprintf (midiMessage, "Negative Flux at: R %d X %3d F %4d PhotomB %10.2f", */
472 /* R, X, f, (((compressedPhotomB->iDispFringe)[R])[X])[f]); */
473 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
474 /* } */
475 /* } */
476  // Reject frames which are not 'T'
477  if (compressedPhotomB->tarType[f] != 'T')
478  compressedPhotomB->rejectList[X][f] |= BSL_SKY_SCAN;
479  }
480  }
481  }
482 
483 
484 
485 
486 
487 
488 
489 
490 
491 
492  // Display data with background removed
493  if (plotFile)
494  {
495  array = (double *) calloc (formatInterf->numOfFrames, sizeof (double));
496 
497  n = 0;
498  fluxAve = 0.0;
499  for (f = 0; f < formatInterf->numOfFrames; f++)
500  {
501  if (compressedInterf->tarType[f] == 'T')
502  {
503  array[n] = compressedInterf->iFringe1[f];
504  fluxAve += array[n];
505  n++;
506  }
507  }
508  fluxAve /= n;
509  cpl_msg_info(cpl_func,"Interf DATA2 Average Flux = %f \n", fluxAve);
510  midiCreatePlotFileDouble2D ("InterfCleanDATA2", "Interferometry DATA2 (Sky Removed)",
511  "Frame", "Flux", 0, array, 0, n, 1);
512 
513  n = 0;
514  fluxAve = 0.0;
515  for (f = 0; f < formatInterf->numOfFrames; f++)
516  {
517  if (compressedInterf->tarType[f] == 'T')
518  {
519  array[n] = compressedInterf->iFringe2[f];
520  fluxAve += array[n];
521  n++;
522  }
523  }
524  fluxAve /= n;
525  cpl_msg_info(cpl_func,"Interf DATA3 Average Flux = %f \n", fluxAve);
526  midiCreatePlotFileDouble2D ("InterfCleanDATA3", "Interferometry DATA3 (Sky Removed)",
527  "Frame", "Flux", 0, array, 0, n, 1);
528 
529  n = 0;
530  for (f = 0; f < formatInterf->numOfFrames; f++)
531  {
532  if (compressedInterf->tarType[f] == 'T')
533  {
534  array[n] = compressedInterf->iFringe[f];
535  n++;
536  }
537  }
538  midiCreatePlotFileDouble2D ("InterfCleanDATA2_DATA3", "Interferometry DATA2-DATA3 (Sky Removed)",
539  "Frame", "Flux", 0, array, 0, n, 1);
540 
541  n = 0;
542  fluxAve = 0.0;
543  for (f = 0; f < formatPhotomA->numOfFrames; f++)
544  {
545  if (compressedPhotomA->tarType[f] == 'T')
546  {
547  array[n] = compressedPhotomA->iFringe1[f];
548  fluxAve += array[n];
549  n++;
550  }
551  }
552  fluxAve /= n;
553  cpl_msg_info(cpl_func,"PhotomA DATA1 Average Flux = %f \n", fluxAve);
554  midiCreatePlotFileDouble2D ("PhotomACleanDATA1", "Photometry A DATA1 (Sky Removed)",
555  "Frame", "Flux", 0, array, 0, n, 1);
556 
557  n = 0;
558  fluxAve = 0.0;
559  for (f = 0; f < formatPhotomB->numOfFrames; f++)
560  {
561  if (compressedPhotomB->tarType[f] == 'T')
562  {
563  array[n] = compressedPhotomB->iFringe1[f];
564  fluxAve += array[n];
565  n++;
566  }
567  }
568  fluxAve /= n;
569  cpl_msg_info(cpl_func,"PhotomB DATA4 Average Flux = %f \n", fluxAve);
570  midiCreatePlotFileDouble2D ("PhotomBCleanDATA4", "Photometry B DATA4 (Sky Removed)",
571  "Frame", "Flux", 0, array, 0, n, 1);
572 
573  free (array);
574  }
575 
576  // Display for each channel
577  if (plotFile && diagnostic > 4)
578  {
579  arrayF = (float *) calloc (formatInterf->numOfFrames, sizeof (float));
580  fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
581  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
582 
583  for (R = 0; R < formatInterf->numOfRegionsToProcess; R++)
584  {
585  for (X = 0; X < formatInterf->iXWidth; X++)
586  {
587  if (badChannelList[X])
588  continue;
589 
590  n = 0;
591  for (f = 0; f < formatInterf->numOfFrames; f++)
592  {
593  if (compressedInterf->tarType[f] == 'T' && !(compressedInterf->rejectList[X][f]))
594  {
595  arrayF[n] = compressedInterf->iDispFringe[R][X][f];
596  n++;
597  }
598  }
599  sprintf (fileName, "InterfCleanDATA%d_X%d", R+2, X+1);
600  sprintf (title, "Interferometry DATA%d for Channel %d (Sky Removed)", R+2, X+1);
601  midiCreatePlotFile2D (fileName, title, "Frame", "Flux", 1, arrayF, 0, n, 1, 0);
602  }
603  }
604  for (R = 0; R < formatPhotomA->numOfRegionsToProcess; R++)
605  {
606  for (X = 0; X < formatPhotomA->iXWidth; X++)
607  {
608  if (badChannelList[X])
609  continue;
610 
611  n = 0;
612  for (f = 0; f < formatPhotomA->numOfFrames; f++)
613  {
614  if (compressedPhotomA->tarType[f] == 'T' && !(compressedPhotomA->rejectList[X][f]))
615  {
616  arrayF[n] = compressedPhotomA->iDispFringe[R][X][f];
617  n++;
618  }
619  }
620  sprintf (fileName, "PhotomACleanDATA1_X%d", X+1);
621  sprintf (title, "Photometry A DATA1 for Channel %d (Sky Removed)", X+1);
622  midiCreatePlotFile2D (fileName, title, "Frame", "Flux", 1, arrayF, 0, n, 1, 0);
623  }
624  }
625  for (R = 0; R < formatPhotomB->numOfRegionsToProcess; R++)
626  {
627  for (X = 0; X < formatPhotomB->iXWidth; X++)
628  {
629  if (badChannelList[X])
630  continue;
631 
632  n = 0;
633  for (f = 0; f < formatPhotomB->numOfFrames; f++)
634  {
635  if (compressedPhotomB->tarType[f] == 'T' && !(compressedPhotomB->rejectList[X][f]))
636  {
637  arrayF[n] = compressedPhotomB->iDispFringe[R][X][f];
638  n++;
639  }
640  }
641  sprintf (fileName, "PhotomBCleanDATA4_X%d", X+1);
642  sprintf (title, "Photometry B DATA4 for Channel %d (Sky Removed)", X+1);
643  midiCreatePlotFile2D (fileName, title, "Frame", "Flux", 1, arrayF, 0, n, 1, 0);
644  }
645  }
646  free (fileName);
647  free (title);
648  free (arrayF);
649  }
650 
651 
652 
653  // Display the mean flux as a function of the channel
654 
655  if (plotFile)
656  {
657  arrayF = (float *) calloc (formatInterf->iXWidth, sizeof (float));
658  fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
659  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
660 
661  for (R = 0; R < formatInterf->numOfRegionsToProcess; R++)
662  {
663  for (X = 0; X < formatInterf->iXWidth; X++)
664  {
665  arrayF[X]=0;
666  if (badChannelList[X])
667  continue;
668 
669  n = 0;
670  for (f = 0; f < formatInterf->numOfFrames; f++)
671  {
672  if (compressedInterf->tarType[f] == 'T' && !(compressedInterf->rejectList[X][f]))
673  {
674  arrayF[X] += compressedInterf->iDispFringe[R][X][f];
675  n++;
676  }
677  }
678  arrayF[X] /=(float)n;
679  }
680 
681  sprintf (fileName, "MeanInterfCleanDATA%d", R+1);
682  sprintf (title, "Mean Interferometry DATA%d (Sky Removed)", R+1);
683  midiCreatePlotFile2D (fileName, title, "Channel", "Flux", 0, arrayF, 0, formatInterf->iXWidth, 1, 0);
684  }
685  free (fileName);
686  free (title);
687  free (arrayF);
688  }
689 
690 
691  // Finalise rejection list
692  finaliseRejectListInterf ("Combined Interferometry", formatInterf, compressedInterf, error);
693  if (*error) return;
694  finaliseRejectListPhotom ("Photometry A", formatPhotomA, compressedPhotomA, error);
695  if (*error) return;
696  finaliseRejectListPhotom ("Photometry B", formatPhotomB, compressedPhotomB, error);
697  if (*error) return;
698 
699  return;
700 
701 }
702 /*****************************************************************************/
703 
704 
705 /******************************************************************************
706 * European Southern Observatory
707 * VLTI MIDI Data Reduction Software
708 *
709 * Module name: applyOpticalCompensation
710 * Input/Output: See function arguments to avoid duplication
711 * Description: Uses the existing Transfer Ratios to carry out optical compensation
712 * If Transfer Ratios is not available in the current directory
713 * it will extract the data from the static database
714 *
715 * History:
716 * 06-Dec-05 (csabet) Created
717 ******************************************************************************/
718 void applyOpticalCompensation (
719  MidiFiles *fileNames, // In: Pointer to midi files structure
720  ImageFormat *format, // In: Interf size parameters
721  CompressedData *compressedInterf, // Ou: Pointer to the compressed interferometry data structure
722  CompressedData *compressedPhotomA, // Ou: Pointer to the compressed photom A data structure
723  CompressedData *compressedPhotomB, // Ou: Pointer to the compressed photom B data structure
724  int *error, // Ou: Error status
725  cpl_parameterlist *parlist,
726  cpl_frameset *frameset)
727 {
728 
729  // Local Declarations
730  // ------------------
731  const char routine[] = "applyOpticalCompensation";
732 /* FILE *trrPtr=NULL; */
733  TransferRatios *trr;
734  int i, X, n;
735 /* int numOfRecords; */
736 /* char *fileString; */
737  char * tag=NULL;
738  char * softag=NULL;
739  cpl_frame * cur_frame;
740  cpl_table * table;
741  float * kappamatrix11=NULL;
742  float * kappamatrix12=NULL;
743  float * kappamatrix21=NULL;
744  float * kappamatrix22=NULL;
745  float * kappamatrix11_error=NULL;
746  float * kappamatrix12_error=NULL;
747  float * kappamatrix21_error=NULL;
748  float * kappamatrix22_error=NULL;
749  int dimenkappamatrix=0;
750  cpl_errorstate prestate = cpl_errorstate_get();
751 
752 
753  // Algorithm
754  // ---------
755  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
756  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
757 
758  // Initialise
759  *error = 0;
760 
761  // Check if Transfer Ratios file is available. Try to open the file for reading
762  cpl_msg_info(cpl_func,"\nApplying Optical Compensation for batch %d \n", batchNumber);
763  cpl_msg_info(cpl_func,"--------------------------------------- \n");
764  fprintf (midiReportPtr, "\nApplying Optical Compensation for batch %d \n", batchNumber);
765  fprintf (midiReportPtr, "--------------------------------------- \n");
766 
767 
768 /* ---------------------------------------- */
769  {
770 /* Grism or Prism? */
771  if (strcmp(format->grismId,"GRISM")==0){
772  softag = cpl_sprintf("%s", "MIDI_KAPPAMATRIX_GRISM");
773  }
774  if (strcmp(format->grismId,"PRISM")==0){
775  softag = cpl_sprintf("%s", "MIDI_KAPPAMATRIX_PRISM");
776  }
777 
778 
779  cur_frame = cpl_frameset_get_first(frameset);
780  if (cur_frame == NULL) {
781  cpl_msg_error(cpl_func, "No frame found in the SOF");
782  return ;
783 
784  }
785 
786  while(cur_frame)
787  {
788  /* Check the right tags */
789  tag = (char*)cpl_frame_get_tag(cur_frame);
790  if (strcmp(tag, softag)) {
791  cur_frame = cpl_frameset_get_next( frameset );
792  continue;
793  }
794  else{
795  cpl_msg_info(cpl_func, "Kappamatrix found in the SOF: %s\n",cpl_frame_get_filename(cur_frame));
796  break;
797  }
798 /* cur_frame = cpl_frameset_get_next( frameset ); */
799  }
800 
801  if (strcmp(tag, softag)) {
802  cpl_msg_info(cpl_func, "No Kappamatrix found in the SOF!");
803  cpl_msg_warning(cpl_func, "Subsequent computational values are without Optical Compensation");
804  *error = 1;
805  return;
806  }
807 
808  cpl_free(softag);
809 
810  /* Load extension MIDI_KAPPAMATRIX == extension 1 Do it more clever in the future*/
811 
812  prestate = cpl_errorstate_get();
813  if((table = cpl_table_load(cpl_frame_get_filename(cur_frame), 1, 1))==NULL)
814  {
815  cpl_msg_info(cpl_func, "No siutable table found in the file %s\n",cpl_frame_get_filename(cur_frame));
816  cpl_msg_warning(cpl_func, "Subsequent computational values are without Optical Compensation");
817  cpl_errorstate_set(prestate);
818  *error = 1;
819  return;
820  }
821 
822  /* If all is Ok read the values */
823 
824  if (cpl_table_has_column(table, "kappam11"))
825  {
826  dimenkappamatrix=cpl_table_get_column_dimensions(table, "kappam11");
827  kappamatrix11=cpl_table_get_data_float(table, "kappam11");
828  kappamatrix12=cpl_table_get_data_float(table, "kappam12");
829  kappamatrix21=cpl_table_get_data_float(table, "kappam21");
830  kappamatrix22=cpl_table_get_data_float(table, "kappam22");
831  kappamatrix11_error=cpl_table_get_data_float(table, "kappam11_error");
832  kappamatrix12_error=cpl_table_get_data_float(table, "kappam12_error");
833  kappamatrix21_error=cpl_table_get_data_float(table, "kappam21_error");
834  kappamatrix22_error=cpl_table_get_data_float(table, "kappam22_error");
835 /* cpl_msg_info(cpl_func, "kappam11: %f", kappamatrix11[0]); */
836  }
837  else{
838  cpl_msg_info(cpl_func, "No siutable table column found in the file %s\n",cpl_frame_get_filename(cur_frame));
839  cpl_msg_warning(cpl_func, "Subsequent computational values are without Optical Compensation");
840  *error = 1;
841  return;
842  }
843 
844  trr = callocTransferRatios (format->iXWidth);
845 
846  cpl_msg_info(cpl_func,"Dimension: %d",dimenkappamatrix);
847 /* for (i=0; i<dimenkappamatrix;i++){ */
848  for (i=0; i<format->iXWidth;i++){
849 
850  trr->ka1[i]=kappamatrix11[i] ;
851  trr->siga1[i]=kappamatrix11_error[i] ;
852  trr->ka2[i]=kappamatrix12[i] ;
853  trr->siga2[i]=kappamatrix12_error[i] ;
854  trr->kb1[i]=kappamatrix21[i] ;
855  trr->sigb1[i]=kappamatrix21_error[i] ;
856  trr->kb2[i]=kappamatrix22[i] ;
857  trr->sigb2[i]=kappamatrix22_error[i] ;
858  cpl_msg_info(cpl_func,"%3d %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n", i,
859  trr->ka1[i], trr->siga1[i], trr->ka2[i], trr->siga2[i],
860  trr->kb1[i], trr->sigb1[i], trr->kb2[i], trr->sigb2[i]);
861  }
862 
863  for (i=0; i<format->iXWidth;i++){
864  if (!(trr->ka1[i]) || !(trr->ka2[i]) || !(trr->kb1[i]) || !(trr->kb2[i]))
865  {
866  badChannelList[i] |= BSL_DATA_ERROR;
867  cpl_msg_info(cpl_func,"%3d <-- %s --> \n", i, UNAV);
868  fprintf (midiReportPtr, "%3d <-- %s --> QCLOG \n", i, UNAV);
869  }
870  }
871 
872  // Compute compensated beams:
873 
874  // Check for valid channels
875  n = 0;
876  for (X = 0; X < format->iXWidth; X++)
877  {
878  if (!(badChannelList[X]))
879  n++;
880  }
881  if (!n)
882  {
883  cpl_msg_warning(cpl_func, "Cannot find any valid Transfer Ratios");
884  cpl_msg_warning(cpl_func, "Subsequent computational values are without Optical Compensation");
885  *error = 1;
886  freeTransferRatios (trr);
887  return;
888  }
889 
890  // Get compensated beams
891  getCompensatedBeams (trr, format, compressedInterf, compressedPhotomA, compressedPhotomB);
892  freeTransferRatios (trr);
893  cpl_table_delete(table);
894 /* *error = 1; */
895  return;
896  }
897 
898 /* ---------------------------------------- */
899 
900 
901 
902 
903 /* if (diagnostic)cpl_msg_info(cpl_func,"Trying to extract Transfer Ratios from %s \n", fileNames->trrNameRead); */
904 /* fprintf (midiReportPtr, "Trying to extract Transfer Ratios from %s \n", fileNames->trrNameRead); */
905 /* if ((trrPtr = fopen (fileNames->trrNameRead, "r")) == NULL) */
906 /* { */
907 /* *error = 1; */
908 /* sprintf (midiMessage, "Cannot open Transfer Ratios file %s in the local directory", fileNames->trrNameRead); */
909 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
910 /* } */
911 
912 /* // If Transfer Ratios file is not available in the local directory try the static database */
913 /* if (*error) */
914 /* { */
915 /* *error = 0; */
916 /* fileString = (char *) calloc (MAX_STRING_LENGTH, sizeof (char)); */
917 /* sprintf (fileString , "%s_%s.dat", fileNames->transferRatiosName, format->grismId); */
918 /* if (diagnostic)cpl_msg_info(cpl_func,"Trying to extract Transfer Ratios from the static database %s \n", fileString); */
919 /* fprintf (midiReportPtr, "Trying to extract Transfer Ratios from the static database %s \n", fileString); */
920 /* if ((trrPtr = fopen (fileString, "r")) == NULL) */
921 /* { */
922 /* sprintf (midiMessage, "Cannot open Transfer Ratios file %s", fileString); */
923 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
924 /* *error = 1; */
925 /* } */
926 /* free (fileString); */
927 /* } */
928 
929 /* // If all is well, read the supporting parameters */
930 /* if (!(*error)) */
931 /* { */
932 /* // Read number of record in the file */
933 /* if (fscanf (trrPtr, "%d \n", &numOfRecords) == EOF) */
934 /* { */
935 /* *error = 1; */
936 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Number of Records"); */
937 /* if (trrPtr) fclose (trrPtr); */
938 /* } */
939 /* else */
940 /* { */
941 /* // Check if number of records is consistent */
942 /* if (numOfRecords != format->iXWidth) */
943 /* { */
944 /* *error = 1; */
945 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent Number of Records"); */
946 /* cpl_msg_info(cpl_func,"Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
947 /* fprintf (midiReportPtr, "Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
948 /* if (trrPtr) fclose (trrPtr); */
949 /* } */
950 /* } */
951 
952 /* // If no error, extract the data */
953 /* if (!(*error)) */
954 /* { */
955 /* trr = callocTransferRatios (format->iXWidth); */
956 
957 /* // Extract Transfer Ratios. File pointer should now be at the second line */
958 /* cpl_msg_info(cpl_func,"Channel ka1 siga1 ka2 siga2 kb1 sigb1 kb2 sigb2 \n"); */
959 /* fprintf (midiReportPtr, "Channel ka1 siga1 ka2 siga2 kb1 sigb1 kb2 sigb2 \n"); */
960 
961 
962 /* for (i = 0; i < format->iXWidth; i++) */
963 /* { */
964 /* if (fscanf (trrPtr, "%f %f %f %f %f %f %f %f \n", &(trr->ka1[i]), &(trr->siga1[i]), */
965 /* &(trr->ka2[i]), &(trr->siga2[i]), &(trr->kb1[i]), &(trr->sigb1[i]), */
966 /* &(trr->kb2[i]), &(trr->sigb2[i])) == EOF) */
967 /* { */
968 /* *error = 1; */
969 /* sprintf (midiMessage, "Extracted %d records. Expected %d", i, format->iXWidth); */
970 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
971 /* if (trrPtr) fclose (trrPtr); */
972 /* freeTransferRatios (trr); */
973 /* break; */
974 /* } */
975 /* else */
976 /* { */
977 /* if (!(trr->ka1[i]) || !(trr->ka2[i]) || !(trr->kb1[i]) || !(trr->kb2[i])) */
978 /* { */
979 /* badChannelList[i] |= BSL_DATA_ERROR; */
980 /* cpl_msg_info(cpl_func,"%3d <-- %s --> \n", i, UNAV); */
981 /* fprintf (midiReportPtr, "%3d <-- %s --> QCLOG \n", i, UNAV); */
982 /* if (diagnostic > 2) */
983 /* { */
984 /* sprintf (midiMessage, "Found invalid Transfer Ratios for channel %3d", i); */
985 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
986 /* } */
987 /* } */
988 /* else */
989 /* { */
990 /* cpl_msg_info(cpl_func,"%3d %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n", i, */
991 /* trr->ka1[i], trr->siga1[i], trr->ka2[i], trr->siga2[i], */
992 /* trr->kb1[i], trr->sigb1[i], trr->kb2[i], trr->sigb2[i]); */
993 /* fprintf (midiReportPtr, "%3d %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f QCLOG \n", i, */
994 /* trr->ka1[i], trr->siga1[i], trr->ka2[i], trr->siga2[i], */
995 /* trr->kb1[i], trr->sigb1[i], trr->kb2[i], trr->sigb2[i]); */
996 /* } */
997 /* } */
998 /* } */
999 
1000 /* // Compute compensated beams */
1001 /* if (!(*error)) */
1002 /* { */
1003 /* sprintf (midiMessage, "Extracted the above %d Transfer Ratios records \n", format->iXWidth); */
1004 /* midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
1005 /* if (trrPtr) fclose (trrPtr); */
1006 
1007 /* // Check for valid channels */
1008 /* n = 0; */
1009 /* for (X = 0; X < format->iXWidth; X++) */
1010 /* { */
1011 /* if (!(badChannelList[X])) */
1012 /* n++; */
1013 /* } */
1014 /* if (!n) */
1015 /* { */
1016 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot find any valid Transfer Ratios"); */
1017 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, */
1018 /* "Subsequent computational values are without Optical Compensation"); */
1019 /* *error = 1; */
1020 /* freeTransferRatios (trr); */
1021 /* return; */
1022 /* } */
1023 
1024 /* // Get compensated beams */
1025 /* getCompensatedBeams (trr, format, compressedInterf, compressedPhotomA, compressedPhotomB); */
1026 /* freeTransferRatios (trr); */
1027 /* } */
1028 /* } */
1029 /* else */
1030 /* { */
1031 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, */
1032 /* "Subsequent computational values are without Optical Compensation"); */
1033 /* } */
1034 /* } */
1035 /* else */
1036 /* { */
1037 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, */
1038 /* "Subsequent computational values are without Optical Compensation"); */
1039 /* } */
1040 
1041 /* return; */
1042 }
1043 /*****************************************************************************/
1044 
1045 
1046 
1047 /******************************************************************************
1048 * European Southern Observatory
1049 * VLTI MIDI Data Reduction Software
1050 *
1051 * Module name: getCompensatedBeams
1052 * Input/Output: See function arguments to avoid duplication
1053 * Description: Computes compensated Interferometry channels
1054 *
1055 * History:
1056 * 06-Mar-06 (csabet) Created
1057 ******************************************************************************/
1058 void getCompensatedBeams (
1059  TransferRatios *trr, // In: Transfer Ratios
1060  ImageFormat *format, // In: Interf size parameters
1061  CompressedData *compressedInterf, // Ou: Pointer to the compressed interferometry data structure
1062  CompressedData *compressedPhotomA, // Ou: Pointer to the compressed photom A data structure
1063  CompressedData *compressedPhotomB) // Ou: Pointer to the compressed photom B data structure
1064 {
1065 
1066  // Local Declarations
1067  // ------------------
1068  const char routine[] = "getCompensatedBeams";
1069  int f, X, R;
1070  double compensate;
1071 
1072  // Algorithm
1073  // ---------
1074  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1075  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
1076 
1077  // For all regions
1078  for (R = 0; R < format->numOfRegionsToProcess; R++)
1079  {
1080  // For all valid channels (Wavelengths)
1081  for (X = 0; X < format->iXWidth; X++)
1082  {
1083  if (badChannelList[X])
1084  continue;
1085 
1086  for (f = 0; f < format->numOfFrames; f++)
1087  {
1088  // Process good frames only
1089  if (!((compressedInterf->rejectList[X])[f]) )
1090  {
1091 /* At the moment no compensation in the fringe */
1092 /* channels should be done, but one has to compensate */
1093 /* the photA and photB photometry. photA and photB are */
1094 /* scaled to the total flux of telescope A and */
1095 /* telescope B used to produce the fringes(!!), respectively. */
1096 
1097  if (R == 0)
1098  {
1099  if(trr->ka1[X] > 0 && trr->ka2[X] > 0 && trr->kb1[X] > 0 && trr->kb2[X] > 0)
1100  {
1101 /* Total flux of telescope A and B */
1102 /* ((compressedPhotomA->iDispFringe[0])[X])[f]=(((compressedPhotomA->iDispFringe[0])[X])[f])*(1.+ trr->ka1[X] + trr->kb1[X]); */
1103 /* ((compressedPhotomB->iDispFringe[0])[X])[f]=(((compressedPhotomB->iDispFringe[0])[X])[f])*(1.+trr->ka2[X] + trr->kb2[X]); */
1104 
1105 /* Total flux of telescope A and B used to produce the fringes (!) */
1106  ((compressedPhotomA->iDispFringe[0])[X])[f]=(((compressedPhotomA->iDispFringe[0])[X])[f])*(trr->ka1[X] + trr->kb1[X]);
1107  ((compressedPhotomB->iDispFringe[0])[X])[f]=(((compressedPhotomB->iDispFringe[0])[X])[f])*(trr->ka2[X] + trr->kb2[X]);
1108  }
1109  else
1110  {
1111  ((compressedPhotomA->iDispFringe[0])[X])[f]=(((compressedPhotomA->iDispFringe[0])[X])[f]);
1112  ((compressedPhotomB->iDispFringe[0])[X])[f]=(((compressedPhotomB->iDispFringe[0])[X])[f]);
1113  }
1114 /* cpl_msg_info(cpl_func, "PhotA: %f PhotB: %f ka1: %f kb1 %f Fringe: %f", ((compressedPhotomA->iDispFringe[R])[X])[f], */
1115 /* ((compressedPhotomB->iDispFringe[R])[X])[f], trr->ka1[X], trr->kb1[X],((compressedInterf->iDispFringe[R])[X])[f]); */
1116 
1117  }
1118  continue;
1119 
1120  if (R == 0)
1121  {
1122  compensate=1. / ( (sqrt(((compressedPhotomA->iDispFringe[R])[X])[f] *
1123  ((compressedPhotomB->iDispFringe[R])[X])[f])) *
1124  (sqrt(trr->ka1[X] * trr->kb1[X])) );
1125  if(isnan(compensate) || isinf(compensate))
1126  {
1127  compensate=0.;
1128 /* cpl_msg_info(cpl_func, "PhotA: %f PhotB: %f ka1: %f kb1 %f ", ((compressedPhotomA->iDispFringe[R])[X])[f], */
1129 /* ((compressedPhotomB->iDispFringe[R])[X])[f], trr->ka1[X], trr->kb1[X]); */
1130  }
1131  ((compressedInterf->iDispFringe[R])[X])[f] = ((compressedInterf->iDispFringe[R])[X])[f] * compensate;
1132  }
1133  else
1134  {
1135  compensate=1. / ( (sqrt(((compressedPhotomA->iDispFringe[R-1])[X])[f] *
1136  ((compressedPhotomB->iDispFringe[R-1])[X])[f])) *
1137  (sqrt(trr->ka2[X] * trr->kb2[X])) );
1138 
1139  if(isnan(compensate) || isinf(compensate))
1140 /* if(1) */
1141  {
1142  compensate=0.;
1143 /* cpl_msg_info(cpl_func, "PhotA: %f PhotB: %f ka2: %f kb2 %f ", ((compressedPhotomA->iDispFringe[R-1])[X])[f], */
1144 /* ((compressedPhotomB->iDispFringe[R-1])[X])[f], trr->ka2[X], trr->kb2[X]); */
1145  }
1146 
1147  ((compressedInterf->iDispFringe[R])[X])[f] =
1148  ((compressedInterf->iDispFringe[R])[X])[f] * compensate;
1149 
1150  }
1151  }
1152  else
1153  {
1154  if (diagnostic > 2)
1155  {
1156  sprintf (midiMessage, "Interferometry data in region %d, channel %3d, frame %4d cannot be compensated",
1157  R, X, f);
1158  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
1159  }
1160  }
1161  }
1162  }
1163  }
1164 
1165  return;
1166 }
1167 /*****************************************************************************/