procRefPix.c

00001 
00002 /******************************************************************************
00003 *******************************************************************************
00004 *               European Southern Observatory
00005 *          VLTI MIDI Maintenance Templates Software
00006 *
00007 * Module name:  procRefPix.c
00008 * Description:  Contains routines for processing the templates
00009 *
00010 * History:      
00011 * 16-Jun-04     (csabet) created
00012 *******************************************************************************
00013 ******************************************************************************/
00014 
00015 /******************************************************************************
00016 *   Compiler directives
00017 ******************************************************************************/
00018 
00019 /******************************************************************************
00020 *   Include files
00021 ******************************************************************************/
00022 #include <math.h>
00023 #include <stdio.h>
00024 #include <cpl.h>
00025 #include "midiGlobal.h"
00026 #include "midiLib.h"
00027 #include "imageProcessing.h"
00028 #include "memoryHandling.h"
00029 #include "createProdRefPix.h"
00030 #include "procRefPix.h"
00031 #include "errorHandling.h"
00032 #include "midiFitsUtility.h"
00033 #include "fitsAnalysisTec.h"
00034 #include "diagnostics.h"
00035 #include "qfits.h"
00036 
00037 /**********************************************************
00038 *   Constant definitions
00039 **********************************************************/
00040 
00041 /**********************************************************
00042 *   Global Variables 
00043 **********************************************************/
00044 
00045 /*============================ C O D E    A R E A ===========================*/
00046 
00047 
00048 
00049 /******************************************************************************
00050 *               European Southern Observatory
00051 *          VLTI MIDI Maintenance Templates Software
00052 *
00053 * Module name:  procRefPix
00054 * Input/Output: See function arguments to avoid duplication
00055 * Description:  Evaluates the reference positions of the VLTI beams on the MIDI
00056 *                detector for the fine positioning of the target. This is the main 
00057 *                routine for this application.
00058 *
00059 * History:      
00060 * 03-May-05     (csabet) Created
00061 ******************************************************************************/
00062 void procRefPix (
00063     MidiFiles    *fileNames,    // In: Pointer to file names
00064     int            *error)        // Ou: Error status
00065 {
00066 
00067     //    Local Declarations
00068     //    ------------------
00069     const char      routine[] = "procRefPix";
00070     ImageFormat        *format=NULL;
00071     ReferencePixel     *refPix=NULL;
00072     int                numOfExposures, maxNumOfBeams;
00073     FILE            *signaturePtr=NULL;
00074     
00075     //    Algorithm
00076     //    ---------
00077     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00078     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00079 
00080     //    Write a signature
00081     signaturePtr = fopen ("MIDI_sig_pix.log", "w");
00082     fclose (signaturePtr);
00083 
00084     //    Reset status
00085     *error = 0;
00086     numOfExposures = 0;
00087     maxNumOfBeams = 0;
00088     
00089     //    Allocate memory
00090     format = callocImageFormat ();
00091     
00092     analyseFitsRefPix (fileNames, format, &numOfExposures, &maxNumOfBeams, error);
00093     if (*error)
00094     {
00095         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot analyse REFPIX");
00096         freeImageFormat (format);
00097         return;
00098     }
00099     
00100     refPix = callocRefPix (numOfExposures, maxNumOfBeams);
00101     computeRefPix (fileNames, refPix, error);
00102     if (*error)
00103     {
00104         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot process REFPIX");
00105         freeRefPix (refPix);
00106         freeImageFormat (format);
00107         return;
00108     }
00109     
00110     createRefPixProd (fileNames, format, refPix, error);
00111     if (*error)    midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create REFPIX products");
00112 
00113     //    Release memory
00114     freeRefPix (refPix);
00115     freeImageFormat (format);
00116 
00117     return; 
00118 }
00119 /*****************************************************************************/
00120 
00121 
00122 
00123 /******************************************************************************
00124 *               European Southern Observatory
00125 *          VLTI MIDI Maintenance Templates Software
00126 *
00127 * Module name:  computeRefPix
00128 * Input/Output: See function arguments to avoid duplication
00129 * Description:  Evaluates the reference positions of the VLTI beams on the MIDI
00130 *                detector for the fine positioning of the target. It also monitors
00131 *                and evaluates the stability of the beams inside the MIDI dewar
00132 *                For every frame of the beam compute the coordinates of the brightest
00133 *                pixel (x1, y1). This is found by a 2D gaussian fit or any suitable
00134 *                centroiding method. The output for beam 1 (I1) is N coordinates
00135 *                where N is the number of frames. Carry out the same for beam 2 (I2)
00136 *                and obtain a second set of coordinates. A number of correlation may be
00137 *                carried out to assess the quality of the output. If DATA1 and DATA2
00138 *                are combined into DATA1 then we need to know the sub-image coordinates.
00139 *
00140 * History:      
00141 * 11-Aug-04     (csabet) Created
00142 ******************************************************************************/
00143 void computeRefPix (
00144     MidiFiles        *fileNames,    // In: Pointer to the MIDI file structure
00145     ReferencePixel     *refPix,    // Ou: Pointer to the reference pixel data structure
00146     int                *error)        // Ou:    Error status
00147 {
00148   
00149     //    Local Declarations
00150     //    ------------------
00151     const char  routine[] = "computeRefPix";
00152     char                        *fileTemp, *classification;
00153     FILE                    *inFitsBatchPtr;
00154     ImageFormat             *format;
00155     int                     localError, fileNumber, extNumOfImagingDataFile;
00156     
00157     //    Algorithm
00158     //    ---------
00159     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00160     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00161 
00162     //    Allocate memory
00163     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00164     fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00165     format = callocImageFormat ();
00166 
00167     //    Reset status
00168     *error = 0;
00169     localError = 0;
00170     fileNumber = 0;
00171     refPix->exists = 0;
00172     format->hasData = 0;
00173     
00174     //    Open the list of files
00175     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00176     {
00177         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, 
00178             "Cannot open input FITS file list\n                 No data preprocessing has been carried out for this batch");
00179         freeImageFormat (format);
00180         free (fileTemp);
00181         free (classification);
00182         *error = 1;
00183         return;
00184     }
00185 
00186     //    Loop through the files and analyse
00187     while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
00188     {
00189         sprintf (classification, "%s", "");
00190         sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
00191         if (diagnostic)cpl_msg_info(cpl_func,"\n   Processing file   %s \n", fileNames->inFitsName);
00192         fprintf(midiReportPtr, "\n   Processing file   %s \n", fileNames->inFitsName);
00193 
00194         //    Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
00195         extNumOfImagingDataFile  = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, &localError);
00196         if (localError) 
00197         {
00198             *error = 1;
00199             break;
00200         }
00201 
00202         //    Get Image Format parameters
00203         if (extNumOfImagingDataFile > 0)
00204         {
00205             getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, format, &localError);
00206             if (localError) 
00207             {
00208                 *error = 1;
00209                 break;
00210             }
00211         }
00212         else format->hasData = 0;
00213 
00214         //    Check if the file has data
00215         if (format->hasData)
00216         {
00217             /*  Check Categ, Tech and Type and then compute the image size */
00218             if ((strcmp (format->obsCatg, "CALIB") == 0) &&
00219             (strcmp (format->obsTech, "IMAGE") == 0) &&
00220             (strcmp (format->obsType, "FMTCHCK") == 0))
00221             {
00222                 //    Save beam combiner and sutter ID
00223                 sprintf (refPix->exposure[fileNumber].shutterId, "%s", format->shutterId);
00224                 sprintf (refPix->exposure[fileNumber].beamCombiner, "%s", format->beamCombiner);
00225                 if ((strcmp (format->beamCombiner, "HIGH_SENS") == 0) || 
00226                     (strcmp (format->beamCombiner, "OPEN") == 0))
00227                     refPix->exposure[fileNumber].numOfBeams = 2;
00228                 else if (strcmp (format->beamCombiner, "SCI_PHOT") == 0) 
00229                     refPix->exposure[fileNumber].numOfBeams = 3;
00230 
00231                 if (diagnostic)cpl_msg_info(cpl_func,"   Beam combiner for file %d      = %s\n", fileNumber+1, 
00232                     refPix->exposure[fileNumber].beamCombiner);
00233                 if (diagnostic)cpl_msg_info(cpl_func,"   Shutter ID for file %d         = %s\n", fileNumber+1, 
00234                     refPix->exposure[fileNumber].shutterId);
00235                 if (diagnostic)cpl_msg_info(cpl_func,"   Number of beams for file %d    = %d\n", fileNumber+1, 
00236                     refPix->exposure[fileNumber].numOfBeams);
00237                 fprintf (midiReportPtr, "   Beam combiner for file %d      = %s\n", fileNumber+1, 
00238                     refPix->exposure[fileNumber].beamCombiner);
00239                 fprintf (midiReportPtr, "   Shutter ID for file %d         = %s\n", fileNumber+1, 
00240                     refPix->exposure[fileNumber].shutterId);
00241                 fprintf (midiReportPtr, "   Number of beams for file %d    = %d\n", fileNumber+1, 
00242                     refPix->exposure[fileNumber].numOfBeams);
00243 
00244                 //    Calculate Image Centroids
00245                 procCentroidsRefPix (fileNumber, fileNames->inFitsName, extNumOfImagingDataFile, 
00246                     format, refPix, &localError);
00247                 if (localError) *error = 1;
00248                         
00249                 //    Set the flags
00250                 refPix->exists = 1;
00251                 
00252                 //    Increment file number but make sure it is not greater than the allocated
00253                 fileNumber++;
00254                 if (fileNumber > refPix->numOfExposures)
00255                 {
00256                     *error = 1;
00257                     break;
00258                 }                
00259             }
00260             else
00261                 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, "The above file is not suitable for this task");
00262         }
00263         else
00264         {
00265             if (diagnostic)
00266             {
00267                 sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
00268                 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00269             }
00270         }
00271     }
00272 
00273     //    Check if processing has been carried out
00274     if ((refPix->exists) && !(*error) && (fileNumber == refPix->numOfExposures))
00275     {
00276        cpl_msg_info(cpl_func,"\nReference Pixel Position Inventry: \n");
00277        cpl_msg_info(cpl_func,"================================= \n");
00278        cpl_msg_info(cpl_func,"   Expected number of data files  = %d\n", refPix->numOfExposures);
00279        cpl_msg_info(cpl_func,"   Number of data files processed = %d\n", fileNumber);
00280        cpl_msg_info(cpl_func,"\n");
00281 
00282         fprintf (midiReportPtr, "\nReference Pixel Position Inventry: \n");
00283         fprintf (midiReportPtr, "================================= \n");
00284         fprintf (midiReportPtr, "   Expected number of data files  = %d\n", refPix->numOfExposures);
00285         fprintf (midiReportPtr, "   Number of data files processed = %d\n", fileNumber);
00286         fprintf (midiReportPtr, "\n");
00287 
00288         //    Beam analysis
00289         //    -------------
00290         evaluateBeamPosition ();
00291     }
00292 
00293     if (*error || localError)
00294         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create an Image Centroid Data for this batch");
00295 
00296     //    Close the file list
00297     fclose (inFitsBatchPtr);
00298     
00299     //    Release memory
00300     freeImageFormat (format);
00301     free (fileTemp);
00302     free (classification);    
00303     
00304     return; 
00305 }
00306 /*****************************************************************************/
00307 
00308 
00309 
00310 /******************************************************************************
00311 *               European Southern Observatory
00312 *          VLTI MIDI Maintenance Templates Software
00313 *
00314 * Module name:  procCentroidsRefPix
00315 * Input/Output: See function arguments to avoid duplication
00316 * Description:  Main routine for computing the averaged image and the coordinates of 
00317 *                the targets
00318 *                The structure of the centroid data is as follows:
00319 *                refPix->centrod[0]    beam 1 of OPEN        file 1    ABOPEN (Imaging)
00320 *                refPix->centrod[1]    beam 2 of OPEN        file 1    ABOPEN (Imaging)
00321 *                refPix->centrod[2]    beam 1 of HIGH_SENS    file 2    AOPEN
00322 *                refPix->centrod[3]    beam 2 of HIGH_SENS    file 2    AOPEN
00323 *                refPix->centrod[4]    beam 1 of HIGH_SENS    file 3    BOPEN
00324 *                refPix->centrod[5]    beam 2 of HIGH_SENS    file 3    BOPEN
00325 *                refPix->centrod[6]    beam 1 of SCI_PHOT    file 4    AOPEN
00326 *                refPix->centrod[7]    beam 2 of SCI_PHOT    file 4    AOPEN
00327 *                refPix->centrod[8]    beam 3 of SCI_PHOT    file 4    AOPEN
00328 *                refPix->centrod[9]    beam 1 of SCI_PHOT    file 5    BOPEN
00329 *                refPix->centrod[10]    beam 2 of SCI_PHOT    file 5    BOPEN
00330 *                refPix->centrod[11]    beam 3 of SCI_PHOT    file 5    BOPEN
00331 *
00332 *
00333 * History:      
00334 * 11-Aug-04     (csabet) Created
00335 * 28-Aug-06     (csabet) Modified
00336 ******************************************************************************/
00337 void procCentroidsRefPix ( 
00338     int                fileNumber,        //    In:    File number
00339     char            *inFitsName,    //  In: Name of file to process
00340     int             extensionNumber,//    In:    Extension number of the IMAGE_DATA
00341     ImageFormat     *format,        //    In:    Pointer to the image format
00342     ReferencePixel     *refPix,        //  Ou: Pointer to the reference pixel data structure
00343     int                *error)            //    Ou:    Error status
00344 
00345 {
00346   
00347     //  Local Declarations
00348     //    ------------------
00349     const char  routine[] = "procCentroidsRefPix";
00350     qfits_table *pTable  = NULL;
00351     short int   *inData;
00352     char        *tempStr, *string, *title, *dataName;
00353     int         i, foundData = 0, scalingOffset, indexData, subWindowSize;
00354     float        *aveImage;
00355 
00356 
00357     //  Algorithm
00358     //    ---------
00359     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00360     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00361     
00362     //    Reset status
00363     *error = 0;
00364     
00365     //  Open IMAGING_DATA = INDEX 2
00366     pTable = qfits_table_open (inFitsName, extensionNumber);
00367     if (!pTable)
00368     {
00369         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot load IMAGING_DATA");
00370         *error = 1;
00371         return;
00372     }
00373         
00374     //    Get data table information
00375     for (i = 0; i < pTable->nc; i++)
00376     {
00377         if (strcmp (pTable->col[i].tlabel, "DATA1") == 0)
00378         {
00379             foundData = 1;
00380             indexData = i;
00381         }
00382     }
00383     if (foundData == 0)
00384     {
00385         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot find requested columns in data FITS file");
00386         qfits_table_close (pTable);
00387         *error = 1;
00388         return;
00389     }
00390 
00391     //  Read column DATA
00392     inData = (short int*) qfits_query_column (pTable, indexData, NULL); 
00393 
00394     //    Read Scaling Offset
00395     dataName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00396     for (i = 14; i < 25; i++)
00397     {
00398         sprintf (dataName, "TZERO%d", i);
00399         tempStr = qfits_query_ext (inFitsName, dataName, extensionNumber);
00400         if (tempStr != NULL)
00401         {
00402             if (diagnostic)cpl_msg_info(cpl_func,"Scaling Offset = %s\n", tempStr);
00403             if (diagnostic) fprintf (midiReportPtr, "Scaling Offset = %s\n", tempStr);
00404             sscanf (tempStr, "%d", &scalingOffset);
00405             break;
00406         }
00407     }
00408     if (tempStr == NULL)
00409     {
00410         scalingOffset = 0;
00411         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Scaling Offset. It is set to 0");
00412     }
00413     free (dataName);
00414     
00415     //    Create averaged image for the whole file. This also allows a check on existence of a target
00416     subWindowSize = format->iXWidth * format->iYWidth;
00417     aveImage = (float *) calloc (subWindowSize, sizeof(float));
00418     createAveragedImage (inData, scalingOffset,    format, aveImage);
00419     
00420     //    Create an image FITS file
00421     title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00422     string = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00423     sprintf (title, "AveImg%d", fileNumber+1);
00424     sprintf (string, "file %d", fileNumber+1);
00425     createFitsImage (string, title, inFitsName, format->iXWidth, format->iYWidth, aveImage);
00426     
00427     //    Create plot file
00428     sprintf (string, "3dAveImg%d", fileNumber+1);
00429     sprintf (title, "Averaged Image, Beam Combiner %s", format->beamCombiner);
00430     if (plotFile) midiCreatePlotFile3D (string, title, "X", "Y", "Flux", 
00431         0, aveImage, format->iXWidth, format->iYWidth, "lines", "3");
00432     free (string);
00433     free (title);
00434     
00435     //    Compute the centroid coordinates of targets in the given image 
00436     computeTargetCentroidsRefPix (fileNumber, format, aveImage, refPix, error);
00437     if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot determine target centroid");
00438     
00439     //    Release memory
00440     qfits_table_close (pTable);
00441     free (inData);
00442     free (aveImage);
00443 
00444     return; 
00445 }
00446 /*****************************************************************************/
00447 
00448 
00449 
00450 /******************************************************************************
00451 *               European Southern Observatory
00452 *          VLTI MIDI Maintenance Templates Software
00453 *
00454 * Module name:  computeTargetCentroidsRefPix
00455 * Input/Output: See function arguments to avoid duplication
00456 * Description:     Using a 2D Gaussian fit find the coordinates of the target in the given averaged 
00457 *                image. The number of targets depend on the type of observation. For 
00458 *                Interferometry (HIGH_SENS or OPEN) there are 2 groups of 3-pin-holes. The 
00459 *                coordinates of the central pinhole for each group are always given. 
00460 *                Additionally the size of a search window is also given. The targets are
00461 *                expected to be around the cetral pinholes. The result of the 2D Gaussian 
00462 *                determines the accuracy of the beam positions. For Photometry (SCI_PHOT) 
00463 *                there are 3 groups of 3-pin-holes. Hence three sets of coordinates are always
00464 *                given.
00465 *
00466 * History:      
00467 * 18-Aug-04     (csabet) Created
00468 ******************************************************************************/
00469 void computeTargetCentroidsRefPix (
00470     int                fileNumber,    //    In:    File number
00471     ImageFormat     *format,    //    In:    Pointer to the image format
00472     float             *image,        //  In: Pointer to the image data
00473     ReferencePixel     *refPix,    //    In:    Pointer to ref pix structure                        
00474     int                *error)        //    Ou:    Error status
00475 {
00476   
00477     //  Local Declarations
00478     //    ------------------
00479     const char  routine[] = "computeTargetCentroidsRefPix";
00480     int            dimension = 2, xPinhole, yPinhole, sizeSearch;
00481     double        xTarget, yTarget, sizeXTarget, sizeYTarget;
00482     
00483     //  Algorithm
00484     //    ---------
00485     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00486     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00487 
00488     //    Reset status
00489     *error = 0;
00490 
00491     //    Using a 2D Gaussian fit find the coordinates of the targets for each case
00492     if ((strcmp (refPix->exposure[fileNumber].beamCombiner, "HIGH_SENS") == 0) || 
00493         (strcmp (refPix->exposure[fileNumber].beamCombiner, "OPEN") == 0))
00494     {
00495         //    Here we expect 2 beams for each case
00496         if (strcmp (refPix->exposure[fileNumber].shutterId, "ABOPEN") == 0)
00497         {
00498             //    Compute beam 1 coordinates
00499             sizeSearch = SIZE_SEARCH_REF_PIX;
00500             xPinhole = X1_REF_PIX_ABOPEN;
00501             yPinhole = Y1_REF_PIX_ABOPEN;
00502             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00503                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00504             if (*error) 
00505             {
00506                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00507                 return;
00508             }
00509             //    Save output values
00510             refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
00511             refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
00512             refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
00513 
00514             //    Compute beam 2 coordinates
00515             xPinhole = X2_REF_PIX_ABOPEN;
00516             yPinhole = Y2_REF_PIX_ABOPEN;
00517             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00518                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00519             if (*error) 
00520             {
00521                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00522                 return;
00523             }
00524             //    Save output values
00525             refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
00526             refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
00527             refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
00528         }
00529         else if (strcmp (refPix->exposure[fileNumber].shutterId, "AOPEN") == 0)
00530         {
00531             //    Compute beam 1 coordinates
00532             sizeSearch = SIZE_SEARCH_REF_PIX;
00533             xPinhole = X1_REF_PIX_HS_AOPEN;
00534             yPinhole = Y1_REF_PIX_HS_AOPEN;
00535             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00536                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00537             if (*error) 
00538             {
00539                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00540                 return;
00541             }
00542             //    Save output values
00543             refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
00544             refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
00545             refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
00546 
00547             //    Compute beam 2 coordinates
00548             xPinhole = X2_REF_PIX_HS_AOPEN;
00549             yPinhole = Y2_REF_PIX_HS_AOPEN;
00550             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00551                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00552             if (*error) 
00553             {
00554                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00555                 return;
00556             }
00557             //    Save output values
00558             refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
00559             refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
00560             refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
00561         }
00562         else if (strcmp (refPix->exposure[fileNumber].shutterId, "BOPEN") == 0)
00563         {
00564             //    Compute beam 1 coordinates
00565             sizeSearch = SIZE_SEARCH_REF_PIX;
00566             xPinhole = X1_REF_PIX_HS_BOPEN;
00567             yPinhole = Y1_REF_PIX_HS_BOPEN;
00568             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00569                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00570             if (*error) 
00571             {
00572                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00573                 return;
00574             }
00575             //    Save output values
00576             refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
00577             refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
00578             refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
00579 
00580             //    Compute beam 2 coordinates
00581             xPinhole = X2_REF_PIX_HS_BOPEN;
00582             yPinhole = Y2_REF_PIX_HS_BOPEN;
00583             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00584                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00585             if (*error) 
00586             {
00587                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00588                 return;
00589             }
00590             //    Save output values
00591             refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
00592             refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
00593             refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
00594         }
00595         else
00596         {
00597             midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Unknown Shutter ID");
00598             *error = 1;
00599             return;
00600         }
00601     }
00602     else if (strcmp (refPix->exposure[fileNumber].beamCombiner, "SCI_PHOT") == 0)
00603     {
00604         //    Here we expect 3 beams for each case
00605         if (strcmp (refPix->exposure[fileNumber].shutterId, "AOPEN") == 0)
00606         {
00607             sizeSearch = SIZE_SEARCH_REF_PIX;
00608             xPinhole = X1_REF_PIX_SP_AOPEN;
00609             yPinhole = Y1_REF_PIX_SP_AOPEN;
00610             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00611                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00612             if (*error) 
00613             {
00614                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00615                 return;
00616             }
00617             //    Save output values
00618             refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
00619             refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
00620             refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
00621             
00622             xPinhole = X2_REF_PIX_SP_AOPEN;
00623             yPinhole = Y2_REF_PIX_SP_AOPEN;
00624             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00625                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00626             if (*error) 
00627             {
00628                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00629                 return;
00630             }
00631             //    Save output values
00632             refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
00633             refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
00634             refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
00635             
00636             xPinhole = X3_REF_PIX_SP_AOPEN;
00637             yPinhole = Y3_REF_PIX_SP_AOPEN;
00638             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00639                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00640             if (*error) 
00641             {
00642                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00643                 return;
00644             }
00645             //    Save output values
00646             refPix->exposure[fileNumber].centroid[2].xCoord = xTarget;
00647             refPix->exposure[fileNumber].centroid[2].yCoord = yTarget;
00648             refPix->exposure[fileNumber].centroid[2].size = 0.5 * (sizeXTarget + sizeYTarget);
00649         }
00650         else if (strcmp (refPix->exposure[fileNumber].shutterId, "BOPEN") == 0)
00651         {
00652             sizeSearch = SIZE_SEARCH_REF_PIX;
00653             xPinhole = X1_REF_PIX_SP_BOPEN;
00654             yPinhole = Y1_REF_PIX_SP_BOPEN;
00655             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00656                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00657             if (*error) 
00658             {
00659                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00660                 return;
00661             }
00662             //    Save output values
00663             refPix->exposure[fileNumber].centroid[0].xCoord = xTarget;
00664             refPix->exposure[fileNumber].centroid[0].yCoord = yTarget;
00665             refPix->exposure[fileNumber].centroid[0].size = 0.5 * (sizeXTarget + sizeYTarget);
00666             
00667             xPinhole = X2_REF_PIX_SP_BOPEN;
00668             yPinhole = Y2_REF_PIX_SP_BOPEN;
00669             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00670                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00671             if (*error) 
00672             {
00673                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00674                 return;
00675             }
00676             //    Save output values
00677             refPix->exposure[fileNumber].centroid[1].xCoord = xTarget;
00678             refPix->exposure[fileNumber].centroid[1].yCoord = yTarget;
00679             refPix->exposure[fileNumber].centroid[1].size = 0.5 * (sizeXTarget + sizeYTarget);
00680             
00681             xPinhole = X3_REF_PIX_SP_BOPEN;
00682             yPinhole = Y3_REF_PIX_SP_BOPEN;
00683             midiGaussianFit (fileNumber, dimension, image, format->iXWidth, format->iYWidth, xPinhole, yPinhole, 
00684                 sizeSearch, &xTarget, &yTarget, &sizeXTarget, &sizeYTarget, error);
00685             if (*error) 
00686             {
00687                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot perform a Gaussian fit");
00688                 return;
00689             }
00690             //    Save output values
00691             refPix->exposure[fileNumber].centroid[2].xCoord = xTarget;
00692             refPix->exposure[fileNumber].centroid[2].yCoord = yTarget;
00693             refPix->exposure[fileNumber].centroid[2].size = 0.5 * (sizeXTarget + sizeYTarget);
00694         }
00695         else
00696         {
00697             midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Unknown Shutter ID");
00698             *error = 1;
00699             return;
00700         }
00701     }
00702     
00703     return; 
00704 }
00705 //*****************************************************************************
00706 
00707 
00708 
00709 
00710 /******************************************************************************
00711 *               European Southern Observatory
00712 *          VLTI MIDI Maintenance Templates Software
00713 *
00714 * Module name:  evaluateBeamPosition
00715 * Input/Output: See function arguments to avoid duplication
00716 * Description:  Determine the reference pixel values
00717 *
00718 * History:      
00719 * 23-Jun-04     (csabet) Created
00720 ******************************************************************************/
00721 void evaluateBeamPosition (void)
00722 {
00723   
00724     /*  Local Declarations
00725     --------------------*/
00726     const char  routine[] = "evaluateBeamPosition";
00727     
00728     /*  Algorithm
00729     -----------*/
00730     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00731     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00732 
00733     midiReportTbd (midiReportPtr, routine, __FILE__, __LINE__, "Entire routine to be written");
00734 
00735     return; 
00736 }
00737 /*****************************************************************************/
00738 

Generated on 15 Mar 2012 for MIDI Pipeline Reference Manual by  doxygen 1.6.1