MIDI Pipeline Reference Manual  2.8.3
procRefPix.c
1 
2 /******************************************************************************
3 *******************************************************************************
4 * European Southern Observatory
5 * VLTI MIDI Maintenance Templates Software
6 *
7 * Module name: procRefPix.c
8 * Description: Contains routines for processing the templates
9 *
10 * History:
11 * 16-Jun-04 (csabet) created
12 *******************************************************************************
13 ******************************************************************************/
14 
15 /******************************************************************************
16 * Compiler directives
17 ******************************************************************************/
18 
19 /******************************************************************************
20 * Include files
21 ******************************************************************************/
22 #include <math.h>
23 #include <stdio.h>
24 #include <cpl.h>
25 #include "midiGlobal.h"
26 #include "midiLib.h"
27 #include "imageProcessing.h"
28 #include "memoryHandling.h"
29 #include "createProdRefPix.h"
30 #include "procRefPix.h"
31 #include "errorHandling.h"
32 #include "midiFitsUtility.h"
33 #include "fitsAnalysisTec.h"
34 #include "diagnostics.h"
35 #include "qfits.h"
36 
37 /**********************************************************
38 * Constant definitions
39 **********************************************************/
40 
41 /**********************************************************
42 * Global Variables
43 **********************************************************/
44 
45 /*============================ C O D E A R E A ===========================*/
46 
47 
48 
49 /******************************************************************************
50 * European Southern Observatory
51 * VLTI MIDI Maintenance Templates Software
52 *
53 * Module name: procRefPix
54 * Input/Output: See function arguments to avoid duplication
55 * Description: Evaluates the reference positions of the VLTI beams on the MIDI
56 * detector for the fine positioning of the target. This is the main
57 * routine for this application.
58 *
59 * History:
60 * 03-May-05 (csabet) Created
61 ******************************************************************************/
62 void procRefPix (
63  MidiFiles *fileNames, // In: Pointer to file names
64  int *error) // Ou: Error status
65 {
66 
67  // Local Declarations
68  // ------------------
69  const char routine[] = "procRefPix";
70  ImageFormat *format=NULL;
71  ReferencePixel *refPix=NULL;
72  int numOfExposures, maxNumOfBeams;
73  FILE *signaturePtr=NULL;
74 
75  // Algorithm
76  // ---------
77  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
78  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
79 
80  // Write a signature
81  signaturePtr = fopen ("MIDI_sig_pix.log", "w");
82  fclose (signaturePtr);
83 
84  // Reset status
85  *error = 0;
86  numOfExposures = 0;
87  maxNumOfBeams = 0;
88 
89  // Allocate memory
90  format = callocImageFormat ();
91 
92  analyseFitsRefPix (fileNames, format, &numOfExposures, &maxNumOfBeams, error);
93  if (*error)
94  {
95  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot analyse REFPIX");
96  freeImageFormat (format);
97  return;
98  }
99 
100  refPix = callocRefPix (numOfExposures, maxNumOfBeams);
101  computeRefPix (fileNames, refPix, error);
102  if (*error)
103  {
104  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot process REFPIX");
105  freeRefPix (refPix);
106  freeImageFormat (format);
107  return;
108  }
109 
110  createRefPixProd (fileNames, format, refPix, error);
111  if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create REFPIX products");
112 
113  // Release memory
114  freeRefPix (refPix);
115  freeImageFormat (format);
116 
117  return;
118 }
119 /*****************************************************************************/
120 
121 
122 
123 /******************************************************************************
124 * European Southern Observatory
125 * VLTI MIDI Maintenance Templates Software
126 *
127 * Module name: computeRefPix
128 * Input/Output: See function arguments to avoid duplication
129 * Description: Evaluates the reference positions of the VLTI beams on the MIDI
130 * detector for the fine positioning of the target. It also monitors
131 * and evaluates the stability of the beams inside the MIDI dewar
132 * For every frame of the beam compute the coordinates of the brightest
133 * pixel (x1, y1). This is found by a 2D gaussian fit or any suitable
134 * centroiding method. The output for beam 1 (I1) is N coordinates
135 * where N is the number of frames. Carry out the same for beam 2 (I2)
136 * and obtain a second set of coordinates. A number of correlation may be
137 * carried out to assess the quality of the output. If DATA1 and DATA2
138 * are combined into DATA1 then we need to know the sub-image coordinates.
139 *
140 * History:
141 * 11-Aug-04 (csabet) Created
142 ******************************************************************************/
143 void computeRefPix (
144  MidiFiles *fileNames, // In: Pointer to the MIDI file structure
145  ReferencePixel *refPix, // Ou: Pointer to the reference pixel data structure
146  int *error) // Ou: Error status
147 {
148 
149  // Local Declarations
150  // ------------------
151  const char routine[] = "computeRefPix";
152  char *fileTemp, *classification;
153  FILE *inFitsBatchPtr;
154  ImageFormat *format;
155  int localError, fileNumber, extNumOfImagingDataFile;
156 
157  // Algorithm
158  // ---------
159  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
160  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
161 
162  // Allocate memory
163  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
164  fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
165  format = callocImageFormat ();
166 
167  // Reset status
168  *error = 0;
169  localError = 0;
170  fileNumber = 0;
171  refPix->exists = 0;
172  format->hasData = 0;
173 
174  // Open the list of files
175  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
176  {
177  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
178  "Cannot open input FITS file list\n No data preprocessing has been carried out for this batch");
179  freeImageFormat (format);
180  free (fileTemp);
181  free (classification);
182  *error = 1;
183  return;
184  }
185 
186  // Loop through the files and analyse
187  while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
188  {
189  sprintf (classification, "%s", "");
190  sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
191  if (diagnostic)cpl_msg_info(cpl_func,"\n Processing file %s \n", fileNames->inFitsName);
192  fprintf(midiReportPtr, "\n Processing file %s \n", fileNames->inFitsName);
193 
194  // Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
195  extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, &localError);
196  if (localError)
197  {
198  *error = 1;
199  break;
200  }
201 
202  // Get Image Format parameters
203  if (extNumOfImagingDataFile > 0)
204  {
205  getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, format, &localError);
206  if (localError)
207  {
208  *error = 1;
209  break;
210  }
211  }
212  else format->hasData = 0;
213 
214  // Check if the file has data
215  if (format->hasData)
216  {
217  /* Check Categ, Tech and Type and then compute the image size */
218  if ((strcmp (format->obsCatg, "CALIB") == 0) &&
219  (strcmp (format->obsTech, "IMAGE") == 0) &&
220  (strcmp (format->obsType, "FMTCHCK") == 0))
221  {
222  // Save beam combiner and sutter ID
223  sprintf (refPix->exposure[fileNumber].shutterId, "%s", format->shutterId);
224  sprintf (refPix->exposure[fileNumber].beamCombiner, "%s", format->beamCombiner);
225  if ((strcmp (format->beamCombiner, "HIGH_SENS") == 0) ||
226  (strcmp (format->beamCombiner, "OPEN") == 0))
227  refPix->exposure[fileNumber].numOfBeams = 2;
228  else if (strcmp (format->beamCombiner, "SCI_PHOT") == 0)
229  refPix->exposure[fileNumber].numOfBeams = 3;
230 
231  if (diagnostic)cpl_msg_info(cpl_func," Beam combiner for file %d = %s\n", fileNumber+1,
232  refPix->exposure[fileNumber].beamCombiner);
233  if (diagnostic)cpl_msg_info(cpl_func," Shutter ID for file %d = %s\n", fileNumber+1,
234  refPix->exposure[fileNumber].shutterId);
235  if (diagnostic)cpl_msg_info(cpl_func," Number of beams for file %d = %d\n", fileNumber+1,
236  refPix->exposure[fileNumber].numOfBeams);
237  fprintf (midiReportPtr, " Beam combiner for file %d = %s\n", fileNumber+1,
238  refPix->exposure[fileNumber].beamCombiner);
239  fprintf (midiReportPtr, " Shutter ID for file %d = %s\n", fileNumber+1,
240  refPix->exposure[fileNumber].shutterId);
241  fprintf (midiReportPtr, " Number of beams for file %d = %d\n", fileNumber+1,
242  refPix->exposure[fileNumber].numOfBeams);
243 
244  // Calculate Image Centroids
245  procCentroidsRefPix (fileNumber, fileNames->inFitsName, extNumOfImagingDataFile,
246  format, refPix, &localError);
247  if (localError) *error = 1;
248 
249  // Set the flags
250  refPix->exists = 1;
251 
252  // Increment file number but make sure it is not greater than the allocated
253  fileNumber++;
254  if (fileNumber > refPix->numOfExposures)
255  {
256  *error = 1;
257  break;
258  }
259  }
260  else
261  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, "The above file is not suitable for this task");
262  }
263  else
264  {
265  if (diagnostic)
266  {
267  sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
268  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
269  }
270  }
271  }
272 
273  // Check if processing has been carried out
274  if ((refPix->exists) && !(*error) && (fileNumber == refPix->numOfExposures))
275  {
276  cpl_msg_info(cpl_func,"\nReference Pixel Position Inventry: \n");
277  cpl_msg_info(cpl_func,"================================= \n");
278  cpl_msg_info(cpl_func," Expected number of data files = %d\n", refPix->numOfExposures);
279  cpl_msg_info(cpl_func," Number of data files processed = %d\n", fileNumber);
280  cpl_msg_info(cpl_func,"\n");
281 
282  fprintf (midiReportPtr, "\nReference Pixel Position Inventry: \n");
283  fprintf (midiReportPtr, "================================= \n");
284  fprintf (midiReportPtr, " Expected number of data files = %d\n", refPix->numOfExposures);
285  fprintf (midiReportPtr, " Number of data files processed = %d\n", fileNumber);
286  fprintf (midiReportPtr, "\n");
287 
288  // Beam analysis
289  // -------------
290  evaluateBeamPosition ();
291  }
292 
293  if (*error || localError)
294  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create an Image Centroid Data for this batch");
295 
296  // Close the file list
297  fclose (inFitsBatchPtr);
298 
299  // Release memory
300  freeImageFormat (format);
301  free (fileTemp);
302  free (classification);
303 
304  return;
305 }
306 /*****************************************************************************/
307 
308 
309 
310 /******************************************************************************
311 * European Southern Observatory
312 * VLTI MIDI Maintenance Templates Software
313 *
314 * Module name: procCentroidsRefPix
315 * Input/Output: See function arguments to avoid duplication
316 * Description: Main routine for computing the averaged image and the coordinates of
317 * the targets
318 * The structure of the centroid data is as follows:
319 * refPix->centrod[0] beam 1 of OPEN file 1 ABOPEN (Imaging)
320 * refPix->centrod[1] beam 2 of OPEN file 1 ABOPEN (Imaging)
321 * refPix->centrod[2] beam 1 of HIGH_SENS file 2 AOPEN
322 * refPix->centrod[3] beam 2 of HIGH_SENS file 2 AOPEN
323 * refPix->centrod[4] beam 1 of HIGH_SENS file 3 BOPEN
324 * refPix->centrod[5] beam 2 of HIGH_SENS file 3 BOPEN
325 * refPix->centrod[6] beam 1 of SCI_PHOT file 4 AOPEN
326 * refPix->centrod[7] beam 2 of SCI_PHOT file 4 AOPEN
327 * refPix->centrod[8] beam 3 of SCI_PHOT file 4 AOPEN
328 * refPix->centrod[9] beam 1 of SCI_PHOT file 5 BOPEN
329 * refPix->centrod[10] beam 2 of SCI_PHOT file 5 BOPEN
330 * refPix->centrod[11] beam 3 of SCI_PHOT file 5 BOPEN
331 *
332 *
333 * History:
334 * 11-Aug-04 (csabet) Created
335 * 28-Aug-06 (csabet) Modified
336 ******************************************************************************/
337 void procCentroidsRefPix (
338  int fileNumber, // In: File number
339  char *inFitsName, // In: Name of file to process
340  int extensionNumber,// In: Extension number of the IMAGE_DATA
341  ImageFormat *format, // In: Pointer to the image format
342  ReferencePixel *refPix, // Ou: Pointer to the reference pixel data structure
343  int *error) // Ou: Error status
344 
345 {
346 
347  // Local Declarations
348  // ------------------
349  const char routine[] = "procCentroidsRefPix";
350  qfits_table *pTable = NULL;
351  short int *inData;
352  char *tempStr, *string, *title, *dataName;
353  int i, foundData = 0, scalingOffset, indexData, subWindowSize;
354  float *aveImage;
355 
356 
357  // Algorithm
358  // ---------
359  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
360  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
361 
362  // Reset status
363  *error = 0;
364 
365  // Open IMAGING_DATA = INDEX 2
366  pTable = qfits_table_open (inFitsName, extensionNumber);
367  if (!pTable)
368  {
369  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot load IMAGING_DATA");
370  *error = 1;
371  return;
372  }
373 
374  // Get data table information
375  for (i = 0; i < pTable->nc; i++)
376  {
377  if (strcmp (pTable->col[i].tlabel, "DATA1") == 0)
378  {
379  foundData = 1;
380  indexData = i;
381  }
382  }
383  if (foundData == 0)
384  {
385  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot find requested columns in data FITS file");
386  qfits_table_close (pTable);
387  *error = 1;
388  return;
389  }
390 
391  // Read column DATA
392  inData = (short int*) qfits_query_column (pTable, indexData, NULL);
393 
394  // Read Scaling Offset
395  dataName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
396  for (i = 14; i < 25; i++)
397  {
398  sprintf (dataName, "TZERO%d", i);
399  tempStr = qfits_query_ext (inFitsName, dataName, extensionNumber);
400  if (tempStr != NULL)
401  {
402  if (diagnostic)cpl_msg_info(cpl_func,"Scaling Offset = %s\n", tempStr);
403  if (diagnostic) fprintf (midiReportPtr, "Scaling Offset = %s\n", tempStr);
404  sscanf (tempStr, "%d", &scalingOffset);
405  break;
406  }
407  }
408  if (tempStr == NULL)
409  {
410  scalingOffset = 0;
411  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Scaling Offset. It is set to 0");
412  }
413  free (dataName);
414 
415  // Create averaged image for the whole file. This also allows a check on existence of a target
416  subWindowSize = format->iXWidth * format->iYWidth;
417  aveImage = (float *) calloc (subWindowSize, sizeof(float));
418  createAveragedImage (inData, scalingOffset, format, aveImage);
419 
420  // Create an image FITS file
421  title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
422  string = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
423  sprintf (title, "AveImg%d", fileNumber+1);
424  sprintf (string, "file %d", fileNumber+1);
425  createFitsImage (string, title, inFitsName, format->iXWidth, format->iYWidth, aveImage);
426 
427  // Create plot file
428  sprintf (string, "3dAveImg%d", fileNumber+1);
429  sprintf (title, "Averaged Image, Beam Combiner %s", format->beamCombiner);
430  if (plotFile) midiCreatePlotFile3D (string, title, "X", "Y", "Flux",
431  0, aveImage, format->iXWidth, format->iYWidth, "lines", "3");
432  free (string);
433  free (title);
434 
435  // Compute the centroid coordinates of targets in the given image
436  computeTargetCentroidsRefPix (fileNumber, format, aveImage, refPix, error);
437  if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot determine target centroid");
438 
439  // Release memory
440  qfits_table_close (pTable);
441  free (inData);
442  free (aveImage);
443 
444  return;
445 }
446 /*****************************************************************************/
447 
448 
449 
450 /******************************************************************************
451 * European Southern Observatory
452 * VLTI MIDI Maintenance Templates Software
453 *
454 * Module name: computeTargetCentroidsRefPix
455 * Input/Output: See function arguments to avoid duplication
456 * Description: Using a 2D Gaussian fit find the coordinates of the target in the given averaged
457 * image. The number of targets depend on the type of observation. For
458 * Interferometry (HIGH_SENS or OPEN) there are 2 groups of 3-pin-holes. The
459 * coordinates of the central pinhole for each group are always given.
460 * Additionally the size of a search window is also given. The targets are
461 * expected to be around the cetral pinholes. The result of the 2D Gaussian
462 * determines the accuracy of the beam positions. For Photometry (SCI_PHOT)
463 * there are 3 groups of 3-pin-holes. Hence three sets of coordinates are always
464 * given.
465 *
466 * History:
467 * 18-Aug-04 (csabet) Created
468 ******************************************************************************/
469 void computeTargetCentroidsRefPix (
470  int fileNumber, // In: File number
471  ImageFormat *format, // In: Pointer to the image format
472  float *image, // In: Pointer to the image data
473  ReferencePixel *refPix, // In: Pointer to ref pix structure
474  int *error) // Ou: Error status
475 {
476 
477  // Local Declarations
478  // ------------------
479  const char routine[] = "computeTargetCentroidsRefPix";
480  int dimension = 2, xPinhole, yPinhole, sizeSearch;
481  double xTarget, yTarget, sizeXTarget, sizeYTarget;
482 
483  // Algorithm
484  // ---------
485  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
486  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
487 
488  // Reset status
489  *error = 0;
490 
491  // Using a 2D Gaussian fit find the coordinates of the targets for each case
492  if ((strcmp (refPix->exposure[fileNumber].beamCombiner, "HIGH_SENS") == 0) ||
493  (strcmp (refPix->exposure[fileNumber].beamCombiner, "OPEN") == 0))
494  {
495  // Here we expect 2 beams for each case
496  if (strcmp (refPix->exposure[fileNumber].shutterId, "ABOPEN") == 0)
497  {
498  // Compute beam 1 coordinates
499  sizeSearch = SIZE_SEARCH_REF_PIX;
500  xPinhole = X1_REF_PIX_ABOPEN;
501  yPinhole = Y1_REF_PIX_ABOPEN;
502  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
503  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
504  if (*error)
505  {
506  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
507  return;
508  }
509  // Save output values
510  refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
511  refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
512  refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
513 
514  // Compute beam 2 coordinates
515  xPinhole = X2_REF_PIX_ABOPEN;
516  yPinhole = Y2_REF_PIX_ABOPEN;
517  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
518  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
519  if (*error)
520  {
521  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
522  return;
523  }
524  // Save output values
525  refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
526  refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
527  refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
528  }
529  else if (strcmp (refPix->exposure[fileNumber].shutterId, "AOPEN") == 0)
530  {
531  // Compute beam 1 coordinates
532  sizeSearch = SIZE_SEARCH_REF_PIX;
533  xPinhole = X1_REF_PIX_HS_AOPEN;
534  yPinhole = Y1_REF_PIX_HS_AOPEN;
535  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
536  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
537  if (*error)
538  {
539  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
540  return;
541  }
542  // Save output values
543  refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
544  refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
545  refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
546 
547  // Compute beam 2 coordinates
548  xPinhole = X2_REF_PIX_HS_AOPEN;
549  yPinhole = Y2_REF_PIX_HS_AOPEN;
550  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
551  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
552  if (*error)
553  {
554  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
555  return;
556  }
557  // Save output values
558  refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
559  refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
560  refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
561  }
562  else if (strcmp (refPix->exposure[fileNumber].shutterId, "BOPEN") == 0)
563  {
564  // Compute beam 1 coordinates
565  sizeSearch = SIZE_SEARCH_REF_PIX;
566  xPinhole = X1_REF_PIX_HS_BOPEN;
567  yPinhole = Y1_REF_PIX_HS_BOPEN;
568  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
569  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
570  if (*error)
571  {
572  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
573  return;
574  }
575  // Save output values
576  refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
577  refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
578  refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
579 
580  // Compute beam 2 coordinates
581  xPinhole = X2_REF_PIX_HS_BOPEN;
582  yPinhole = Y2_REF_PIX_HS_BOPEN;
583  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
584  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
585  if (*error)
586  {
587  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
588  return;
589  }
590  // Save output values
591  refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
592  refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
593  refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
594  }
595  else
596  {
597  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Unknown Shutter ID");
598  *error = 1;
599  return;
600  }
601  }
602  else if (strcmp (refPix->exposure[fileNumber].beamCombiner, "SCI_PHOT") == 0)
603  {
604  // Here we expect 3 beams for each case
605  if (strcmp (refPix->exposure[fileNumber].shutterId, "AOPEN") == 0)
606  {
607  sizeSearch = SIZE_SEARCH_REF_PIX;
608  xPinhole = X1_REF_PIX_SP_AOPEN;
609  yPinhole = Y1_REF_PIX_SP_AOPEN;
610  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
611  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
612  if (*error)
613  {
614  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
615  return;
616  }
617  // Save output values
618  refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
619  refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
620  refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
621 
622  xPinhole = X2_REF_PIX_SP_AOPEN;
623  yPinhole = Y2_REF_PIX_SP_AOPEN;
624  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
625  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
626  if (*error)
627  {
628  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
629  return;
630  }
631  // Save output values
632  refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
633  refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
634  refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
635 
636  xPinhole = X3_REF_PIX_SP_AOPEN;
637  yPinhole = Y3_REF_PIX_SP_AOPEN;
638  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
639  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
640  if (*error)
641  {
642  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
643  return;
644  }
645  // Save output values
646  refPix->exposure[fileNumber].centroid[2].xCoord = xTarget;
647  refPix->exposure[fileNumber].centroid[2].yCoord = yTarget;
648  refPix->exposure[fileNumber].centroid[2].size = 0.5 * (sizeXTarget + sizeYTarget);
649  }
650  else if (strcmp (refPix->exposure[fileNumber].shutterId, "BOPEN") == 0)
651  {
652  sizeSearch = SIZE_SEARCH_REF_PIX;
653  xPinhole = X1_REF_PIX_SP_BOPEN;
654  yPinhole = Y1_REF_PIX_SP_BOPEN;
655  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
656  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
657  if (*error)
658  {
659  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
660  return;
661  }
662  // Save output values
663  refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
664  refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
665  refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
666 
667  xPinhole = X2_REF_PIX_SP_BOPEN;
668  yPinhole = Y2_REF_PIX_SP_BOPEN;
669  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
670  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
671  if (*error)
672  {
673  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
674  return;
675  }
676  // Save output values
677  refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
678  refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
679  refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
680 
681  xPinhole = X3_REF_PIX_SP_BOPEN;
682  yPinhole = Y3_REF_PIX_SP_BOPEN;
683  midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole,
684  sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
685  if (*error)
686  {
687  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
688  return;
689  }
690  // Save output values
691  refPix->exposure[fileNumber].centroid[2].xCoord = xTarget;
692  refPix->exposure[fileNumber].centroid[2].yCoord = yTarget;
693  refPix->exposure[fileNumber].centroid[2].size = 0.5 * (sizeXTarget + sizeYTarget);
694  }
695  else
696  {
697  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Unknown Shutter ID");
698  *error = 1;
699  return;
700  }
701  }
702 
703  return;
704 }
705 //*****************************************************************************
706 
707 
708 
709 
710 /******************************************************************************
711 * European Southern Observatory
712 * VLTI MIDI Maintenance Templates Software
713 *
714 * Module name: evaluateBeamPosition
715 * Input/Output: See function arguments to avoid duplication
716 * Description: Determine the reference pixel values
717 *
718 * History:
719 * 23-Jun-04 (csabet) Created
720 ******************************************************************************/
721 void evaluateBeamPosition (void)
722 {
723 
724  /* Local Declarations
725  --------------------*/
726  const char routine[] = "evaluateBeamPosition";
727 
728  /* Algorithm
729  -----------*/
730  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
731  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
732 
733  midiReportTbd (midiReportPtr, routine, __FILE__, __LINE__, "Entire routine to be written");
734 
735  return;
736 }
737 /*****************************************************************************/
738