MIDI Pipeline Reference Manual  2.8.3
diagnostics.c
1 /******************************************************************************
2 *******************************************************************************
3 * European Southern Observatory
4 * VLTI Data Reduction Software
5 *
6 * File name: diagnostics.c
7 * Description: Contains the routines for diagnostic purposes
8 *
9 *
10 * History:
11 * 08-Jan-04 (csabet) Created
12 *******************************************************************************
13 ******************************************************************************/
14 
15 /******************************************************************************
16 * Compiler directives
17 ******************************************************************************/
18 
19 /******************************************************************************
20 * Include files
21 ******************************************************************************/
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <cpl.h>
27 #include <math.h>
28 #include <time.h>
29 #include <stdlib.h>
30 #include "midiGlobal.h"
31 #include "midiLib.h"
32 #include "errorHandling.h"
33 #include "diagnostics.h"
34 #include "qfits.h"
35 
36 /******************************************************************************
37 * Global Variables
38 ******************************************************************************/
39 
40 /******************************************************************************
41 * Prototypes
42 ******************************************************************************/
43 
44 /*============================ C O D E A R E A ===========================*/
45 
46 
47 /******************************************************************************
48 * European Southern Observatory
49 * VLTI MIDI Data Reduction Software
50 *
51 * Module name: midiCreatePlotFileDouble3D
52 * Input/Output: See function arguments to avoid duplication
53 * Description: Creates a 3D plot file
54 *
55 * History:
56 * 08-Apr-05 (csabet)
57 ******************************************************************************/
58 void midiCreatePlotFileDouble3D (
59  const char *plotFileName,
60  const char *title,
61  const char *xLabel,
62  const char *yLabel,
63  const char *zLabel,
64  int deletePlot,
65  double *image,
66  int sizeX,
67  int sizeY,
68  const char *style,
69  const char *lineType)
70 {
71 
72  // Local Declarations
73  // ------------------
74  const char routine[] = "midiCreatePlotFileDouble3D";
75  int i, j, frame, zero = 0;
76  FILE *dataFilePtr=NULL, *cmdFilePtr=NULL;
77  char *dataFilePath, *cmdFileName, *argument;
78 
79  // Algorithm
80  // ---------
81  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
82  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
83 
84  // Allocate memory
85  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
86  cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
87  argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
88 
89  // Create the plot file
90  sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
91  dataFilePtr = fopen (dataFilePath, "w");
92 
93  for (i = 0; i < sizeY; i++)
94  {
95  frame = i * sizeX;
96  for (j = 0; j < sizeX; j++)
97  {
98  if (isnan (image[frame + j])) fprintf (dataFilePtr, "%d \n", zero);
99  else fprintf (dataFilePtr, "%8.4f ", image[frame + j]);
100  }
101 
102  fprintf (dataFilePtr, "\n");
103  }
104  fclose (dataFilePtr);
105 
106  // Create the command file
107  if (plotFile > 1)
108  {
109  sprintf (cmdFileName, "plotCmdFile.log");
110  cmdFilePtr = fopen (cmdFileName, "w");
111  fprintf (cmdFilePtr, "set title \'%s\' \n", title);
112  fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
113  fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
114  fprintf (cmdFilePtr, "set zlabel \'%s\' \n", zLabel);
115  fprintf (cmdFilePtr, "set xrange [0:%d] \n", sizeX);
116  fprintf (cmdFilePtr, "set yrange [0:%d] \n", sizeY);
117  fprintf (cmdFilePtr, "set ticslevel 0 \n");
118  fprintf (cmdFilePtr, "splot \'%s\' matrix with %s %s \n", dataFilePath, style, lineType);
119 
120  if (plotDuration == -1)
121  {
122  cpl_msg_info(cpl_func,"\n");
123  fprintf (cmdFilePtr, "pause %d \" ***** Hit Return to continue *****\" \n", plotDuration);
124  }
125  else
126  fprintf (cmdFilePtr, "pause %d \n", plotDuration);
127 
128  fclose (cmdFilePtr);
129 
130  // Run the command file
131  sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 900x900+0+0 %s", cmdFileName);
132  system (argument);
133 
134  // Remove temporary files
135  remove (cmdFileName);
136  }
137 
138  // Delete plot file if display only
139  if (deletePlot || plotFile == 3) remove (dataFilePath);
140 
141  // Release memory
142  free (dataFilePath);
143  free (cmdFileName);
144  free (argument);
145 
146  return;
147 }
148 /*****************************************************************************/
149 
150 
151 
152 
153 /******************************************************************************
154 * European Southern Observatory
155 * VLTI MIDI Data Reduction Software
156 *
157 * Module name: midiCreatePlotFile3D
158 * Input/Output: See function arguments to avoid duplication
159 * Description: Creates a 3D plot file
160 *
161 * History:
162 * 08-Apr-05 (csabet)
163 ******************************************************************************/
164 void midiCreatePlotFile3D (
165  const char *plotFileName,
166  const char *title,
167  const char *xLabel,
168  const char *yLabel,
169  const char *zLabel,
170  int deletePlot,
171  float *image,
172  int sizeX,
173  int sizeY,
174  const char *style,
175  const char *lineType)
176 {
177 
178  // Local Declarations
179  // ------------------
180  const char routine[] = "midiCreatePlotFile3D";
181  int i, j, frame, zero = 0;
182  FILE *dataFilePtr=NULL, *cmdFilePtr=NULL;
183  char *dataFilePath, *cmdFileName, *argument;
184 
185  // Algorithm
186  // ---------
187  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
188  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
189 
190  // Allocate memory
191  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
192  cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
193  argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
194 
195  // Create the plot file
196  sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
197  dataFilePtr = fopen (dataFilePath, "w");
198 
199  for (i = 0; i < sizeY; i++)
200  {
201  frame = i * sizeX;
202  for (j = 0; j < sizeX; j++)
203  {
204  if (isnan (image[frame + j])) fprintf (dataFilePtr, "%d \n", zero);
205  else fprintf (dataFilePtr, "%8.4f ", image[frame + j]);
206  }
207 
208  fprintf (dataFilePtr, "\n");
209  }
210  fclose (dataFilePtr);
211 
212  // Create the command file
213  if (plotFile > 1)
214  {
215  sprintf (cmdFileName, "plotCmdFile.log");
216  cmdFilePtr = fopen (cmdFileName, "w");
217  fprintf (cmdFilePtr, "set title \'%s\' \n", title);
218  fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
219  fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
220  fprintf (cmdFilePtr, "set zlabel \'%s\' \n", zLabel);
221  fprintf (cmdFilePtr, "set xrange [0:%d] \n", sizeX);
222  fprintf (cmdFilePtr, "set yrange [0:%d] \n", sizeY);
223  fprintf (cmdFilePtr, "set ticslevel 0 \n");
224  fprintf (cmdFilePtr, "splot \'%s\' matrix with %s %s \n", dataFilePath, style, lineType);
225 
226  if (plotDuration == -1)
227  {
228  cpl_msg_info(cpl_func,"\n");
229  fprintf (cmdFilePtr, "pause %d \" ***** Hit Return to continue *****\" \n", plotDuration);
230  }
231  else
232  fprintf (cmdFilePtr, "pause %d \n", plotDuration);
233 
234  fclose (cmdFilePtr);
235 
236  // Run the command file
237  sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 900x900+0+0 %s", cmdFileName);
238  system (argument);
239 
240  // Remove temporary files
241  remove (cmdFileName);
242  }
243 
244  // Delete plot file if display only
245  if (deletePlot || plotFile == 3) remove (dataFilePath);
246 
247  // Release memory
248  free (dataFilePath);
249  free (cmdFileName);
250  free (argument);
251 
252  return;
253 }
254 /*****************************************************************************/
255 
256 
257 
258 /******************************************************************************
259 * European Southern Observatory
260 * VLTI MIDI Data Reduction Software
261 *
262 * Module name: midiCreatePlotFileDouble2D
263 * Input/Output: See function arguments to avoid duplication
264 * Description: Creates a plot file
265 *
266 * History:
267 * 14-Feb-05 (csabet)
268 ******************************************************************************/
269 void midiCreatePlotFileDouble2D (
270  const char *plotFileName,
271  const char *title,
272  const char *xLabel,
273  const char *yLabel,
274  int deletePlot,
275  double *array,
276  int begin,
277  int end,
278  int interval)
279 {
280 
281  // Local Declarations
282  // ------------------
283  const char routine[] = "midiCreatePlotFileDouble2D";
284  int i, zero = 0;
285  FILE *dataFilePtr=NULL, *cmdFilePtr=NULL;
286  char *dataFilePath, *cmdFileName, *argument;
287 
288  // Algorithm
289  // ---------
290  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
291  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
292 
293  // Allocate memory
294  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
295  cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
296  argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
297 
298  // Create the plot file
299  sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
300  dataFilePtr = fopen (dataFilePath, "w");
301  for (i = begin; i < end; i += interval)
302  {
303  if (isnan (array[i])) fprintf (dataFilePtr, "%d \n", zero);
304  else fprintf (dataFilePtr, "%f \n", array[i]);
305  }
306  fclose (dataFilePtr);
307 
308  // Display plot file
309  if (plotFile > 1)
310  {
311  sprintf (cmdFileName, "plotCmdFile.grb");
312  cmdFilePtr = fopen (cmdFileName, "w");
313  fprintf (cmdFilePtr, "set title \'%s\' \n", title);
314  fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
315  fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
316  fprintf (cmdFilePtr, "plot \'%s\' with lines 1\n", dataFilePath);
317  if (plotDuration == -1)
318  {
319  cpl_msg_info(cpl_func,"\n");
320  fprintf (cmdFilePtr, "pause %d \" ***** Hit Return to continue *****\" \n", plotDuration);
321  }
322  else
323  fprintf (cmdFilePtr, "pause %d \n", plotDuration);
324 
325  fclose (cmdFilePtr);
326 
327 
328  // Run the command file
329  sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
330  system (argument);
331 
332  // Remove temporary files
333  remove (cmdFileName);
334  }
335 
336  // Delete plot file if display only
337  if (deletePlot || plotFile == 3) remove (dataFilePath);
338 
339  // Release memory
340  free (dataFilePath);
341  free (cmdFileName);
342  free (argument);
343 
344  return;
345 }
346 /*****************************************************************************/
347 
348 
349 /******************************************************************************
350 * European Southern Observatory
351 * VLTI MIDI Data Reduction Software
352 *
353 * Module name: midiCreateReplotFileDouble2D2P
354 * Input/Output: See function arguments to avoid duplication
355 * Description: Creates a plot file for a 2 column table
356 *
357 * History:
358 * 14-Feb-05 (csabet)
359 ******************************************************************************/
360 void midiCreateReplotFileDouble2D2P (
361  char *plotFileName,
362  char *title,
363  char *xLabel,
364  char *yLabel,
365  int deletePlot,
366  double *arrayX, // In: Array X
367  double *arrayY,
368  int begin, // In: Start of the arrayX
369  int end, // In: End of arrayX
370  int interval, // In: Interval for the arrayX
371  char *lineType)
372 {
373 
374  // Local Declarations
375  // ------------------
376  const char routine[] = "midiCreateReplotFileDouble2D2P";
377  int i, zero = 0;
378  FILE *dataFilePtr=NULL, *cmdFilePtr=NULL;
379  char *dataFilePath, *cmdFileName, *argument;
380 
381  // Algorithm
382  // ---------
383  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
384  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
385 
386  // Allocate memory
387  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
388  cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
389  argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
390 
391  // Create the plot file
392  sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
393  dataFilePtr = fopen (dataFilePath, "w");
394  for (i = begin; i < end; i += interval)
395  {
396  if (isnan (arrayX[i]) || isnan (arrayY[i])) fprintf (dataFilePtr, "%d %d \n", zero, zero);
397  else fprintf (dataFilePtr, "%f %f \n", arrayX[i], arrayY[i]);
398  }
399  fclose (dataFilePtr);
400 
401  // Display plot file
402  if (plotFile > 1)
403  {
404  sprintf (cmdFileName, "plotCmdFile.grb");
405  cmdFilePtr = fopen (cmdFileName, "w");
406  fprintf (cmdFilePtr, "set title \'%s\' \n", title);
407  fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
408  fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
409  fprintf (cmdFilePtr, "replot \'%s\' with %s\n", dataFilePath, lineType);
410  if (plotDuration == -1)
411  {
412  cpl_msg_info(cpl_func,"\n");
413  fprintf (cmdFilePtr, "pause %d \" ***** Hit Return to continue *****\" \n", plotDuration);
414  }
415  else
416  fprintf (cmdFilePtr, "pause %d \n", plotDuration);
417 
418  fclose (cmdFilePtr);
419 
420 
421  // Run the command file
422  sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
423  system (argument);
424 
425  // Remove temporary files
426  remove (cmdFileName);
427  }
428 
429  // Delete plot file if display only
430  if (deletePlot || plotFile == 3) remove (dataFilePath);
431 
432  // Release memory
433  free (dataFilePath);
434  free (cmdFileName);
435  free (argument);
436 
437  return;
438 }
439 /*****************************************************************************/
440 
441 
442 /******************************************************************************
443 * European Southern Observatory
444 * VLTI MIDI Data Reduction Software
445 *
446 * Module name: midiCreatePlotFileDouble2D2P
447 * Input/Output: See function arguments to avoid duplication
448 * Description: Creates a plot file for a 2 column table
449 *
450 * History:
451 * 14-Feb-05 (csabet)
452 ******************************************************************************/
453 void midiCreatePlotFileDouble2D2P (
454  const char *plotFileName,
455  const char *title,
456  const char *xLabel,
457  const char *yLabel,
458  int deletePlot,
459  double *arrayX, // In: Array X
460  double *arrayY,
461  int begin, // In: Start of the arrayX
462  int end, // In: End of arrayX
463  int interval, // In: Interval for the arrayX
464  const char *lineType)
465 {
466 
467  // Local Declarations
468  // ------------------
469  const char routine[] = "midiCreatePlotFileDouble2D2P";
470  int i, zero = 0;
471  FILE *dataFilePtr=NULL, *cmdFilePtr=NULL;
472  char *dataFilePath, *cmdFileName, *argument;
473 
474  // Algorithm
475  // ---------
476  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
477  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
478 
479  // Allocate memory
480  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
481  cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
482  argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
483 
484  // Create the plot file
485  sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
486  dataFilePtr = fopen (dataFilePath, "w");
487  for (i = begin; i < end; i += interval)
488  {
489  if (isnan (arrayX[i]) || isnan (arrayY[i])) fprintf (dataFilePtr, "%d %d \n", zero, zero);
490  else fprintf (dataFilePtr, "%f %f \n", arrayX[i], arrayY[i]);
491  }
492  fclose (dataFilePtr);
493 
494  // Display plot file
495  if (plotFile > 1)
496  {
497  sprintf (cmdFileName, "plotCmdFile.grb");
498  cmdFilePtr = fopen (cmdFileName, "w");
499  fprintf (cmdFilePtr, "set title \'%s\' \n", title);
500  fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
501  fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
502  fprintf (cmdFilePtr, "plot \'%s\' with %s\n", dataFilePath, lineType);
503  if (plotDuration == -1)
504  {
505  cpl_msg_info(cpl_func,"\n");
506  fprintf (cmdFilePtr, "pause %d \" ***** Hit Return to continue *****\" \n", plotDuration);
507  }
508  else
509  fprintf (cmdFilePtr, "pause %d \n", plotDuration);
510 
511  fclose (cmdFilePtr);
512 
513 
514  // Run the command file
515  sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
516  system (argument);
517 
518  // Remove temporary files
519  remove (cmdFileName);
520  }
521 
522  // Delete plot file if display only
523  if (deletePlot || plotFile == 3) remove (dataFilePath);
524 
525  // Release memory
526  free (dataFilePath);
527  free (cmdFileName);
528  free (argument);
529 
530  return;
531 }
532 /*****************************************************************************/
533 
534 
535 /******************************************************************************
536 * European Southern Observatory
537 * VLTI MIDI Data Reduction Software
538 *
539 * Module name: midiCreatePlotFile2D2P
540 * Input/Output: See function arguments to avoid duplication
541 * Description: Creates a plot file for a 2 column table
542 *
543 * History:
544 * 14-Feb-05 (csabet)
545 ******************************************************************************/
546 void midiCreatePlotFile2D2P (
547  const char *plotFileName,
548  const char *title,
549  const char *xLabel,
550  const char *yLabel,
551  int deletePlot,
552  float *arrayX, // In: Array X
553  float *arrayY,
554  int begin, // In: Start of the arrayX
555  int end, // In: End of arrayX
556  int interval) // In: Interval for the arrayX
557 {
558 
559  // Local Declarations
560  // ------------------
561  const char routine[] = "midiCreatePlotFile2D2P";
562  int i, zero = 0;
563  FILE *dataFilePtr=NULL, *cmdFilePtr=NULL;
564  char *dataFilePath, *cmdFileName, *argument;
565 
566  // Algorithm
567  // ---------
568  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
569  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
570 
571  // Allocate memory
572  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
573  cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
574  argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
575 
576  // Create the plot file
577  sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
578  dataFilePtr = fopen (dataFilePath, "w");
579  for (i = begin; i < end; i += interval)
580  {
581  if (isnan (arrayX[i]) || isnan (arrayY[i])) fprintf (dataFilePtr, "%d %d \n", zero, zero);
582  else fprintf (dataFilePtr, "%f %f \n", arrayX[i], arrayY[i]);
583  }
584  fclose (dataFilePtr);
585 
586  // Display plot file
587  if (plotFile > 1)
588  {
589  sprintf (cmdFileName, "plotCmdFile.grb");
590  cmdFilePtr = fopen (cmdFileName, "w");
591  fprintf (cmdFilePtr, "set title \'%s\' \n", title);
592  fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
593  fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
594  fprintf (cmdFilePtr, "plot \'%s\' with lines 1\n", dataFilePath);
595  if (plotDuration == -1)
596  {
597  cpl_msg_info(cpl_func,"\n");
598  fprintf (cmdFilePtr, "pause %d \" ***** Hit Return to continue *****\" \n", plotDuration);
599  }
600  else
601  fprintf (cmdFilePtr, "pause %d \n", plotDuration);
602 
603  fclose (cmdFilePtr);
604 
605 
606  // Run the command file
607  sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
608  system (argument);
609 
610  // Remove temporary files
611  remove (cmdFileName);
612  }
613 
614  // Delete plot file if display only
615  if (deletePlot || plotFile == 3) remove (dataFilePath);
616 
617  // Release memory
618  free (dataFilePath);
619  free (cmdFileName);
620  free (argument);
621 
622  return;
623 }
624 /*****************************************************************************/
625 
626 
627 /******************************************************************************
628 * European Southern Observatory
629 * VLTI MIDI Data Reduction Software
630 *
631 * Module name: midiCreatePlotFile2D
632 * Input/Output: See function arguments to avoid duplication
633 * Description: Creates a plot file
634 *
635 * History:
636 * 14-Feb-05 (csabet)
637 ******************************************************************************/
638 void midiCreatePlotFile2D (
639  const char *plotFileName,
640  const char *title,
641  const char *xLabel,
642  const char *yLabel,
643  int deletePlot,
644  float *array,
645  int begin,
646  int end,
647  int interval,
648  int override)
649 {
650 
651  // Local Declarations
652  // ------------------
653  const char routine[] = "midiCreatePlotFile2D";
654  int i, zero = 0, duration;
655  FILE *dataFilePtr=NULL, *cmdFilePtr=NULL;
656  char *dataFilePath, *cmdFileName, *argument;
657 
658  // Algorithm
659  // ---------
660  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
661  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
662 
663  // Allocate memory
664  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
665  cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
666  argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
667 
668  // Reset
669  if (override)
670  duration = override;
671  else
672  duration = plotDuration;
673 
674  // Create the plot file
675  sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
676  dataFilePtr = fopen (dataFilePath, "w");
677  for (i = begin; i < end; i += interval)
678  {
679  if (isnan (array[i])) fprintf (dataFilePtr, "%d \n", zero);
680  else fprintf (dataFilePtr, "%f \n", array[i]);
681  }
682  fclose (dataFilePtr);
683 
684  // Display plot file
685  if (plotFile > 1)
686  {
687  sprintf (cmdFileName, "plotCmdFile.grb");
688  cmdFilePtr = fopen (cmdFileName, "w");
689  fprintf (cmdFilePtr, "set title \'%s\' \n", title);
690  fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
691  fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
692  fprintf (cmdFilePtr, "plot \'%s\' with lines 1\n", dataFilePath);
693  if (duration == -1)
694  {
695  cpl_msg_info(cpl_func,"\n");
696  fprintf (cmdFilePtr, "pause %d \" ***** Hit Return to continue *****\" \n", duration);
697  }
698  else
699  fprintf (cmdFilePtr, "pause %d \n", duration);
700 
701  fclose (cmdFilePtr);
702 
703 
704  // Run the command file
705  sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
706  system (argument);
707 
708  // Remove temporary files
709  remove (cmdFileName);
710  }
711 
712  // Delete plot file if display only
713  if (deletePlot || plotFile == 3) remove (dataFilePath);
714 
715  // Release memory
716  free (dataFilePath);
717  free (cmdFileName);
718  free (argument);
719 
720  return;
721 }
722 /*****************************************************************************/
723 
724 
725 
726 /******************************************************************************
727 * European Southern Observatory
728 * VLTI MIDI Data Reduction Software
729 *
730 * Module name: getVersions
731 * Input/Output: See function arguments to avoid duplication
732 * Description: Displays versions of integrated software
733 *
734 * History:
735 * 14-Feb-05 (csabet)
736 ******************************************************************************/
737 void getVersions (void)
738 {
739 
740  // Local Declarations
741  // ------------------
742 
743  // Algorithm
744  // ---------
745  cpl_msg_info(cpl_func,"\nIntegrated Versions \n");
746  cpl_msg_info(cpl_func,"------------------- \n");
747  cpl_msg_info(cpl_func,"MIDI DRS Pipeline = %s \n", MIDI_PIPE_VERSION);
748  cpl_msg_info(cpl_func,"Iau Exchange = %s \n", IAUEXCHANGE_VERSION);
749  cpl_msg_info(cpl_func,"QC Dictionary = %s \n", MIDI_QC_DIC_VERSION);
750  cpl_msg_info(cpl_func,"\n");
751 
752  return;
753 }
754 /*****************************************************************************/
755 
756 
757 /******************************************************************************
758 * European Southern Observatory
759 * VLTI MIDI Data Reduction Software
760 *
761 * Module name: prepareWaterfallDisplay
762 * Input/Output: See function arguments to avoid duplication
763 * Description: This routine creates the waterfall display.
764 *
765 * History:
766 * 14-Aug-03 (csabet) Created. Derived from pballest July 2003
767 ******************************************************************************/
768 void prepareWaterfallDisplay (
769  MidiFiles *fileNames, // In: Pointer to the file structure
770  ImageFormat *imageSize, // In: Image format
771  CompressedData *compressed) // In: Compressed data
772 {
773 
774  // Local Declarations
775  // ------------------
776  const char routine[] = "prepareWaterfallDisplay";
777  qfits_header *pHeaderOut;
778  FILE *waterfallPtr;
779  qfitsdumper qdFringe;
780  char *sFramesPerScan, *sNumOfScans, *classification, *stringTemp,
781  *currentTime, *sNumOfChannels, *sNumOfFreqBins;
782  FILE *inFitsBatchPtr = NULL;
783  struct stat buf;
784  char *fileName, *title;
785  int f, fs, s, numOfScans, framesPerScan, numOfFrames, scanMax, frameStart,
786  numOfFreqBins, frameEnd;
787  double *cleanArray, dcLevel, accum, fluxMax;
788  time_t now;
789  struct tm *newTime;
790 
791  // Algorithm
792  // ---------
793  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
794  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
795 
796  cpl_msg_info(cpl_func,"\nCreating Waterfall Display Data for batch %d \n", batchNumber);
797  cpl_msg_info(cpl_func,"----------------------------------------- \n");
798  fprintf (midiReportPtr, "\nCreating Waterfall Display Data for batch %d \n", batchNumber);
799  fprintf (midiReportPtr, "----------------------------------------- \n");
800 
801  // Allocate memory
802  stringTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
803  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
804  sNumOfScans = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
805  sFramesPerScan = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
806  sNumOfFreqBins = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
807  sNumOfChannels = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
808  cleanArray = (double *) calloc (imageSize->numOfFrames, sizeof (double));
809  currentTime = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
810 
811  // Get current time/date
812  now = time(NULL);
813  newTime = gmtime (&now);
814  strftime (currentTime, MIN_STRING_LENGTH, "%a %d %b %Y at %H:%M:%S", newTime);
815 
816  // Create a clean iFringe
817  numOfFrames = 0;
818  for (f = 0; f < imageSize->numOfFrames; f++)
819  {
820  if (compressed->tarType[f] == 'T')
821  {
822  cleanArray[numOfFrames] = compressed->iFringe[f];
823  numOfFrames++;
824  }
825  }
826 
827  if (strcmp (imageSize->beamCombiner, "SCI_PHOT") == 0)
828  {
829  numOfScans = countTransitions ('T', imageSize->numOfFrames, compressed->tarType) + 1;
830  framesPerScan = numOfFrames / numOfScans;
831  }
832  else
833  {
834  numOfScans = imageSize->numOfScans;
835  framesPerScan = imageSize->framesPerScan;
836  }
837 
838  // Remove DC level
839  for (s = 0; s < numOfScans; s++)
840  {
841  accum = 0;
842  for (fs = 0; fs < framesPerScan; fs++)
843  {
844  f = fs + s * framesPerScan;
845  accum += cleanArray[f];
846  }
847  dcLevel = accum/framesPerScan;
848  for (fs = 0; fs < framesPerScan; fs++)
849  {
850  f = fs + s * framesPerScan;
851  cleanArray[f] -= dcLevel;
852  }
853  }
854 
855  // Find the scan at which the fringe is maximum
856  fluxMax = 0.0;
857  scanMax = 0;
858  for (f = 0; f < numOfFrames; f++)
859  {
860  if (fabs(cleanArray[f]) > fluxMax)
861  {
862  fluxMax = fabs(cleanArray[f]);
863  scanMax = f;
864  }
865  }
866  scanMax = scanMax / framesPerScan + 1;
867 
868  // Write all NAXIS values as character strings
869  numOfFreqBins = POST_FFT_SIZE/2;
870  sprintf (sNumOfScans, "%d", numOfScans);
871  sprintf (sFramesPerScan, "%d", framesPerScan);
872  sprintf (sNumOfFreqBins, "%d", numOfFreqBins);
873  sprintf (sNumOfChannels, "%d", imageSize->iXWidth);
874 
875  // Open the list of files
876  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
877  {
878  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
879  cpl_msg_info(cpl_func,"\nCannot Create Waterfall Display Data for batch %d \n", batchNumber);
880  fprintf (midiReportPtr, "\nCannot Create Waterfall Display Data for batch %d \n", batchNumber);
881  free (sNumOfScans);
882  free (sFramesPerScan);
883  free (classification);
884  free (stringTemp);
885  free (cleanArray);
886  free (sNumOfFreqBins);
887  free (sNumOfChannels);
888  return;
889  }
890 
891 
892  // Read the name of the first file in the list and get it's full path name
893  fgets (stringTemp, MAX_STRING_LENGTH, inFitsBatchPtr);
894  sprintf (classification, "%s", "");
895  sscanf (stringTemp, "%s%s", fileNames->inFitsName, classification);
896 
897  // Add primary Header
898  if (diagnostic)cpl_msg_info(cpl_func,"Extracting primary header from input FITS file %s \n", fileNames->inFitsName);
899  if (diagnostic) fprintf(midiReportPtr, "Extracting primary header from input FITS file %s \n", fileNames->inFitsName);
900  pHeaderOut = qfits_header_read (fileNames->inFitsName);
901  if (pHeaderOut == NULL)
902  {
903  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot extract primary header from input FITS file");
904  cpl_msg_info(cpl_func,"\nCannot Create Waterfall Display Data for batch %d \n", batchNumber);
905  fprintf (midiReportPtr, "\nCannot Create Waterfall Display Data for batch %d \n", batchNumber);
906  free (sNumOfScans);
907  free (sFramesPerScan);
908  free (classification);
909  free (stringTemp);
910  free (cleanArray);
911  free (sNumOfFreqBins);
912  free (sNumOfChannels);
913  return;
914  }
915 
916  // Updates header for the Waterfall output file
917  qfits_header_mod (pHeaderOut, "BITPIX","-64", "number of bits per pixel");
918  qfits_header_mod (pHeaderOut, "NAXIS", "2", "number of data axes");
919  qfits_header_add (pHeaderOut, "NAXIS1", sFramesPerScan, "", "");
920  qfits_header_add (pHeaderOut, "NAXIS2", sNumOfScans, "", "");
921  qfits_header_add (pHeaderOut, "FREQBIN", sNumOfFreqBins, "", "");
922  qfits_header_add (pHeaderOut, "NUMCHAN", sNumOfChannels, "", "");
923  qfits_header_mod (pHeaderOut, "INSTRUME", "MIDI", "MIDI Raw Data Display FITS created by DRS pipeline" );
924  qfits_header_add (pHeaderOut, "HIERARCH ESO PRO CATG", "WATERFALL", "Pipeline product category", NULL);
925  qfits_header_add (pHeaderOut, "HIERARCH ESO PRO ARCFILE", fileNames->archFileName, "Arcfile name of first raw file", "");
926  qfits_header_add (pHeaderOut, "HIERARCH ESO PRO PIPEDATE", currentTime, "Pipeline run date", "");
927  qfits_header_add (pHeaderOut, "HIERARCH ESO PRO VERSION", MIDI_PIPE_VERSION, "Pipeline version", "");
928  qfits_header_add (pHeaderOut, "PIPEFILE", fileNames->pipeFileName, "Pipeline product file name", "");
929 
930  // Create file and dump FITS Header for Waterfall output file. If the file exist delete it
931  if (stat (fileNames->outWaterfallName, &buf) == 0) remove (fileNames->outWaterfallName);
932  if ((waterfallPtr = fopen (fileNames->outWaterfallName, "w")) == NULL)
933  {
934  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create Waterfall FITS file");
935  free (sNumOfScans);
936  free (sFramesPerScan);
937  free (classification);
938  free (stringTemp);
939  qfits_header_destroy (pHeaderOut);
940  free (cleanArray);
941  free (sNumOfFreqBins);
942  free (sNumOfChannels);
943  return;
944  }
945 
946  if (diagnostic)cpl_msg_info(cpl_func,"Created Waterfall FITS file: %s \n", fileNames->outWaterfallName);
947  fprintf (midiReportPtr, "Created Waterfall FITS file: %s \n", fileNames->outWaterfallName);
948 
949  qfits_header_dump (pHeaderOut, waterfallPtr);
950  fclose (waterfallPtr);
951 
952  // Done writing header, close structure
953  qfits_header_destroy (pHeaderOut);
954 
955  // Dumps Fringe into the Waterfall file
956  qdFringe.filename = fileNames->outWaterfallName;
957  qdFringe.npix = framesPerScan * numOfScans;
958  qdFringe.ptype = PTYPE_DOUBLE;
959  qdFringe.dbuf = cleanArray;
960  qdFringe.out_ptype = BPP_IEEE_DOUBLE;
961 
962  qfits_pixdump (&qdFringe);
963  qfits_zeropad (fileNames->outWaterfallName);
964 
965  // Close files and release memory
966  fclose (inFitsBatchPtr);
967  free (sNumOfScans);
968  free (sFramesPerScan);
969  free (sNumOfFreqBins);
970  free (sNumOfChannels);
971  free (classification);
972  free (stringTemp);
973  free (currentTime);
974 
975  // Create plot file
976  if (plotFile)
977  {
978  // Allocate memory
979  fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
980  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
981 
982  // Plot a few fringes around the maximum
983  sprintf (fileName, "FringeAtScan%d", scanMax-1);
984  sprintf (title, "Fringe at scan %d", scanMax-1);
985 
986  if(scanMax<2){
987  frameStart = 0;
988  frameEnd = framesPerScan;
989  }
990  else {
991  frameStart = (scanMax - 2) * framesPerScan;
992  frameEnd = (scanMax - 1) * framesPerScan;
993  }
994  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux (dc removed)", 0, cleanArray, frameStart, frameEnd, 1);
995 
996  sprintf (fileName, "FringeStrongest");
997  sprintf (title, "Strongest fringe found at scan %d", scanMax);
998  frameStart = (scanMax - 1) * framesPerScan;
999  frameEnd = scanMax * framesPerScan;
1000  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux (dc removed)", 0, cleanArray, frameStart, frameEnd, 1);
1001 
1002  sprintf (fileName, "FringeAtScan%d", scanMax+1);
1003  sprintf (title, "Fringe at scan %d", scanMax+1);
1004  frameStart = scanMax * framesPerScan;
1005  frameEnd = (scanMax + 1) * framesPerScan;
1006  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux (dc removed)", 0, cleanArray, frameStart, frameEnd, 1);
1007 
1008  free (fileName);
1009  free (title);
1010  }
1011  free (cleanArray);
1012 
1013  return;
1014 }
1015 /*****************************************************************************/
1016 
1017 
1018 /******************************************************************************
1019 * European Southern Observatory
1020 * VLTI MIDI Data Reduction Software
1021 *
1022 * Module name: prepareWaterpowerDisplay
1023 * Input/Output: See function arguments to avoid duplication
1024 * Description: This routine creates the waterpower display
1025 *
1026 * History:
1027 * 21-Jul-03 (csabet) Created
1028 ******************************************************************************/
1029 void prepareWaterpowerDisplay (
1030  MidiFiles *fileNames, // In: Pointer to file structure including target file name
1031  ImageFormat *imageSize, // In: Pointer to image structure
1032  float *allSpectrum) // In: Compressed spectrum for all regions
1033 {
1034  /* Local Declarations
1035  ---------------------- */
1036  const char routine[] = "prepareWaterpowerDisplay";
1037  qfits_header *pHeaderOut;
1038  FILE *waterpowerPtr;
1039  qfitsdumper qdEachSpectrum;
1040  char *sFramesPerScan, *sNumOfScans, *classification, *stringTemp;
1041  FILE *inFitsBatchPtr = NULL;
1042  struct stat buf;
1043 
1044  /* Algorithm
1045  -----------*/
1046  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1047  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
1048 
1049  cpl_msg_info(cpl_func,"\nCreating Waterpower Display Data for batch %d \n", batchNumber);
1050  cpl_msg_info(cpl_func,"------------------------------------------ \n");
1051  fprintf (midiReportPtr, "\nCreating Waterpower Display Data for batch %d \n", batchNumber);
1052  fprintf (midiReportPtr, "------------------------------------------ \n");
1053 
1054  /* Allocate memory */
1055  stringTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1056  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1057  sNumOfScans = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1058  sFramesPerScan = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
1059 
1060  /* Write all NAXIS values as character strings */
1061  sprintf (sNumOfScans, "%d", imageSize->numOfScans); // imageSize->numOfScans);
1062  sprintf (sFramesPerScan, "%d", imageSize->fftsize/2);
1063 
1064  /* Open the list of files */
1065  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
1066  {
1067  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
1068  cpl_msg_info(cpl_func,"\nCannot Create Waterpower Display Data for batch %d \n", batchNumber);
1069  fprintf (midiReportPtr, "\nCannot Create Waterpower Display Data for batch %d \n", batchNumber);
1070  free (sNumOfScans);
1071  free (sFramesPerScan);
1072  free (classification);
1073  free (stringTemp);
1074  return;
1075  }
1076  /* Read the name of the first file in the list and get it's full path name */
1077  fgets (stringTemp, MAX_STRING_LENGTH, inFitsBatchPtr);
1078  sprintf (classification, "%s", "");
1079  sscanf (stringTemp, "%s%s", fileNames->inFitsName, classification);
1080 
1081  /* Add primary Header */
1082  if (diagnostic)cpl_msg_info(cpl_func,"Extracting primary header from input FITS file %s \n", fileNames->inFitsName);
1083  if (diagnostic) fprintf(midiReportPtr, "Extracting primary header from input FITS file %s \n", fileNames->inFitsName);
1084  pHeaderOut = qfits_header_read (fileNames->inFitsName);
1085  if (pHeaderOut == NULL)
1086  {
1087  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot extract header from input FITS file");
1088  cpl_msg_info(cpl_func,"\nCannot Create Waterpower Display Data for batch %d \n", batchNumber);
1089  fprintf (midiReportPtr, "\nCannot Create Waterpower Display Data for batch %d \n", batchNumber);
1090  free (sNumOfScans);
1091  free (sFramesPerScan);
1092  free (classification);
1093  free (stringTemp);
1094  return;
1095  }
1096 
1097  /* Updates header for the Waterpower output file */
1098  qfits_header_mod (pHeaderOut, "BITPIX","-64", "number of bits per pixel");
1099  qfits_header_mod (pHeaderOut, "NAXIS", "2", "number of data axes");
1100  qfits_header_add (pHeaderOut, "NAXIS1", sFramesPerScan, "", "");
1101  qfits_header_add (pHeaderOut, "NAXIS2", sNumOfScans, "", "");
1102  qfits_header_mod (pHeaderOut, "INSTRUME", "MIDI", "MIDI Raw Data Display FITS created by DRS pipeline" );
1103 
1104  // Create file and dump FITS Header for Waterpower output file. If the file exist delete it
1105  if (stat (fileNames->outWaterpowerName, &buf) == 0) remove (fileNames->outWaterpowerName);
1106  if ((waterpowerPtr = fopen (fileNames->outWaterpowerName, "w")) == NULL)
1107  {
1108  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create Waterpower FITS file");
1109  free (sNumOfScans);
1110  free (sFramesPerScan);
1111  free (classification);
1112  free (stringTemp);
1113  qfits_header_destroy (pHeaderOut);
1114  return;
1115  }
1116 
1117  if (diagnostic)cpl_msg_info(cpl_func,"Created Waterpower FITS file: %s \n", fileNames->outWaterpowerName);
1118  fprintf (midiReportPtr, "Created Waterpower FITS file: %s \n", fileNames->outWaterpowerName);
1119 
1120  qfits_header_dump (pHeaderOut, waterpowerPtr);
1121  fclose (waterpowerPtr);
1122 
1123  /* Done writing header, close structure */
1124  qfits_header_destroy (pHeaderOut);
1125 
1126  /* Dumps allSpectrum into the Waterpower file */
1127  qdEachSpectrum.filename = fileNames->outWaterpowerName;
1128  qdEachSpectrum.npix = imageSize->allSpectrumLength;
1129  qdEachSpectrum.ptype = PTYPE_FLOAT;
1130  qdEachSpectrum.fbuf = allSpectrum;
1131  qdEachSpectrum.out_ptype = BPP_IEEE_FLOAT;
1132 
1133  qfits_pixdump (&qdEachSpectrum);
1134  qfits_zeropad (fileNames->outWaterpowerName);
1135 
1136  /* Close files */
1137  fclose (inFitsBatchPtr);
1138 
1139  /* Release memory */
1140  free (sNumOfScans);
1141  free (sFramesPerScan);
1142  free (classification);
1143  free (stringTemp);
1144 
1145  return;
1146 }
1147 /*****************************************************************************/
1148 
1149 
1150 
1151 /******************************************************************************
1152 * European Southern Observatory
1153 * VLTI MIDI Data Reduction Software
1154 *
1155 * Module name: reportInterfChopping
1156 * Input/Output: See function arguments to avoid duplication
1157 * Description: Checks chopping cycles
1158 *
1159 * History:
1160 * 06-Dec-05 (csabet)
1161 ******************************************************************************/
1162 void reportInterfChopping (
1163  const char *dataKey, // In: Whether Interferometry or Photometry etc.
1164  ImageFormat *format, // In: Image format
1165  CompressedData *compressed) // In: Compressed data
1166 {
1167 
1168  // Local Declarations
1169  // ------------------
1170  const char routine[] = "reportInterfChopping";
1171  int f, s, u, n, fps;
1172  char *fileName, *title, *dataFilePath;
1173  FILE *dataFilePtr=NULL;
1174  double *array;
1175 
1176  // Algorithm
1177  // ---------
1178  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1179  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
1180 
1181  // Reset
1182  fps = format->framesPerScan;
1183 
1184  // Allocate memory
1185  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1186 
1187  // Create a QC log file for Interferometry
1188  sprintf (dataFilePath, "%s%s.Compressed%s.qc.dummy", outFileDir, outRootName, dataKey);
1189  dataFilePtr = fopen (dataFilePath, "w");
1190 
1191  if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
1192  (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
1193  {
1194  fprintf (dataFilePtr, "Frame TarType DATA1 DATA2 DATA1-DATA2 \n");
1195  fprintf (dataFilePtr, "================================================================= \n");
1196  }
1197  else
1198  {
1199  fprintf (dataFilePtr, "Frame TarType DATA2 DATA3 DATA2-DATA3 \n");
1200  fprintf (dataFilePtr, "================================================================= \n");
1201  }
1202  for (f = 0; f < format->numOfFrames; f++)
1203  {
1204  fprintf (dataFilePtr, "%5d %c %f %f %f\n", f, compressed->tarType[f],
1205  compressed->iFringe1[f], compressed->iFringe2[f], compressed->iFringe[f]);
1206  }
1207  fclose (dataFilePtr);
1208 
1209  // Create statistics and plot
1210  s = u = compressed->numOfTargetChops = 0;
1211  for (f = 0; f < format->numOfFrames; f++)
1212  {
1213  if (compressed->tarType[f] == 'S') s++;
1214  else if (compressed->tarType[f] == 'T') (compressed->numOfTargetChops)++;
1215  else u++;
1216  }
1217 
1218  cpl_msg_info(cpl_func,"\n%s Chopping Statistics QCLOG \n", dataKey);
1219  cpl_msg_info(cpl_func,"--------------------------------- QCLOG \n");
1220  cpl_msg_info(cpl_func,"Number of Target chops = %d QCLOG \n", compressed->numOfTargetChops);
1221  cpl_msg_info(cpl_func,"Number of Sky chops = %d QCLOG \n", s);
1222  cpl_msg_info(cpl_func,"Number of Undefined chops = %d QCLOG \n", u);
1223  fprintf (midiReportPtr, "\n%s Chopping Statistics QCLOG \n", dataKey);
1224  fprintf (midiReportPtr, "--------------------------------- QCLOG \n");
1225  fprintf (midiReportPtr, "Number of Target chops = %d QCLOG \n", compressed->numOfTargetChops);
1226  fprintf (midiReportPtr, "Number of Sky chops = %d QCLOG \n", s);
1227  fprintf (midiReportPtr, "Number of Undefined chops = %d QCLOG \n", u);
1228 
1229  if (plotFile && diagnostic > 1)
1230  {
1231  array = (double *) calloc (format->numOfFrames, sizeof (double));
1232  fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1233  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1234 
1235  if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
1236  (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
1237  {
1238  n = 0;
1239  for (f = 0; f < format->numOfFrames; f++)
1240  {
1241  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
1242  {
1243  array[n] = compressed->iFringe1[f];
1244  n++;
1245  }
1246  }
1247  sprintf (fileName, "%sCompressedDATA1", dataKey);
1248  sprintf (title, "Compressed %s DATA1", dataKey);
1249  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1250 
1251  n = 0;
1252  for (f = 0; f < format->numOfFrames; f++)
1253  {
1254  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe2[f]))))
1255  {
1256  array[n] = compressed->iFringe2[f];
1257  n++;
1258  }
1259  }
1260  sprintf (fileName, "%sCompressedDATA2", dataKey);
1261  sprintf (title, "Compressed %s DATA2", dataKey);
1262  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1263 
1264  n = 0;
1265  for (f = 0; f < format->numOfFrames; f++)
1266  {
1267  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe[f]))))
1268  {
1269  array[n] = compressed->iFringe[f];
1270  n++;
1271  }
1272  }
1273  sprintf (fileName, "%sCompressedDATA1_DATA2", dataKey);
1274  sprintf (title, "Compressed %s DATA1-DATA2", dataKey);
1275  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1276  }
1277  else
1278  {
1279  n = 0;
1280  for (f = 0; f < format->numOfFrames; f++)
1281  {
1282  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
1283  {
1284  array[n] = compressed->iFringe1[f];
1285  n++;
1286  }
1287  }
1288  sprintf (fileName, "%sCompressedDATA2", dataKey);
1289  sprintf (title, "Compressed %s DATA2", dataKey);
1290  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1291 
1292  n = 0;
1293  for (f = 0; f < format->numOfFrames; f++)
1294  {
1295  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe2[f]))))
1296  {
1297  array[n] = compressed->iFringe2[f];
1298  n++;
1299  }
1300  }
1301  sprintf (fileName, "%sCompressedDATA3", dataKey);
1302  sprintf (title, "Compressed %s DATA3", dataKey);
1303  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1304 
1305  n = 0;
1306  for (f = 0; f < format->numOfFrames; f++)
1307  {
1308  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe[f]))))
1309  {
1310  array[n] = compressed->iFringe[f];
1311  n++;
1312  }
1313  }
1314  sprintf (fileName, "%sCompressedDATA2_DATA3", dataKey);
1315  sprintf (title, "Compressed %s DATA2-DATA3", dataKey);
1316  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1317  }
1318  free (fileName);
1319  free (title);
1320  free (array);
1321  }
1322 
1323  // Release memory
1324  free (dataFilePath);
1325 
1326  return;
1327 }
1328 /*****************************************************************************/
1329 
1330 
1331 
1332 /******************************************************************************
1333 * European Southern Observatory
1334 * VLTI MIDI Data Reduction Software
1335 *
1336 * Module name: displayInterfChoppingDisp
1337 * Input/Output: See function arguments to avoid duplication
1338 * Description: Checks chopping cycles
1339 *
1340 * History:
1341 * 06-Dec-05 (csabet)
1342 ******************************************************************************/
1343 void displayInterfChoppingDisp (
1344  const char *dataKey, // In: Whether Interferometry or Photometry etc.
1345  ImageFormat *format, // In: Image format
1346  CompressedData *compressed) // In: Compressed data
1347 {
1348 
1349  // Local Declarations
1350  // ------------------
1351  const char routine[] = "displayInterfChoppingDisp";
1352  int f, n, X, R;
1353  char *fileName, *title;
1354  float *arrayF;
1355 
1356  // Algorithm
1357  // ---------
1358  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1359  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
1360 
1361  // Display for each channel
1362  if (plotFile && diagnostic > 4)
1363  {
1364  arrayF = (float *) calloc (format->numOfFrames, sizeof (float));
1365  fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1366  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1367 
1368  for (R = 0; R < format->numOfRegionsToProcess; R++)
1369  {
1370  for (X = 0; X < format->iXWidth; X++)
1371  {
1372  if (badChannelList[X])
1373  continue;
1374 
1375  n = 0;
1376  for (f = 0; f < format->numOfFrames; f++)
1377  {
1378  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iDispFringe[R][X][f]))))
1379  {
1380  arrayF[n] = compressed->iDispFringe[R][X][f];
1381  n++;
1382  }
1383  }
1384  if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
1385  (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
1386  {
1387  sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+1, X+1);
1388  sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+1, X+1);
1389  }
1390  else
1391  {
1392  sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+2, X+1);
1393  sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+2, X+1);
1394  }
1395  midiCreatePlotFile2D (fileName, title, "Frame", "Flux", 0, arrayF, 0, n, 1, 0);
1396  }
1397  }
1398  free (fileName);
1399  free (title);
1400  free (arrayF);
1401  }
1402 
1403  return;
1404 }
1405 /*****************************************************************************/
1406 
1407 
1408 /******************************************************************************
1409 * European Southern Observatory
1410 * VLTI MIDI Data Reduction Software
1411 *
1412 * Module name: reportPhotomChopping
1413 * Input/Output: See function arguments to avoid duplication
1414 * Description: Determines chopping coherency
1415 *
1416 * History:
1417 * 06-Dec-05 (csabet)
1418 ******************************************************************************/
1419 void reportPhotomChopping (
1420  const char *dataKey, // In: Whether Interferometry or Photometry etc.
1421  ImageFormat *format, // In: Image format
1422  CompressedData *compressed) // In: Compressed data
1423 {
1424 
1425  // Local Declarations
1426  // ------------------
1427  const char routine[] = "reportPhotomChopping";
1428  int f, s, t, u, n, fps;
1429  char *fileName, *title, *dataFilePath;
1430  FILE *dataFilePtr=NULL;
1431  double *array;
1432 
1433  // Algorithm
1434  // ---------
1435  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1436  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
1437 
1438  // Reset
1439  fps = format->framesPerScan;
1440 
1441  // Allocate memory
1442  dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1443 
1444  // Create a QC log file for Interferometry
1445  sprintf (dataFilePath, "%s%s.Compressed%s.qc.dummy", outFileDir, outRootName, dataKey);
1446  dataFilePtr = fopen (dataFilePath, "w");
1447 
1448  if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
1449  (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
1450  {
1451  fprintf (dataFilePtr, "Frame TarType DATA1 DATA2 \n");
1452  fprintf (dataFilePtr, "======================================== \n");
1453  for (f = 0; f < format->numOfFrames; f++)
1454  {
1455  fprintf (dataFilePtr, "%5d %c %f %f \n", f, compressed->tarType[f],
1456  compressed->iFringe1[f], compressed->iFringe2[f]);
1457  }
1458  }
1459  else
1460  {
1461  if (strcmp (format->shutterId, "AOPEN") == 0)
1462  {
1463  fprintf (dataFilePtr, "Frame TarType DATA1 \n");
1464  fprintf (dataFilePtr, "===================== \n");
1465  for (f = 0; f < format->numOfFrames; f++)
1466  {
1467  fprintf (dataFilePtr, "%5d %c %f \n", f, compressed->tarType[f],
1468  compressed->iFringe1[f]);
1469  }
1470  }
1471  else if (strcmp (format->shutterId, "BOPEN") == 0)
1472  {
1473  fprintf (dataFilePtr, "Frame TarType DATA4 \n");
1474  fprintf (dataFilePtr, "===================== \n");
1475  for (f = 0; f < format->numOfFrames; f++)
1476  {
1477  fprintf (dataFilePtr, "%5d %c %f \n", f, compressed->tarType[f],
1478  compressed->iFringe1[f]);
1479  }
1480  }
1481  else if (strcmp (format->shutterId, "ABOPEN") == 0)
1482  {
1483  fprintf (dataFilePtr, "Frame TarType DATA1 or DATA4 \n");
1484  fprintf (dataFilePtr, "============================== \n");
1485  for (f = 0; f < format->numOfFrames; f++)
1486  {
1487  fprintf (dataFilePtr, "%5d %c %f \n", f, compressed->tarType[f],
1488  compressed->iFringe1[f]);
1489  }
1490  }
1491  }
1492  fclose (dataFilePtr);
1493 
1494  // Create statistics and plot
1495  s = t = u = 0;
1496  for (f = 0; f < format->numOfFrames; f++)
1497  {
1498  if (compressed->tarType[f] == 'S') s++;
1499  else if (compressed->tarType[f] == 'T') t++;
1500  else u++;
1501  }
1502 
1503  cpl_msg_info(cpl_func,"\n%s Chopping Statistics QCLOG \n", dataKey);
1504  cpl_msg_info(cpl_func,"--------------------------------- QCLOG \n");
1505  cpl_msg_info(cpl_func,"Number of Target chops = %d QCLOG \n", t);
1506  cpl_msg_info(cpl_func,"Number of Sky chops = %d QCLOG \n", s);
1507  cpl_msg_info(cpl_func,"Number of Undefined chops = %d QCLOG \n", u);
1508  fprintf (midiReportPtr, "\n%s Chopping Statistics QCLOG \n", dataKey);
1509  fprintf (midiReportPtr, "--------------------------------- QCLOG \n");
1510  fprintf (midiReportPtr, "Number of Target chops = %d QCLOG \n", t);
1511  fprintf (midiReportPtr, "Number of Sky chops = %d QCLOG \n", s);
1512  fprintf (midiReportPtr, "Number of Undefined chops = %d QCLOG \n", u);
1513 
1514  if (plotFile && diagnostic > 1)
1515  {
1516  array = (double *) calloc (format->numOfFrames, sizeof (double));
1517  fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1518  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1519 
1520  if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
1521  (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
1522  {
1523  n = 0;
1524  for (f = 0; f < format->numOfFrames; f++)
1525  {
1526  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
1527  {
1528  array[n] = compressed->iFringe1[f];
1529  n++;
1530  }
1531  }
1532  sprintf (fileName, "%sCompressedDATA1", dataKey);
1533  sprintf (title, "Compressed %s DATA1", dataKey);
1534  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1535 
1536  n = 0;
1537  for (f = 0; f < format->numOfFrames; f++)
1538  {
1539  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe2[f]))))
1540  {
1541  array[n] = compressed->iFringe2[f];
1542  n++;
1543  }
1544  }
1545  sprintf (fileName, "%sCompressedDATA2", dataKey);
1546  sprintf (title, "Compressed %s DATA2", dataKey);
1547  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1548  }
1549  else
1550  {
1551  if (strcmp (format->shutterId, "AOPEN") == 0)
1552  {
1553  n = 0;
1554  for (f = 0; f < format->numOfFrames; f++)
1555  {
1556  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
1557  {
1558  array[n] = compressed->iFringe1[f];
1559  n++;
1560  }
1561  }
1562  sprintf (fileName, "%sCompressedDATA1", dataKey);
1563  sprintf (title, "Compressed %s DATA1", dataKey);
1564  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1565  }
1566  else if (strcmp (format->shutterId, "BOPEN") == 0)
1567  {
1568  n = 0;
1569  for (f = 0; f < format->numOfFrames; f++)
1570  {
1571  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
1572  {
1573  array[n] = compressed->iFringe1[f];
1574  n++;
1575  }
1576  }
1577  sprintf (fileName, "%sCompressedDATA4", dataKey);
1578  sprintf (title, "Compressed %s DATA4", dataKey);
1579  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1580  }
1581  else
1582  {
1583  if (strcmp (dataKey, "PHOTOMA") == 0)
1584  {
1585  n = 0;
1586  for (f = 0; f < format->numOfFrames; f++)
1587  {
1588  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
1589  {
1590  array[n] = compressed->iFringe1[f];
1591  n++;
1592  }
1593  }
1594  sprintf (fileName, "%sCompressedDATA1", dataKey);
1595  sprintf (title, "Compressed %s DATA1", dataKey);
1596  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1597  }
1598  else
1599  {
1600  n = 0;
1601  for (f = 0; f < format->numOfFrames; f++)
1602  {
1603  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
1604  {
1605  array[n] = compressed->iFringe1[f];
1606  n++;
1607  }
1608  }
1609  sprintf (fileName, "%sCompressedDATA4", dataKey);
1610  sprintf (title, "Compressed %s DATA4", dataKey);
1611  midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
1612  }
1613  }
1614  }
1615  free (fileName);
1616  free (title);
1617  free (array);
1618  }
1619 
1620  // Release memory
1621  free (dataFilePath);
1622 
1623  return;
1624 }
1625 /*****************************************************************************/
1626 
1627 
1628 /******************************************************************************
1629 * European Southern Observatory
1630 * VLTI MIDI Data Reduction Software
1631 *
1632 * Module name: displayPhotomChoppingDisp
1633 * Input/Output: See function arguments to avoid duplication
1634 * Description: Determines chopping coherency
1635 *
1636 * History:
1637 * 06-Dec-05 (csabet)
1638 ******************************************************************************/
1639 void displayPhotomChoppingDisp (
1640  const char *dataKey, // In: Whether Interferometry or Photometry etc.
1641  ImageFormat *format, // In: Image format
1642  CompressedData *compressed) // In: Compressed data
1643 {
1644 
1645  // Local Declarations
1646  // ------------------
1647  const char routine[] = "displayPhotomChoppingDisp";
1648  int f, n, X, R;
1649  char *fileName, *title;
1650  float *arrayF;
1651 
1652  // Algorithm
1653  // ---------
1654  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1655  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
1656 
1657 
1658  // Display for each channel
1659  if (plotFile && diagnostic > 4)
1660  {
1661  arrayF = (float *) calloc (format->numOfFrames, sizeof (float));
1662  fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1663  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
1664 
1665  for (R = 0; R < format->numOfRegionsToProcess; R++)
1666  {
1667  for (X = 0; X < format->iXWidth; X++)
1668  {
1669  n = 0;
1670  for (f = 0; f < format->numOfFrames; f++)
1671  {
1672  if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iDispFringe[R][X][f]))))
1673  {
1674  arrayF[n] = compressed->iDispFringe[R][X][f];
1675  n++;
1676  }
1677  }
1678  if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
1679  (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
1680  {
1681  sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+1, X+1);
1682  sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+1, X+1);
1683  }
1684  else
1685  {
1686  if (strcmp (dataKey, "PHOTOMA") == 0)
1687  {
1688  sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+1, X+1);
1689  sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+1, X+1);
1690  }
1691  else
1692  {
1693  sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+4, X+1);
1694  sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+4, X+1);
1695  }
1696  }
1697  midiCreatePlotFile2D (fileName, title, "Frame", "Flux", 0, arrayF, 0, n, 1, 0);
1698  }
1699  }
1700  free (fileName);
1701  free (title);
1702  free (arrayF);
1703  }
1704 
1705  return;
1706 }
1707 /*****************************************************************************/
1708 
1709 
1710 /******************************************************************************
1711 * European Southern Observatory
1712 * VLTI MIDI Data Reduction Software
1713 *
1714 * Module name: countTransitions
1715 * Input/Output: See function arguments to avoid duplication
1716 * Description: Checks chopping transitions
1717 *
1718 * History:
1719 * 08-Feb-06 (csabet) Created
1720 ******************************************************************************/
1721 int countTransitions ( // Ou: Chopping transitions
1722  char key, // In: Given TarTyp
1723  int length, // In: Length of array
1724  char *tarType) // In: Array of tarType
1725 
1726 {
1727  // Local Declarations
1728  // ------------------
1729  const char routine[] = "countTransitions";
1730  int i, transitions, sighting;
1731  char lastTarTyp;
1732 
1733  // Algorithm
1734  // ---------
1735  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1736  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
1737 
1738  // Initialise
1739  transitions = 0;
1740  sighting = 0;
1741  lastTarTyp = tarType[0];
1742 
1743  // Count transitions
1744  if (lastTarTyp == key) sighting++;
1745  for (i = 1; i < length; i++)
1746  {
1747  if (tarType[i] == key)
1748  {
1749  if (sighting && tarType[i] != lastTarTyp)
1750  transitions++;
1751 
1752  sighting++;
1753  }
1754 
1755  lastTarTyp = tarType[i];
1756  }
1757  if (!sighting) transitions = - 1;
1758 
1759  return (transitions);
1760 }
1761 /*****************************************************************************/
1762 
1763 
1764 /******************************************************************************
1765 * European Southern Observatory
1766 * VLTI MIDI Data Reduction Software
1767 *
1768 * Module name: midiReportResultsFringe
1769 * Input/Output: See function arguments to avoid duplication
1770 * Description: Reports all the results
1771 *
1772 * History:
1773 * 23-Feb-05 (csabet) Created
1774 ******************************************************************************/
1775 void midiReportResultsFringe (
1776  float *freqCal, // IO: Calibrated frequency in THz
1777  ImageFormat *format, // In: Image size of interferometry data
1778  DispersedResult *dispResult) // In: Result data structure
1779 {
1780 
1781  // Local Declarations
1782  // ------------------
1783  const char routine[] = "midiReportResultsFringe";
1784  int X;
1785 
1786  // Algorithm
1787  // ---------
1788  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1789  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
1790 
1791 
1792  cpl_msg_info(cpl_func,"\nReporting the results for batch %d \n", batchNumber);
1793  cpl_msg_info(cpl_func,"------------------------------- \n");
1794  fprintf (midiReportPtr, "\nReporting the results for batch %d \n", batchNumber);
1795  fprintf (midiReportPtr, "------------------------------- \n");
1796 
1797  // Recalculate number of channels rejected
1798  format->numOfChannelsProcessed = 0;
1799  for (X = 0; X < format->iXWidth; X++)
1800  {
1801  if (!(badChannelList[X]))
1802  (format->numOfChannelsProcessed)++;
1803  }
1804  format->numOfChannelsRejected = format->iXWidth - format->numOfChannelsProcessed;
1805 
1806  cpl_msg_info(cpl_func,"Observation Category = %s \n", format->obsCatg);
1807  cpl_msg_info(cpl_func,"\nResult Abbreviation \n");
1808  cpl_msg_info(cpl_func,"------------------- \n");
1809  cpl_msg_info(cpl_func,"X = Channel Number \n");
1810  cpl_msg_info(cpl_func,"F = Channel Frequency in THz \n");
1811  cpl_msg_info(cpl_func,"W = Channel Wavelength in microns \n");
1812  cpl_msg_info(cpl_func,"RVis = Raw Visibility \n");
1813  cpl_msg_info(cpl_func,"RVisEr = Raw Visibility Error (Standard deviation) \n");
1814  cpl_msg_info(cpl_func,"NVis = Normalised Visibility \n");
1815  cpl_msg_info(cpl_func,"NVisEr = Normalised Visibility Error (Standard deviation) \n");
1816  cpl_msg_info(cpl_func,"PhNe = \'Net\' Photometry \n");
1817  cpl_msg_info(cpl_func,"PhNeEr = \'Net\' Photometry Error (Standard deviation) \n");
1818  cpl_msg_info(cpl_func,"TF = Transfer Function \n");
1819  cpl_msg_info(cpl_func,"TFEr = Transfer Function Error (Standard deviation) \n");
1820  cpl_msg_info(cpl_func,"CVis = Calibrated Visibility \n");
1821  cpl_msg_info(cpl_func,"CVisEr = Calibrated Visibility Error (Standard deviation) \n");
1822 
1823  fprintf (midiReportPtr, "Observation Category = %s QCLOG \n", format->obsCatg);
1824  fprintf (midiReportPtr, "\nResult Abbreviation QCLOG \n");
1825  fprintf (midiReportPtr, "------------------- QCLOG \n");
1826  fprintf (midiReportPtr, "X = Channel Number QCLOG \n");
1827  fprintf (midiReportPtr, "F = Channel Frequency in THz QCLOG \n");
1828  fprintf (midiReportPtr, "W = Channel Wavelength in microns QCLOG \n");
1829  fprintf (midiReportPtr, "RVis = Raw Visibility QCLOG \n");
1830  fprintf (midiReportPtr, "RVisEr = Raw Visibility Error (Standard deviation) QCLOG \n");
1831  fprintf (midiReportPtr, "NVis = Normalised Visibility QCLOG \n");
1832  fprintf (midiReportPtr, "NVisEr = Normalised Visibility Error (Standard deviation) QCLOG \n");
1833  fprintf (midiReportPtr, "PhNe = \'Net\' Photometry QCLOG \n");
1834  fprintf (midiReportPtr, "PhNeEr = \'Net\' Photometry Error (Standard deviation) QCLOG \n");
1835  fprintf (midiReportPtr, "TF = Transfer Function QCLOG \n");
1836  fprintf (midiReportPtr, "TFEr = Transfer Function Error (Standard deviation) QCLOG \n");
1837  fprintf (midiReportPtr, "CVis = Calibrated Visibility QCLOG \n");
1838  fprintf (midiReportPtr, "CVisEr = Calibrated Visibility Error (Standard deviation) QCLOG \n");
1839 
1840  cpl_msg_info(cpl_func,"\nX W F RVis RVisEr NVis NVisEr ");
1841  cpl_msg_info(cpl_func,"PhNe PhNeEr TF TFEr CVis CVisEr \n");
1842  fprintf (midiReportPtr, "\nX W F RVis RVisEr NVis NVisEr ");
1843  fprintf (midiReportPtr, "PhNe PhNeEr TF TFEr CVis CVisEr QCLOG \n");
1844 
1845  for (X = 0; X < format->iXWidth; X++)
1846  {
1847  if (badChannelList[X])
1848  {
1849  cpl_msg_info(cpl_func,"%3d %5.2f %5.2f <-- %s --> \n",
1850  X, freqCal[X], SPEED_OF_LIGHT/freqCal[X], UNAV);
1851  fprintf (midiReportPtr, "%3d %5.2f %5.2f <-- %s --> QCLOG \n",
1852  X, freqCal[X], SPEED_OF_LIGHT/freqCal[X], UNAV);
1853  continue;
1854  }
1855 
1856  cpl_msg_info(cpl_func,"%3d %5.2f %5.2f %11.5f %9.4f %6.4f %8.4f %9.1f %7.2f %6.4f %6.4f %5.3f %5.3f \n",
1857  X, freqCal[X], SPEED_OF_LIGHT/freqCal[X],
1858  dispResult->rawVis2[X], dispResult->rawVis2Err[X],
1859  dispResult->normVis2[X], dispResult->normVis2Err[X],
1860  dispResult->photomNet2[X], dispResult->photomNet2Err[X],
1861  dispResult->trf[X], dispResult->trfErr[X],
1862  dispResult->calibVis2[X], dispResult->calibVis2Err[X]);
1863 
1864  fprintf (midiReportPtr, "%3d %5.2f %5.2f %11.4f %9.4f %6.4f %8.4f %9.1f %7.2f %6.4f %6.4f %5.3f %5.3f QCLOG\n",
1865  X, freqCal[X], SPEED_OF_LIGHT/freqCal[X],
1866  dispResult->rawVis2[X], dispResult->rawVis2Err[X],
1867  dispResult->normVis2[X], dispResult->normVis2Err[X],
1868  dispResult->photomNet2[X], dispResult->photomNet2Err[X],
1869  dispResult->trf[X], dispResult->trfErr[X],
1870  dispResult->calibVis2[X], dispResult->calibVis2Err[X]);
1871  }
1872 
1873  return;
1874 }
1875 /*****************************************************************************/
1876 
1877 /******************************************************************************
1878 * European Southern Observatory
1879 * VLTI MIDI Data Reduction Software
1880 *
1881 * Module name: reportRejectList
1882 * Input/Output: See function arguments to avoid duplication
1883 * Description: Final result of the rejection list for dispersed processing
1884 *
1885 * History:
1886 * 14-Mar-06 (csabet) Created
1887 ******************************************************************************/
1888 void reportRejectList (
1889  ImageFormat *format, // In: Points to the image format
1890  CompressedData *compressed) // In: Compressed data
1891 {
1892  // Local Declarations
1893  //--------------------
1894  const char routine[] = "reportRejectList";
1895  int f, x, numOfFramesProcessed, numOfFramesRejected, frameFailureId;
1896 
1897  // Algorithm
1898  // ---------
1899  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
1900  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
1901 
1902  cpl_msg_info(cpl_func,"\nFinalising Scan, Frame and Channel rejection \n");
1903  cpl_msg_info(cpl_func,"-------------------------------------------- \n");
1904  fprintf (midiReportPtr, "\nFinalising Scan, Frame and Channel rejection \n");
1905  fprintf (midiReportPtr, "-------------------------------------------- \n");
1906 
1907  if (diagnostic)cpl_msg_info(cpl_func,"\nChannel Number of Frames Number of Frames Frame Failure ID Channel Failure ID \n");
1908  if (diagnostic)cpl_msg_info(cpl_func," Processed Rejected \n");
1909  if (diagnostic)cpl_msg_info(cpl_func,"------------------------------------------------------------------------------------- \n");
1910  fprintf (midiReportPtr, "\nChannel Number of Frames Number of Frames Frame Failure ID Channel Failure ID \n");
1911  fprintf (midiReportPtr, " Processed Rejected \n");
1912  fprintf (midiReportPtr, "------------------------------------------------------------------------------------- \n");
1913 
1914  format->numOfChannelsRejected = 0;
1915  for (x = 0; x < format->iXWidth; x++)
1916  {
1917  frameFailureId = 0;
1918  numOfFramesProcessed = 0;
1919 
1920  // If channel was masked no frames were processed
1921  for (f = 0; f < format->numOfFrames; f++)
1922  {
1923  if (!(compressed->rejectList[x][f]))
1924  numOfFramesProcessed++;
1925 
1926  frameFailureId |= compressed->rejectList[x][f];
1927  }
1928 
1929  // Count rejected channels
1930  if (!numOfFramesProcessed || (badChannelList[x]))
1931  (format->numOfChannelsRejected)++;
1932 
1933  // Count rejected frames
1934  numOfFramesRejected = format->numOfFrames - numOfFramesProcessed;
1935 
1936  if (badChannelList[x])
1937  {
1938  if (diagnostic)cpl_msg_info(cpl_func,
1939  "%3d %4d %4d %4d %4d REJECTED\n",
1940  x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
1941  fprintf (midiReportPtr,
1942  "%3d %4d %4d %4d %4d REJECTED QCLOG \n",
1943  x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
1944  }
1945  else
1946  {
1947  if (diagnostic)cpl_msg_info(cpl_func,
1948  "%3d %4d %4d %4d %4d \n",
1949  x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
1950  fprintf (midiReportPtr,
1951  "%3d %4d %4d %4d %4d QCLOG \n",
1952  x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
1953  }
1954  }
1955 
1956  // Count number of channels to process
1957  format->numOfChannelsProcessed = format->iXWidth - format->numOfChannelsRejected;
1958 
1959  cpl_msg_info(cpl_func,"Number of channels processed = %3d \n", format->numOfChannelsProcessed);
1960  cpl_msg_info(cpl_func,"Number of channels rejected = %3d \n", format->numOfChannelsRejected);
1961  fprintf (midiReportPtr, "Number of channels processed = %3d QCLOG \n", format->numOfChannelsProcessed);
1962  fprintf (midiReportPtr, "Number of channels rejected = %3d QCLOG \n", format->numOfChannelsRejected);
1963 
1964  if (diagnostic)
1965  {
1966  cpl_msg_info(cpl_func,"Failure ID \n");
1967  cpl_msg_info(cpl_func,"---------- \n");
1968  cpl_msg_info(cpl_func," 1 = Bit 1, indicates a TIME error \n");
1969  cpl_msg_info(cpl_func," 2 = Bit 2, indicates an LOCALOPD error \n");
1970  cpl_msg_info(cpl_func," 4 = Bit 3, indicates an OPD error \n");
1971  cpl_msg_info(cpl_func," 8 = Bit 4, indicates a Bad DATA \n");
1972  cpl_msg_info(cpl_func," 16 = Bit 5, indicates a chopping problem (TARTYPE2) \n");
1973  cpl_msg_info(cpl_func," 32 = Bit 6, indicates a Delay Line Jump \n");
1974  cpl_msg_info(cpl_func," 64 = Bit 7, indicates an Unwanted Region \n");
1975  cpl_msg_info(cpl_func," 128 = Bit 8, indicates a Weak Signal/Noise \n");
1976  cpl_msg_info(cpl_func," 256 = Bit 9, indicates a SKY or Undefined \n");
1977  cpl_msg_info(cpl_func," 512 = Bit 10, indicates a TARTYPE Cross error. e.g. region 0 different to region 1 \n");
1978  cpl_msg_info(cpl_func,"1024 = Bit 11, indicates a Masked Channel \n");
1979  cpl_msg_info(cpl_func,"\nHence a number such as 168 indicates bits 4, 6 and 8 were set \n\n");
1980  }
1981 
1982  fprintf (midiReportPtr, "Failure ID QCLOG \n");
1983  fprintf (midiReportPtr, "---------- QCLOG \n");
1984  fprintf (midiReportPtr, " 1 = Bit 1, indicates a TIME error QCLOG \n");
1985  fprintf (midiReportPtr, " 2 = Bit 2, indicates an LOCALOPD error QCLOG \n");
1986  fprintf (midiReportPtr, " 4 = Bit 3, indicates an OPD error QCLOG \n");
1987  fprintf (midiReportPtr, " 8 = Bit 4, indicates a Bad DATA QCLOG \n");
1988  fprintf (midiReportPtr, " 16 = Bit 5, indicates a chopping problem (TARTYPE2) QCLOG \n");
1989  fprintf (midiReportPtr, " 32 = Bit 6, indicates a Delay Line Jump QCLOG \n");
1990  fprintf (midiReportPtr, " 64 = Bit 7, indicates an Unwanted Region QCLOG \n");
1991  fprintf (midiReportPtr, " 128 = Bit 8, indicates a Weak Signal/Noise QCLOG \n");
1992  fprintf (midiReportPtr, " 256 = Bit 9, indicates a SKY or Undefined QCLOG \n");
1993  fprintf (midiReportPtr, " 512 = Bit 10, indicates a TARTYPE Cross error. e.g. region 0 different to region 1 QCLOG \n");
1994  fprintf (midiReportPtr, "1024 = Bit 11, indicates a Masked Channel QCLOG \n");
1995  fprintf (midiReportPtr, "\nHence a number such as 168 indicates bits 4, 6 and 8 were set QCLOG \n\n");
1996 
1997  return;
1998 }
1999 /*****************************************************************************/