MIDI Pipeline Reference Manual  2.8.3
visibility.c
1 /******************************************************************************
2 *******************************************************************************
3 * European Southern Observatory
4 * VLTI MIDI Data Reduction Software
5 *
6 * Module name: visibility.c
7 * Description: Contains routines for all visibility computation routines
8 *
9 * History:
10 * 21-Jul-03 (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 "visibility.h"
29 #include "errorHandling.h"
30 #include "diagnostics.h"
31 #include "midi_dfs.h"
32 
33 /*============================ C O D E A R E A ===========================*/
34 
35 
36 
37 
38 /******************************************************************************
39 * European Southern Observatory
40 * VLTI MIDI Data Reduction Software
41 *
42 * Module name: computeCalibVis
43 * Input/Output: See function arguments to avoid duplication
44 * Description: This routine computes the final visibility on SCIENCE targets. It
45 * requires the transfer function as well as the uncalibrated
46 * visibilities.
47 *
48 * History:
49 * 08-Feb-05 (csabet) Created
50 ******************************************************************************/
51 void computeCalibVis (
52  MidiFiles *fileNames, // In: Pointer to MIDI file structure
53  ImageFormat *format, // In: Image structure
54  DispersedResult *dispResult, // In: Dispersed result structure
55  int *error, // Ou: Status
56  cpl_parameterlist *parlist,
57  cpl_frameset *frameset)
58 {
59 
60  // Local Declarations
61  // ------------------
62  const char routine[] = "computeCalibVis";
63  int X;
64 /*
65  FILE *trfPtr=NULL;
66  int numOfRecords;
67  char *givenGrismId;
68  char * tag=NULL;
69 */
70  char * softag=NULL;
71  cpl_frame * cur_frame=NULL;
72  cpl_table * table=NULL;
73  cpl_errorstate prestate = cpl_errorstate_get();
74  int ext_trf=0;
75  int dimentrf=0;
76  cpl_frame * local_trf_frame=NULL;
77  cpl_propertylist * dummy_propertylist = NULL;
78  cpl_propertylist * qclist=NULL;
79  char * dataname=NULL;
80  // Algorithm
81  // ---------
82  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
83  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
84 
85  cpl_msg_info(cpl_func,"\nComputing Calibrated Visibility for batch %d \n", batchNumber);
86  cpl_msg_info(cpl_func,"----------------------------------------- \n");
87  fprintf (midiReportPtr, "\nComputing Calibrated Visibility for batch %d \n", batchNumber);
88  fprintf (midiReportPtr, "----------------------------------------- \n");
89 
90  // Reset parameters
91  *error = 0;
92  dispResult->trfExists = 0;
93  dispResult->calibVisExists = 0;
94 
95 /* -------------------------------------------------------------------------- */
96  prestate = cpl_errorstate_get();
97 
98 /* Grism or Prism? */
99  if (strcmp(format->grismId,"GRISM")==0){
100  softag = cpl_sprintf("%s", MIDI_TRF_GRISM);
101  }
102  else if (strcmp(format->grismId,"PRISM")==0){
103  softag = cpl_sprintf("%s", MIDI_TRF_PRISM);
104  }
105  else {
106  cpl_msg_warning(cpl_func, "No GRISM or PRISM found");
107  cpl_msg_warning(cpl_func, "No transfer function applied");
108  cpl_errorstate_set(prestate);
109  *error = 1;
110  return;
111  }
112 
113  cur_frame = cpl_frameset_find( frameset, softag );
114 
115  /*
116  In case no transfer function file was sent (i.e. during online pipeline run) then
117  check the tmp dir
118  */
119  if( !cur_frame )
120  {
121  /* PIPELINE will not send the trf. Try to load it from tmp */
122  dummy_propertylist=cpl_propertylist_load("/tmp/MIDI_trf.fits", 0);
123  if (dummy_propertylist != NULL)
124  {
125  local_trf_frame=cpl_frame_new();
126  cpl_frame_set_filename (local_trf_frame,"/tmp/MIDI_trf.fits");
127  cpl_frame_set_group (local_trf_frame, CPL_FRAME_GROUP_CALIB);
128  cpl_frame_set_level (local_trf_frame, CPL_FRAME_LEVEL_FINAL);
129  cpl_frame_set_tag (local_trf_frame, cpl_propertylist_get_string(dummy_propertylist, "ESO PRO CATG"));
130  cpl_frame_set_type (local_trf_frame, CPL_FRAME_TYPE_TABLE);
131  cpl_frameset_insert(frameset, local_trf_frame);
132  cpl_propertylist_delete(dummy_propertylist);
133  }
134  }
135 
136  cur_frame = cpl_frameset_find( frameset, softag );
137 
138  if (cur_frame)
139  {
140  cpl_msg_info(cpl_func, "Transfer function found in the SOF: %s\n",cpl_frame_get_filename(cur_frame));
141  }
142 
143 
144  if (!cur_frame) {
145  cpl_msg_warning(cpl_func, "No siutable transfer function found!");
146  cpl_msg_warning(cpl_func, "No transfer function applied to the data");
147  cpl_free(softag);
148  cpl_errorstate_set(prestate);
149  *error = 1;
150  return;
151  }
152 
153  cpl_free(softag);
154 
155  /* Load extension TRANSFER_FUNCTION */
156 
157  prestate = cpl_errorstate_get();
158 
159  ext_trf=cpl_fits_find_extension(cpl_frame_get_filename(cur_frame),"TRANSFER_FUNCTION");
160 
161  if((table = cpl_table_load(cpl_frame_get_filename(cur_frame), ext_trf, 1))==NULL)
162  {
163  cpl_msg_info(cpl_func, "No siutable table found in the file %s\n",cpl_frame_get_filename(cur_frame));
164  cpl_msg_warning(cpl_func, "No transfer function applied");
165  cpl_errorstate_set(prestate);
166  *error = 1;
167  return;
168  }
169 
170  // Check if number of records is consistent
171  dimentrf=cpl_table_get_nrow(table);
172  if ( dimentrf != format->iXWidth)
173  {
174  cpl_msg_warning(cpl_func, "Inconsistent Number of Records found");
175  cpl_msg_warning(cpl_func, "No transfer function applied");
176  cpl_errorstate_set(prestate);
177  cpl_table_delete(table);
178  *error = 1;
179  return;
180  }
181 
182  /* If all is Ok read the values */
183 
184  if (cpl_table_has_column(table, "TRF") && cpl_table_has_column(table, "TRF_ERROR") )
185  {
186 
187  for (X=0; X<dimentrf;X++){
188  dispResult->trf[X]=cpl_table_get_float(table, "TRF", X, NULL);
189  dispResult->trfErr[X]=cpl_table_get_float(table, "TRF_ERROR", X, NULL);
190  }
191  }
192  else{
193  cpl_msg_info(cpl_func, "No siutable table column found in the file %s\n",cpl_frame_get_filename(cur_frame));
194  cpl_msg_warning(cpl_func,"No transfer function applied");
195  cpl_table_delete(table);
196  *error = 1;
197  return;
198  }
199 
200 
201 /* Save the fits table into a fits file */
202  qclist=cpl_propertylist_new();
203 
204  /* Save QC parameters from the original file to the new product */
205  dummy_propertylist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
206  cpl_propertylist_copy_property_regexp(qclist, dummy_propertylist, "^ESO QC",0);
207  cpl_propertylist_delete(dummy_propertylist);
208 
209  if (strcmp(format->grismId,"GRISM")==0) {
210  cpl_propertylist_update_string(qclist, CPL_DFS_PRO_CATG, "TRF_GRISM");
211  dataname=cpl_sprintf("MIDI_trf_grism.fits");
212  }
213  if (strcmp(format->grismId,"PRISM")==0) {
214  cpl_propertylist_update_string(qclist, CPL_DFS_PRO_CATG, "TRF_PRISM");
215  dataname=cpl_sprintf("MIDI_trf_prism.fits");
216  }
217  cpl_propertylist_append_string(qclist, "EXTNAME", "TRANSFER_FUNCTION");
218 
219 
220  cpl_dfs_save_table(frameset, NULL, parlist, frameset, NULL, table,
221  qclist, "midi_fringe_all",
222  qclist, NULL,
223  PACKAGE "/" PACKAGE_VERSION,
224  dataname);
225 
226  cpl_propertylist_delete(qclist);
227  cpl_free(dataname);
228  cpl_table_delete(table);
229 
230 
231 
232 /* -------------------------------------------------------------------------- */
233  // Allicate memory
234 /* givenGrismId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char)); */
235 
236 /* // Check if Transfer Function is available. Try to open the file for reading */
237 /* if (diagnostic)cpl_msg_info(cpl_func,"Trying to extract Transfer Functions from %s \n", fileNames->trfNameRead); */
238 /* fprintf (midiReportPtr, "Trying to extract Transfer Functions from %s \n", fileNames->trfNameRead); */
239 /* if ((trfPtr = fopen (fileNames->trfNameRead, "r")) == NULL) */
240 /* { */
241 /* *error = 1; */
242 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open Transfer Function file"); */
243 /* free (givenGrismId); */
244 /* return; */
245 /* } */
246 
247 /* // Read Grism ID */
248 /* if (fscanf (trfPtr, "%s \n", givenGrismId) == EOF) */
249 /* { */
250 /* *error = 1; */
251 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Grism ID"); */
252 /* if (trfPtr) fclose (trfPtr); */
253 /* free (givenGrismId); */
254 /* if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
255 /* return; */
256 /* } */
257 /* else */
258 /* { */
259 /* // Check if the given Grism ID is the same as that of the current batch */
260 /* if (strcmp (format->grismId, givenGrismId) != 0) */
261 /* { */
262 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent Grism ID"); */
263 /* if (diagnostic)cpl_msg_info(cpl_func,"Given grism ID = %s. Expected %s \n", givenGrismId, format->grismId); */
264 /* fprintf (midiReportPtr, "Given grism ID = %s. Expected %s \n", givenGrismId, format->grismId); */
265 /* if (trfPtr) fclose (trfPtr); */
266 /* free (givenGrismId); */
267 /* if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
268 /* return; */
269 /* } */
270 /* if (diagnostic)cpl_msg_info(cpl_func,"Given grism ID = %s. Expected %s \n", givenGrismId, format->grismId); */
271 /* fprintf (midiReportPtr, "Given grism ID = %s. Expected %s \n", givenGrismId, format->grismId); */
272 /* } */
273 
274 /* // Get number of records */
275 /* if (fscanf (trfPtr, "%d \n", &numOfRecords) == EOF) */
276 /* { */
277 /* *error = 1; */
278 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Number of Records"); */
279 /* if (trfPtr) fclose (trfPtr); */
280 /* free (givenGrismId); */
281 /* if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
282 /* return; */
283 /* } */
284 /* else */
285 /* { */
286 /* // Check if number of records is consistent */
287 /* if (numOfRecords != format->iXWidth) */
288 /* { */
289 /* *error = 1; */
290 /* sprintf (midiMessage, "Inconsistent Number of Records from %s. Expected %d", */
291 /* fileNames->trfNameRead, format->iXWidth); */
292 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
293 /* if (diagnostic)cpl_msg_info(cpl_func,"Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
294 /* fprintf (midiReportPtr, "Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
295 /* if (trfPtr) fclose (trfPtr); */
296 /* free (givenGrismId); */
297 /* if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
298 /* return; */
299 /* } */
300 /* if (diagnostic)cpl_msg_info(cpl_func,"Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
301 /* fprintf (midiReportPtr, "Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
302 /* } */
303 
304 /* // If all is well then try to load the data into the array */
305 /* for (X = 0; X < format->iXWidth; X++) */
306 /* { */
307 /* if (fscanf (trfPtr, "%f %f", &(dispResult->trf[X]), &(dispResult->trfErr[X])) == EOF) */
308 /* { */
309 /* *error = 1; */
310 /* midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Transfer Functions"); */
311 /* if (trfPtr) fclose (trfPtr); */
312 /* free (givenGrismId); */
313 /* if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
314 /* return; */
315 /* } */
316 /* fscanf (trfPtr, "\n"); */
317 /* if (diagnostic)cpl_msg_info(cpl_func,"Channel %3d = %f %f \n", X, (dispResult->trf)[X], (dispResult->trfErr)[X]); */
318 /* fprintf (midiReportPtr, "Channel %3d = %f %f \n", X, (dispResult->trf)[X], (dispResult->trfErr)[X]); */
319 /* } */
320 /* if (diagnostic)cpl_msg_info(cpl_func,"\nRead %d sets of transfer function values from %s \n", format->iXWidth, fileNames->trfNameRead); */
321 /* fprintf (midiReportPtr, "\nRead %d sets of transfer function values from %s \n", format->iXWidth, fileNames->trfNameRead); */
322 /* if (trfPtr) fclose (trfPtr); */
323 /* free (givenGrismId); */
324 /* if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
325 
326 
327  // Compute calibrated visibilities
328  if (diagnostic)cpl_msg_info(cpl_func,"\nChannel Calibrated Visibility Calibrated Visibility Error \n");
329  if (diagnostic)cpl_msg_info(cpl_func,"------------------------------------------------------------- \n");
330  fprintf (midiReportPtr, "\nChannel Calibrated Visibility Calibrated Visibility Error QCLOG \n");
331  fprintf (midiReportPtr, "------------------------------------------------------------- QCLOG\n");
332  for (X = 0; X < format->iXWidth; X++)
333  {
334  if (badChannelList[X] || (dispResult->trf[X] <= 0.0))
335  {
336  badChannelList[X] |= BSL_DATA_ERROR;
337  if (diagnostic)cpl_msg_info(cpl_func,"%3d <-- %s --> \n", X, UNAV);
338  fprintf (midiReportPtr, "%3d <-- %s --> \n", X, UNAV);
339  continue;
340  }
341 
342  (dispResult->calibVis2)[X] = (dispResult->normVis2)[X] / (dispResult->trf)[X];
343  (dispResult->calibVis2Err)[X] = (dispResult->normVis2Err)[X] / (fabs ((dispResult->trf)[X])) +
344  (dispResult->trfErr)[X] * (fabs ((dispResult->normVis2)[X]) / ((dispResult->trf)[X] * (dispResult->trf)[X]));
345 
346  if (diagnostic)cpl_msg_info(cpl_func,"%3d %5.4f %5.4f \n",
347  X, (dispResult->calibVis2)[X], (dispResult->calibVis2Err)[X]);
348  fprintf (midiReportPtr, "%3d %5.4f %5.4f QCLOG \n",
349  X, (dispResult->calibVis2)[X], (dispResult->calibVis2Err)[X]);
350  }
351 
352  if (plotFile)
353  {
354  midiCreatePlotFile2D ("CalibVisCombined", "Combined Calibrated Visibility",
355  "Channale", "Visibility", 0, dispResult->calibVis2, 0, format->iXWidth, 1, 0);
356 
357  midiCreatePlotFile2D ("CalibVisErrCombined", "Combined Calibrated Visibility Error",
358  "Channel", "Visibility Error", 0, dispResult->calibVis2Err, 0, format->iXWidth, 1, 0);
359 
360  midiCreatePlotFile2D ("NormalizedUncalibVisCombined", "Combined Calibrated Visibility",
361  "Channale", "Visibility", 0, dispResult->calibVis2, 0, format->iXWidth, 1, 0);
362 
363  midiCreatePlotFile2D ("NormalizedUncalibVisErrCombined", "Combined Calibrated Visibility Error",
364  "Channel", "Visibility Error", 0, dispResult->calibVis2Err, 0, format->iXWidth, 1, 0);
365  }
366 
367  // Close files
368  dispResult->trfExists = 1;
369  dispResult->calibVisExists = 1;
370 
371  return;
372 }
373 /*****************************************************************************/
374 
375 /******************************************************************************
376 * European Southern Observatory
377 * VLTI MIDI Data Reduction Software
378 *
379 * Module name: computeUncalibVisHSUndisp
380 * Input/Output: See function arguments to avoid duplication
381 * Description: Uses the results of the estimateFringe() together with
382 * any other parameters (TBD) and errors and computes
383 * an estimate of the visibility. This routine applies to both
384 * CALIB and SCIENCE targets.
385 *
386 * History:
387 * 02-Dec-03 (csabet) Created
388 ******************************************************************************/
389 void computeUncalibVisHSUndisp (
390  RawVisibility *rawVis,
391  PhotometryResult *photom)
392 {
393 
394  /* Local Declarations
395  --------------------*/
396  const char routine[] = "computeUncalibVisHSUndisp";
397 
398  /* Algorithm
399  -----------*/
400  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
401  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
402 
403  cpl_msg_info(cpl_func,"\nComputing Uncalibrated Visibilities for batch %d \n", batchNumber);
404  cpl_msg_info(cpl_func,"--------------------------------------------- \n");
405  fprintf (midiReportPtr, "\nComputing Uncalibrated Visibilities for batch %d \n", batchNumber);
406  fprintf (midiReportPtr, "--------------------------------------------- \n");
407 
408  rawVis->visErr = fabs (rawVis->vis * (photom->chop2ChopAErr[0] + photom->chop2ChopAErr[1] +
409  photom->chop2ChopBErr[0] + photom->chop2ChopBErr[1]) / (8.0 * sqrt(2.0)));
410  rawVis->vis1Err = fabs (rawVis->vis1 * (photom->chop2ChopAErr[0] + photom->chop2ChopAErr[1] +
411  photom->chop2ChopBErr[0] + photom->chop2ChopBErr[1]) / 8.0);
412  rawVis->vis2Err = fabs (rawVis->vis2 * (photom->chop2ChopAErr[0] + photom->chop2ChopAErr[1] +
413  photom->chop2ChopBErr[0] + photom->chop2ChopBErr[1]) / 8.0);
414  rawVis->visSqrdErr = 2.0 * (rawVis->visErr * fabs (rawVis->vis));
415  rawVis->visSqrd1Err = 2.0 * (rawVis->vis1Err * fabs (rawVis->vis1));
416  rawVis->visSqrd2Err = 2.0 * (rawVis->vis2Err * fabs (rawVis->vis2));
417 
418  cpl_msg_info(cpl_func,"Uncalibrated Visibility region 0 = %f \n", rawVis->vis);
419  cpl_msg_info(cpl_func,"Uncalibrated Visibility region 0 Error = %f \n", rawVis->visErr);
420  cpl_msg_info(cpl_func,"Uncalibrated Visibility region 1 = %f \n", rawVis->vis1);
421  cpl_msg_info(cpl_func,"Uncalibrated Visibility region 1 Error = %f \n", rawVis->vis1Err);
422  cpl_msg_info(cpl_func,"Uncalibrated Visibility region 2 = %f \n", rawVis->vis2);
423  cpl_msg_info(cpl_func,"Uncalibrated Visibility region 2 Error = %f \n", rawVis->vis2Err);
424  cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 0 = %f \n", rawVis->visSqrd);
425  cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 0 Error = %f \n", rawVis->visSqrdErr);
426  cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 1 = %f \n", rawVis->visSqrd1);
427  cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 1 Error = %f \n", rawVis->visSqrd1Err);
428  cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 2 = %f \n", rawVis->visSqrd2);
429  cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 2 Error = %f \n", rawVis->visSqrd2Err);
430 
431  fprintf (midiReportPtr, "Uncalibrated Visibility region 0 = %f \n", rawVis->vis);
432  fprintf (midiReportPtr, "Uncalibrated Visibility region 0 Error = %f \n", rawVis->visErr);
433  fprintf (midiReportPtr, "Uncalibrated Visibility region 1 = %f \n", rawVis->vis1);
434  fprintf (midiReportPtr, "Uncalibrated Visibility region 1 Error = %f \n", rawVis->vis1Err);
435  fprintf (midiReportPtr, "Uncalibrated Visibility region 2 = %f \n", rawVis->vis2);
436  fprintf (midiReportPtr, "Uncalibrated Visibility region 2 Error = %f \n", rawVis->vis2Err);
437  fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 0 = %f \n", rawVis->visSqrd);
438  fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 0 Error = %f \n", rawVis->visSqrdErr);
439  fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 1 = %f \n", rawVis->visSqrd1);
440  fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 1 Error = %f \n", rawVis->visSqrd1Err);
441  fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 2 = %f \n", rawVis->visSqrd2);
442  fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 2 Error = %f \n", rawVis->visSqrd2Err);
443 
444  return;
445 }
446 /*****************************************************************************/
447 
448 
449 /******************************************************************************
450 * European Southern Observatory
451 * VLTI MIDI Data Reduction Software
452 *
453 * Module name: computeCalibVisHSUndisp
454 * Input/Output: See function arguments to avoid duplication
455 * Description: This routine computes the final visibility on SCIENCE targets. It
456 * requires the transfer function as well as the uncalibrated
457 * visibilities.
458 *
459 * History:
460 * 21-Jul-03 (csabet) Created
461 ******************************************************************************/
462 void computeCalibVisHSUndisp (
463  MidiFiles *fileNames, // In: Pointer to MIDI file structure
464  RawVisibility *rawVis, // In: Raw visibilities
465  TransferFunction *trf, // In: Transfer Functions
466  CalibratedVisibility *calibVis, // Ou: Calibrated visibilities
467  int *error) // Ou: Status
468 {
469 
470  /* Local Declarations
471  --------------------*/
472  const char routine[] = "computeCalibVisHSUndisp";
473  FILE *trfPtr;
474  int i;
475 
476  /* Algorithm
477  -----------*/
478  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
479  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
480 
481  cpl_msg_info(cpl_func,"\nComputing Calibrated Visibility for batch %d \n", batchNumber);
482  cpl_msg_info(cpl_func,"----------------------------------------- \n");
483  fprintf (midiReportPtr, "\nComputing Calibrated Visibility for batch %d \n", batchNumber);
484  fprintf (midiReportPtr, "----------------------------------------- \n");
485 
486  /* Reset parameters */
487  *error = 0;
488  trf->exists = 0;
489  calibVis->exists = 0;
490 
491  /* Open the transfer function file for reading */
492  if ((trfPtr = fopen (fileNames->trfNameRead, "r")) == NULL)
493  {
494  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open Transfer Functions file");
495  *error = 1;
496  return;
497  }
498 
499  /* Read the transfer fuctions from the file */
500  for (i = 0; i < 6; i++)
501  {
502  if (fscanf (trfPtr, "%f\n", &(trf->trf[i])) == EOF)
503  {
504  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Transfer Functions");
505  *error = 1;
506  return;
507  }
508  if (fscanf (trfPtr, "%f\n", &(trf->trfErr[i])) == EOF)
509  {
510  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Transfer Functions");
511  *error = 1;
512  return;
513  }
514  }
515 
516  /* Compute calibrated visibilities */
517  if (trf->trf[0] == 0 || trf->trfErr[0] == 0 ||
518  trf->trf[1] == 0 || trf->trfErr[1] == 0 ||
519  trf->trf[2] == 0 || trf->trfErr[2] == 0 ||
520  trf->trf[3] == 0 || trf->trfErr[3] == 0 ||
521  trf->trf[4] == 0 || trf->trfErr[4] == 0 ||
522  trf->trf[5] == 0 || trf->trfErr[5] == 0)
523  {
524  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
525  "A singularity encountered. Cannot compute Calibrated Visibilities");
526  *error = 1;
527  return;
528  }
529  else
530  {
531  calibVis->vis[0] = rawVis->vis / trf->trf[0];
532  calibVis->visErr[0] = rawVis->visErr / (fabs (trf->trf[0])) +
533  trf->trfErr[0] * (fabs (rawVis->vis) / (trf->trf[0] * trf->trf[0]));
534 
535  calibVis->vis[1] = rawVis->vis1 / trf->trf[1];
536  calibVis->visErr[1] = rawVis->vis1Err / (fabs (trf->trf[1])) +
537  trf->trfErr[1] * (fabs (rawVis->vis1) / (trf->trf[1] * trf->trf[1]));
538 
539  calibVis->vis[2] = rawVis->vis2 / trf->trf[2];
540  calibVis->visErr[2] = rawVis->vis2Err / (fabs (trf->trf[2])) +
541  trf->trfErr[2] * (fabs (rawVis->vis2) / (trf->trf[2] * trf->trf[2]));
542 
543  calibVis->visSqrd[0] = rawVis->visSqrd / trf->trf[3];
544  calibVis->visSqrdErr[0] = rawVis->visSqrdErr / (fabs (trf->trf[3])) +
545  trf->trfErr[3] * (fabs (rawVis->visSqrd) / (trf->trf[3] * trf->trf[3]));
546 
547  calibVis->visSqrd[1] = rawVis->visSqrd1 / trf->trf[4];
548  calibVis->visSqrdErr[1] = rawVis->visSqrd1Err / (fabs (trf->trf[4])) +
549  trf->trfErr[4] * (fabs (rawVis->visSqrd1) / (trf->trf[4] * trf->trf[4]));
550 
551  calibVis->visSqrd[2] = rawVis->visSqrd2 / trf->trf[5];
552  calibVis->visSqrdErr[2] = rawVis->visSqrd2Err / (fabs (trf->trf[5])) +
553  trf->trfErr[5] * (fabs (rawVis->visSqrd2) / (trf->trf[5] * trf->trf[5]));
554  }
555 
556  /* Report results and close file */
557  cpl_msg_info(cpl_func,"Calibrated Visibility region 0 = %f \n", calibVis->vis[0]);
558  cpl_msg_info(cpl_func,"Calibrated Visibility region 0 Error = %f \n", calibVis->visErr[0]);
559  cpl_msg_info(cpl_func,"Calibrated Visibility region 1 = %f \n", calibVis->vis[1]);
560  cpl_msg_info(cpl_func,"Calibrated Visibility region 1 Error = %f \n", calibVis->visErr[1]);
561  cpl_msg_info(cpl_func,"Calibrated Visibility region 2 = %f \n", calibVis->vis[2]);
562  cpl_msg_info(cpl_func,"Calibrated Visibility region 2 Error = %f \n", calibVis->visErr[2]);
563  cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 0 = %f \n", calibVis->visSqrd[0]);
564  cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 0 Error = %f \n", calibVis->visSqrdErr[0]);
565  cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 1 = %f \n", calibVis->visSqrd[1]);
566  cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 1 Error = %f \n", calibVis->visSqrdErr[1]);
567  cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 2 = %f \n", calibVis->visSqrd[2]);
568  cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 2 Error = %f \n", calibVis->visSqrdErr[2]);
569 
570  fprintf (midiReportPtr, "Calibrated Visibility region 0 = %f (QCLOG)\n", calibVis->vis[0]);
571  fprintf (midiReportPtr, "Calibrated Visibility region 0 Error = %f (QCLOG)\n", calibVis->visErr[0]);
572  fprintf (midiReportPtr, "Calibrated Visibility region 1 = %f (QCLOG)\n", calibVis->vis[1]);
573  fprintf (midiReportPtr, "Calibrated Visibility region 1 Error = %f (QCLOG)\n", calibVis->visErr[1]);
574  fprintf (midiReportPtr, "Calibrated Visibility region 2 = %f (QCLOG)\n", calibVis->vis[2]);
575  fprintf (midiReportPtr, "Calibrated Visibility region 2 Error = %f (QCLOG)\n", calibVis->visErr[2]);
576  fprintf (midiReportPtr, "Calibrated Squared Visibility region 0 = %f (QCLOG)\n", calibVis->visSqrd[0]);
577  fprintf (midiReportPtr, "Calibrated Squared Visibility region 0 Error = %f (QCLOG)\n", calibVis->visSqrdErr[0]);
578  fprintf (midiReportPtr, "Calibrated Squared Visibility region 1 = %f (QCLOG)\n", calibVis->visSqrd[1]);
579  fprintf (midiReportPtr, "Calibrated Squared Visibility region 1 Error = %f (QCLOG)\n", calibVis->visSqrdErr[1]);
580  fprintf (midiReportPtr, "Calibrated Squared Visibility region 2 = %f (QCLOG)\n", calibVis->visSqrd[2]);
581  fprintf (midiReportPtr, "Calibrated Squared Visibility region 2 Error = %f (QCLOG)\n", calibVis->visSqrdErr[2]);
582 
583  fclose (trfPtr);
584  remove (fileNames->trfNameRead);
585  trf->exists = 1;
586  calibVis->exists = 1;
587 
588  return;
589 }
590 /*****************************************************************************/
591 
592 
593 /******************************************************************************
594 * European Southern Observatory
595 * VLTI MIDI Data Reduction Software
596 *
597 * Module name: computeUncalibVis
598 * Input/Output: See function arguments to avoid duplication
599 * Description: Computes DISPERSED Uncalibrated Normalized Visibility
600 *
601 * History:
602 * 21-Oct-04 (JM)
603 * 21-Jan-05 (csabet) Cleaned up and Integrated
604 ******************************************************************************/
605 void computeUncalibVis (
606  ImageFormat *format, // In: General data format
607  float *freqFound, // IO: Wavelength calibration
608  DispersedResult *dispResult,// In: Dispersed result structure
609  int *error) // Ou: Error status
610 {
611 
612  /* Local Declarations
613  --------------------*/
614  const char routine[] = "computeUncalibVis";
615  int X, n;
616  float errfromvis, neterr;
617  double phot, photA, photB;
618 
619  /* Algorithm
620  -----------*/
621  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
622  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
623  cpl_msg_info(cpl_func,"\nComputing Normalized Uncalibrated Visibility for batch %d \n", batchNumber);
624  cpl_msg_info(cpl_func,"------------------------------------------------------ \n");
625  fprintf (midiReportPtr, "\nComputing Normalized Uncalibrated Visibility for batch %d \n", batchNumber);
626  fprintf (midiReportPtr, "------------------------------------------------------ \n");
627 
628  // Reset
629  *error = 0;
630 
631  // First for photometry. For SCI_PHOT each photometry has one region to process
632  for (X = 0; X < format->iXWidth; X++)
633  {
634  if (badChannelList[X])
635  continue;
636 
637  if (strcmp (format->beamCombiner, "SCI_PHOT") == 0)
638  {
639  phot = 4.F * (dispResult->photomA)[0][X] * (dispResult->photomB)[0][X];
640  (dispResult->photomNet2Err)[X] = sqrt(sqr((dispResult->photomAErr)[0][X] /
641  (dispResult->photomA)[0][X]) + sqr((dispResult->photomBErr)[0][X] /
642  (dispResult->photomB)[0][X]));
643  }
644  else
645  {
646  photA = (dispResult->photomA)[0][X] + (dispResult->photomA)[1][X];
647  photB = (dispResult->photomB)[0][X] + (dispResult->photomB)[1][X];
648  phot = 4.F*photA*photB;
649  (dispResult->photomNet2Err)[X] = sqrt((sqr((dispResult->photomAErr)[0][X]) +
650  sqr((dispResult->photomAErr)[1][X])) / sqr(photA) +
651  (sqr((dispResult->photomBErr)[0][X]) +
652  sqr((dispResult->photomBErr)[1][X])) / sqr(photB));
653  }
654 
655  if (phot > 0.F)
656  dispResult->photomNet2[X] = phot; // do not ever insert a negative value here!!
657  else
658  dispResult->photomNet2Err[X] = 0.F;// set the err to zero when the photom itself is invalid.
659  }
660 
661  // Now compute the visibility^2
662  n = 0;
663  for (X = 0; X < format->iXWidth; X++)
664  {
665  if (badChannelList[X])
666  continue;
667 
668  if ((dispResult->photomNet2)[X] > 0.F)
669  (dispResult->normVis2)[X] = (dispResult->rawVis2)[X] / (dispResult->photomNet2)[X];
670  else
671  (dispResult->normVis2)[X] = 0.F;
672 
673  if ((dispResult->normVis2)[X] <= 0.0)
674  {
675  (dispResult->normVis2)[X] = 0.F;
676  badChannelList[X] |= BSL_DATA_ERROR;
677  }
678  else
679  n++;
680  }
681 
682  if (!n)
683  {
684  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot find any good visibility range");
685  *error = 1;
686  return;
687  }
688 
689  if (diagnostic)cpl_msg_info(cpl_func,"\nChannel Freq / Wave Net photometry Visibility^2 RMS Photometry Errors percent \n");
690  fprintf (midiReportPtr, "\nChannel Freq / Wave Net photometry Visibility^2 RMS Photometry Errors percent QCLOG \n");
691  if (diagnostic)cpl_msg_info(cpl_func," THz micron ADU/frame normalized Error percent from Vis Net \n");
692  fprintf (midiReportPtr, " THz micron ADU/frame normalized Error percent from Vis Net QCLOG \n");
693 
694  for (X = 0; X < format->iXWidth; X++)
695  {
696  if (badChannelList[X])
697  {
698  if (diagnostic) cpl_msg_info(cpl_func,"%3d %6.3f %6.3f <-- %s --> \n",
699  X, 299.8F/freqFound[X], freqFound[X], UNAV);
700  fprintf (midiReportPtr, "%3d %6.3f %6.3f <-- %s --> QCLOG \n",
701  X, 299.8F/freqFound[X], freqFound[X], UNAV);
702  continue;
703  }
704 
705  if (diagnostic) cpl_msg_info(cpl_func,"%3d ", X); // Tell the column and region....
706  fprintf (midiReportPtr, "%3d ", X); // Tell the column and region....
707 
708 
709  if (diagnostic)cpl_msg_info(cpl_func," %6.3f %6.3f", 299.8F/freqFound[X], freqFound[X]);
710  if (diagnostic)cpl_msg_info(cpl_func," %9.3f", sqrt((dispResult->photomNet2)[X]));
711  if (diagnostic)cpl_msg_info(cpl_func," %7.4f", (dispResult->normVis2)[X]);
712  if (diagnostic)cpl_msg_info(cpl_func," %7.2f", 100.F*(dispResult->photomNet2Err)[X]);
713  fprintf (midiReportPtr, " %6.3f %6.3f", 299.8F/freqFound[X], freqFound[X]);
714  fprintf (midiReportPtr, " %9.3f", sqrt((dispResult->photomNet2)[X]));
715  fprintf (midiReportPtr, " %7.4f", (dispResult->normVis2)[X]);
716  fprintf (midiReportPtr, " %7.2f", 100.F*(dispResult->photomNet2Err)[X]);
717  errfromvis = (dispResult->rawVis2Err)[X] / (dispResult->rawVis2)[X]; // This must be improved. csabet 02-02-05
718  neterr = sqrt(sqr(errfromvis) + sqr((dispResult->photomNet2Err)[X]));
719  (dispResult->normVis2Err)[X] = neterr; // This must be improved. csabet 07-02-05
720  if (diagnostic)cpl_msg_info(cpl_func," %8.2f", 100.F*errfromvis);
721  if (diagnostic)cpl_msg_info(cpl_func," %8.2f", 100.F*neterr);
722  fprintf (midiReportPtr, " %8.2f", 100.F*errfromvis);
723  fprintf (midiReportPtr, " %8.2f", 100.F*neterr);
724 
725  if (diagnostic)cpl_msg_info(cpl_func,"\n");
726  fprintf (midiReportPtr, " QCLOG \n");
727  }
728 
729  if (plotFile)
730  {
731  midiCreatePlotFile2D ("PhotomNetCombined", "Combined Net Photometry",
732  "Channel", "Photometry", 0, dispResult->photomNet2, 0, format->iXWidth, 1, 0);
733  midiCreatePlotFile2D ("PhotomNetErrCombined", "Combined Net Photometry Error",
734  "Channel", "Photometry Error", 0, dispResult->photomNet2Err, 0, format->iXWidth, 1, 0);
735  midiCreatePlotFile2D ("NormalizedUncalibVisCombined", "Combined Normalized Uncalibrated Visibility",
736  "Channel", "Visibility", 0, dispResult->normVis2, 0, format->iXWidth, 1, 0);
737  midiCreatePlotFile2D ("NormalizedUncalibVisErrCombined", "Combined Normalized Uncalibrated Visibility Error",
738  "Channel", "Visibility Error", 0, dispResult->normVis2Err, 0, format->iXWidth, 1, 0);
739  }
740 
741  // Compute Binned Uncalibrated Visibilities
742  computeBinnedUncalibVis (format, dispResult, error);
743  if (*error)
744  {
745  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot compute Binned Uncalibrated visibilities");
746  return;
747  }
748 
749  return;
750 }
751 /*****************************************************************************/
752 
753 
754 /******************************************************************************
755 * European Southern Observatory
756 * VLTI MIDI Data Reduction Software
757 *
758 * Module name: normalizeVis
759 * Input/Output: See function arguments to avoid duplication
760 * Description:
761 *
762 *
763 * History:
764 * 21-Jul-03 (csabet) Created routine template
765 ******************************************************************************/
766 void normalizeVis (
767  RawVisibility *rawVis, // UNnormalized visibilities, get changed to normalized thru pointer
768  float photomA[], // Photometry of A telescope, each region
769  float photomB[]) // Photometry of B telescope, each region
770 
771 { /* Local Declarations
772  --------------------*/
773  const char routine[] = "normalizeVis";
774 
775  /* Algorithm
776  -----------*/
777  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
778  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
779 
780 // Assumes scanmix is equal between regions
781  if (((photomA[0] + photomA[1]) * (photomB[0] + photomB[1])) != 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
782  rawVis->visSqrd /= (photomA[0] + photomA[1])*(photomB[0] + photomB[1]) ;
783  else
784  rawVis->visSqrd = NOT_A_NUMBER;
785 
786  if ((photomA[0] * photomB[0]) != 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
787  rawVis->visSqrd1 /= (photomA[0]*photomB[0]) ;
788  else
789  rawVis->visSqrd1 = NOT_A_NUMBER;
790 
791  if ((photomA[1] * photomB[1]) != 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
792  rawVis->visSqrd2 /= (photomA[1]*photomB[1]) ;
793  else
794  rawVis->visSqrd2 = NOT_A_NUMBER;
795 
796  if (((photomA[0] + photomA[1]) * (photomB[0] + photomB[1])) > 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
797  rawVis->vis /= (float) sqrt((photomA[0] + photomA[1])*(photomB[0] + photomB[1])) ;
798  else
799  rawVis->vis = NOT_A_NUMBER;
800 
801  if ((photomA[0] * photomB[0]) > 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
802  rawVis->vis1 /= (float) sqrt(photomA[0]*photomB[0]) ;
803  else
804  rawVis->vis1 = NOT_A_NUMBER;
805 
806  if ((photomA[1] * photomB[1]) > 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
807  rawVis->vis2 /= (float) sqrt(photomA[1]*photomB[1]) ;
808  else
809  rawVis->vis2 = NOT_A_NUMBER;
810 
811  /* Added csabet 09-Jan-04 */
812  cpl_msg_info(cpl_func,
813  "Visibilities combined I1 I2 \n"
814  "--------------------------------------------- \n"
815  "Vis amplitude: %5.4f %5.4f %5.4f \n"
816  "Vis^2: %5.4f %5.4f %5.4f \n"
817  "sqrt(Vis^2): %5.4f %5.4f %5.4f \n",
818  rawVis->vis, rawVis->vis1, rawVis->vis2,
819  rawVis->visSqrd, rawVis->visSqrd1, rawVis->visSqrd2,
820  sqrtp(rawVis->visSqrd), sqrtp(rawVis->visSqrd1), sqrtp(rawVis->visSqrd2));
821 
822  fprintf (midiReportPtr,
823  "Visibilities combined I1 I2 QCLOG \n"
824  "--------------------------------------------- \n"
825  "Vis amplitude: %5.4f %5.4f %5.4f QCLOG \n"
826  "Vis^2: %5.4f %5.4f %5.4f QCLOG \n"
827  "sqrt(Vis^2): %5.4f %5.4f %5.4f QCLOG \n",
828  rawVis->vis, rawVis->vis1, rawVis->vis2,
829  rawVis->visSqrd, rawVis->visSqrd1, rawVis->visSqrd2,
830  sqrtp(rawVis->visSqrd), sqrtp(rawVis->visSqrd1), sqrtp(rawVis->visSqrd2));
831 
832  if ((rawVis->vis == NOT_A_NUMBER) || (rawVis->vis1 == NOT_A_NUMBER) || (rawVis->vis2 == NOT_A_NUMBER) ||
833  (rawVis->visSqrd == NOT_A_NUMBER) || (rawVis->visSqrd1 == NOT_A_NUMBER) || (rawVis->visSqrd2 == NOT_A_NUMBER) )
834  {
835  sprintf (midiMessage, "A value of %.4f is a reject result. QCLOG", (float)NOT_A_NUMBER);
836  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
837  }
838 
839  return;
840 }
841 /*****************************************************************************/
842 
843 
844 /******************************************************************************
845 * European Southern Observatory
846 * VLTI MIDI Data Reduction Software
847 *
848 * Module name: computeBinnedUncalibVis
849 * Input/Output: See function arguments to avoid duplication
850 * Description: This routine computes the uncalibrated visibilities at 5 spectral
851 * bands as follows:
852 *
853 * 1) 8.64 microns (Channels 120 -> 126) PRISM
854 * (Channels 38 -> 50) GRISM
855 * 2) 9.00 microns (Channels 113 -> 121) PRISM
856 * (Channels 52 -> 68) GRISM
857 * 3) 10.46 microns (Channels 88 -> 99) PRISM
858 * (Channels 116 -> 136) GRISM
859 * 4) 11.79 microns (Channels 60 -> 72) PRISM
860 * (Channels 176 -> 200) GRISM
861 * 5) 12.80 microns (Channels 36 -> 50) PRISM
862 * (Channels 217 -> 245) GRISM
863 *
864 * History:
865 * 21-Sep-06 (csabet) Created
866 ******************************************************************************/
867 void computeBinnedUncalibVis (
868  ImageFormat *format, // In: General data format
869  DispersedResult *dispResult, // In: Dispersed result structure
870  int *error) // Ou: Error status
871 {
872 
873  // Local Declarations
874  // ------------------
875  const char routine[] = "computeBinnedUncalibVis";
876  int i, n;
877 
878  // Algorithm
879  // ---------
880  cpl_msg_info(cpl_func,"\nBinned Uncalibrated Visibilities for batch %d \n", batchNumber);
881  cpl_msg_info(cpl_func,"------------------------------------------ \n");
882  fprintf (midiReportPtr, "\nBinned Uncalibrated Visibilities for batch %d QCLOG \n", batchNumber);
883  fprintf (midiReportPtr, "------------------------------------------ QCLOG \n");
884 
885  // Reset parameters
886  *error = 0;
887  n = 0;
888 
889  dispResult->uncalVisBinned1 = 0.0;
890  dispResult->uncalVisBinned2 = 0.0;
891  dispResult->uncalVisBinned3 = 0.0;
892  dispResult->uncalVisBinned4 = 0.0;
893  dispResult->uncalVisBinned5 = 0.0;
894 
895  if (strcmp(format->grismId, "PRISM") == 0)
896  {
897  n = 0;
898  for (i = 36; i < 51; i++)
899  {
900  if (badChannelList[i])
901  continue;
902 
903  dispResult->uncalVisBinned5 += (dispResult->normVis2)[i];
904  n++;
905  }
906  dispResult->uncalVisBinned5 /= n;
907  n = 0;
908  for (i = 60; i < 73; i++)
909  {
910  if (badChannelList[i])
911  continue;
912 
913  dispResult->uncalVisBinned4 += (dispResult->normVis2)[i];
914  n++;
915  }
916  dispResult->uncalVisBinned4 /= n;
917  n = 0;
918  for (i = 88; i < 99; i++)
919  {
920  if (badChannelList[i])
921  continue;
922 
923  dispResult->uncalVisBinned3 += (dispResult->normVis2)[i];
924  n++;
925  }
926  dispResult->uncalVisBinned3 /= n;
927  n = 0;
928  for (i = 113; i < 122; i++)
929  {
930  if (badChannelList[i])
931  continue;
932 
933  dispResult->uncalVisBinned2 += (dispResult->normVis2)[i];
934  n++;
935  }
936  dispResult->uncalVisBinned2 /= n;
937  n = 0;
938  for (i = 120; i < 127; i++)
939  {
940  if (badChannelList[i])
941  continue;
942 
943  dispResult->uncalVisBinned1 += (dispResult->normVis2)[i];
944  n++;
945  }
946  dispResult->uncalVisBinned1 /= n;
947  }
948  else if (strcmp(format->grismId, "GRISM") == 0)
949  {
950  n = 0;
951  for (i = 38; i < 51; i++)
952  {
953  if (badChannelList[i])
954  continue;
955 
956  dispResult->uncalVisBinned1 += (dispResult->normVis2)[i];
957  n++;
958  }
959  dispResult->uncalVisBinned1 /= n;
960  n = 0;
961  for (i = 52; i < 69; i++)
962  {
963  if (badChannelList[i])
964  continue;
965 
966  dispResult->uncalVisBinned2 += (dispResult->normVis2)[i];
967  n++;
968  }
969  dispResult->uncalVisBinned2 /= n;
970  n = 0;
971  for (i = 116; i < 137; i++)
972  {
973  if (badChannelList[i])
974  continue;
975 
976  dispResult->uncalVisBinned3 += (dispResult->normVis2)[i];
977  n++;
978  }
979  dispResult->uncalVisBinned3 /= n;
980  n = 0;
981  for (i = 176; i < 201; i++)
982  {
983  if (badChannelList[i])
984  continue;
985 
986  dispResult->uncalVisBinned4 += (dispResult->normVis2)[i];
987  n++;
988  }
989  dispResult->uncalVisBinned4 /= n;
990  n = 0;
991  for (i = 217; i < 246; i++)
992  {
993  if (badChannelList[i])
994  continue;
995 
996  dispResult->uncalVisBinned5 += (dispResult->normVis2)[i];
997  n++;
998  }
999  dispResult->uncalVisBinned5 /= n;
1000  }
1001  else
1002  {
1003  sprintf (midiMessage, "Unknown GRISM ID ... %s", format->grismId);
1004  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
1005  *error = 1;
1006  return;
1007  }
1008 
1009  // Report
1010  cpl_msg_info(cpl_func,"Grism ID: %s \n", format->grismId);
1011  fprintf (midiReportPtr, "Grism ID: %s QCLOG \n", format->grismId);
1012  if (strcmp(format->grismId, "PRISM") == 0)
1013  {
1014  cpl_msg_info(cpl_func," 8.64 micron (Channel 120 -> 126) = %0.4f \n", dispResult->uncalVisBinned1);
1015  cpl_msg_info(cpl_func," 9.00 micron (Channel 113 -> 121) = %0.4f \n", dispResult->uncalVisBinned2);
1016  cpl_msg_info(cpl_func,"10.46 micron (Channel 88 -> 98) = %0.4f \n", dispResult->uncalVisBinned3);
1017  cpl_msg_info(cpl_func,"11.79 micron (Channel 60 -> 72) = %0.4f \n", dispResult->uncalVisBinned4);
1018  cpl_msg_info(cpl_func,"12.80 micron (Channel 36 -> 50) = %0.4f \n", dispResult->uncalVisBinned5);
1019 
1020  fprintf (midiReportPtr, " 8.64 micron (Channel 120 -> 126) = %0.4f QCLOG \n", dispResult->uncalVisBinned1);
1021  fprintf (midiReportPtr, " 9.00 micron (Channel 113 -> 121) = %0.4f QCLOG \n", dispResult->uncalVisBinned2);
1022  fprintf (midiReportPtr, "10.46 micron (Channel 88 -> 98) = %0.4f QCLOG \n", dispResult->uncalVisBinned3);
1023  fprintf (midiReportPtr, "11.79 micron (Channel 60 -> 72) = %0.4f QCLOG \n", dispResult->uncalVisBinned4);
1024  fprintf (midiReportPtr, "12.80 micron (Channel 36 -> 50) = %0.4f QCLOG \n", dispResult->uncalVisBinned5);
1025  }
1026  else
1027  {
1028  cpl_msg_info(cpl_func," 8.64 micron (Channel 38 -> 50) = %0.4f \n", dispResult->uncalVisBinned1);
1029  cpl_msg_info(cpl_func," 9.00 micron (Channel 52 -> 68) = %0.4f \n", dispResult->uncalVisBinned2);
1030  cpl_msg_info(cpl_func,"10.46 micron (Channel 116 -> 136) = %0.4f \n", dispResult->uncalVisBinned3);
1031  cpl_msg_info(cpl_func,"11.79 micron (Channel 176 -> 200) = %0.4f \n", dispResult->uncalVisBinned4);
1032  cpl_msg_info(cpl_func,"12.80 micron (Channel 217 -> 245) = %0.4f \n", dispResult->uncalVisBinned5);
1033 
1034  fprintf (midiReportPtr, " 8.64 micron (Channel 38 -> 50) = %0.4f QCLOG \n", dispResult->uncalVisBinned1);
1035  fprintf (midiReportPtr, " 9.00 micron (Channel 52 -> 68) = %0.4f QCLOG \n", dispResult->uncalVisBinned2);
1036  fprintf (midiReportPtr, "10.46 micron (Channel 116 -> 136) = %0.4f QCLOG \n", dispResult->uncalVisBinned3);
1037  fprintf (midiReportPtr, "11.79 micron (Channel 176 -> 200) = %0.4f QCLOG \n", dispResult->uncalVisBinned4);
1038  fprintf (midiReportPtr, "12.80 micron (Channel 217 -> 245) = %0.4f QCLOG \n", dispResult->uncalVisBinned5);
1039  }
1040 
1041  return;
1042 }
1043 /*****************************************************************************/
1044