fitsAnalysisTec.c

00001 
00002 /******************************************************************************
00003 *******************************************************************************
00004 *               European Southern Observatory
00005 *          VLTI MIDI Maintenance Templates Software
00006 *
00007 * Module name:  fitsAnalysisTec.c
00008 * Description:  Contains all routines for FITS format analysis
00009 *
00010 * History:      
00011 * 14-Jun-02     (csabet) created
00012 *******************************************************************************
00013 ******************************************************************************/
00014 
00015 /******************************************************************************
00016 *   Compiler directives
00017 ******************************************************************************/
00018 
00019 /******************************************************************************
00020 *   Include files
00021 ******************************************************************************/
00022 #include <stdio.h>
00023 #include <cpl.h>
00024 #include "midiGlobal.h"
00025 #include "midiLib.h"
00026 #include "fft.h"
00027 #include "errorHandling.h"
00028 #include "memoryHandling.h"
00029 #include "midiFitsUtility.h"
00030 #include "fitsAnalysisTec.h"
00031 
00032 /**********************************************************
00033 *   Global Variables 
00034 **********************************************************/
00035 
00036 
00037 
00038 /*============================ C O D E    A R E A ===========================*/
00039 
00040 
00041 /******************************************************************************
00042 *               European Southern Observatory
00043 *          VLTI MIDI Maintenance Templates Software
00044 *
00045 * Module name:  analyseFitsDetLin
00046 * Input/Output: See function arguments to avoid duplication
00047 * Description:  Analyses all the FITS files in the given list. This routine
00048 *                determines if the FITS list contains useful data files. If
00049 *                not it will discard the list.
00050 *
00051 * History:      
00052 * 14-Jun-04     (csabet) created
00053 ******************************************************************************/
00054 void analyseFitsDetLin (
00055     MidiFiles   *fileNames,        /*  IO: Pointer to midi files structure */
00056     ImageFormat *format,        /*  Ou: Pointer to the image format structure */
00057     int            *numOfFiles,    /*    Ou: Number of files with data */
00058     int            *error)            /*    Ou:    Error status */
00059 {
00060 
00061     //    Local Declarations
00062     //    ------------------
00063     const char              routine[] = "analyseFitsDetLin";
00064     char                        *fileTemp=NULL, *classification=NULL;
00065     FILE                    *inFitsBatchPtr=NULL;
00066     ImageFormat             *localFormat=NULL;
00067     int                     extNumOfImagingDataFile;
00068         
00069     //    Algorithm
00070     //    ---------
00071     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00072     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00073 
00074    cpl_msg_info(cpl_func,"\nAnalysing batch  %d  for Detector Linearity \n", batchNumber);
00075    cpl_msg_info(cpl_func,"--------------- \n");
00076     fprintf (midiReportPtr, "\nAnalysing batch  %d  for Detector Linearity \n", batchNumber);
00077     fprintf (midiReportPtr, "--------------- \n");
00078 
00079     //    Reset status
00080     *error = 0;
00081     *numOfFiles = 0;
00082     
00083     //    Allocate memory for a temporary file name buffer
00084     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00085     fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00086     localFormat = callocImageFormat ();
00087     
00088     //    Open the list of files
00089     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00090     {
00091         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
00092         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
00093         free (fileTemp);
00094         freeImageFormat (localFormat);
00095         free (classification);
00096         *error = 1;
00097         return;
00098     }
00099 
00100     //    Reset image format
00101     format->numOfScans = 0;
00102     format->numOfFrames = 0;
00103     format->subWindowSize = 0;
00104     format->framesPerScan = 0;
00105     format->iXWidth = 0;
00106     format->iYWidth = 0;
00107     
00108     //    Loop through the files and analyse
00109     while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
00110     {
00111         sprintf (classification, "%s", "");
00112         sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
00113         if (diagnostic)cpl_msg_info(cpl_func,"\n   Analysing file   %s \n", fileNames->inFitsName);
00114         fprintf(midiReportPtr, "\n   Analysing file   %s \n", fileNames->inFitsName);
00115 
00116         //    Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
00117         extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
00118         if (*error) break;
00119 
00120         //    Get Image Format parameters
00121         if (extNumOfImagingDataFile > 0)
00122         {
00123             getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
00124             if (*error) break;
00125         }
00126         else localFormat->hasData = 0;
00127 
00128         //    Check if the file has data
00129         if (localFormat->hasData)
00130         {
00131             if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
00132                 ((strcmp (localFormat->obsTech, "IMAGE") == 0) || 
00133                 (strcmp (localFormat->obsTech, "SPECTRUM") == 0)) &&
00134                 (strcmp (localFormat->obsType, "FLAT") == 0))
00135             {
00136                 //    Increment file counter
00137                 (*numOfFiles)++;
00138 
00139                 //    Log results
00140                cpl_msg_info(cpl_func,"File number           = %d \n", *numOfFiles);
00141                cpl_msg_info(cpl_func,"Observation Category  = %s \n", localFormat->obsCatg);
00142                cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
00143                cpl_msg_info(cpl_func,"Observation Type      = %s \n", localFormat->obsType);
00144                cpl_msg_info(cpl_func,"Beam Combiner         = %s \n", localFormat->beamCombiner);
00145                cpl_msg_info(cpl_func,"Shutter ID            = %s \n", localFormat->shutterId);
00146                cpl_msg_info(cpl_func,"Filter Name           = %s \n", localFormat->filterName);
00147                cpl_msg_info(cpl_func,"Grism ID              = %s \n", localFormat->grismId);
00148                cpl_msg_info(cpl_func,"Target Name           = %s \n", localFormat->targetName);
00149                cpl_msg_info(cpl_func,"Number of Frames      = %d \n", localFormat->numOfFrames);
00150                cpl_msg_info(cpl_func,"X, Column dimension   = %d \n", localFormat->iXWidth);
00151                cpl_msg_info(cpl_func,"Y, Column dimension   = %d \n", localFormat->iYWidth);
00152                cpl_msg_info(cpl_func,"Sub-window size       = %d \n", localFormat->subWindowSize);
00153                cpl_msg_info(cpl_func,"\n");
00154 
00155                 fprintf (midiReportPtr, "File number           = %d \n", *numOfFiles);
00156                 fprintf (midiReportPtr, "Observation Category  = %s \n", localFormat->obsCatg);
00157                 fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
00158                 fprintf (midiReportPtr, "Observation Type      = %s \n", localFormat->obsType);
00159                 fprintf (midiReportPtr, "Beam Combiner         = %s \n", localFormat->beamCombiner);
00160                 fprintf (midiReportPtr, "Shutter ID            = %s \n", localFormat->shutterId);
00161                 fprintf (midiReportPtr, "Filter Name           = %s \n", localFormat->filterName);
00162                 fprintf (midiReportPtr, "Grism ID              = %s \n", localFormat->grismId);
00163                 fprintf (midiReportPtr, "Target Name           = %s \n", localFormat->targetName);
00164                 fprintf (midiReportPtr, "Number of Frames      = %d \n", localFormat->numOfFrames);
00165                 fprintf (midiReportPtr, "X, Column dimension   = %d \n", localFormat->iXWidth);
00166                 fprintf (midiReportPtr, "Y, Column dimension   = %d \n", localFormat->iYWidth);
00167                 fprintf (midiReportPtr, "Sub-window size       = %d \n", localFormat->subWindowSize);
00168                 fprintf (midiReportPtr, "\n");
00169                  
00170                 //    Compute maximum image format.  Save local parameters
00171                 format->hasData = 1;
00172                 if (*numOfFiles == 1)
00173                 {
00174                     sprintf (format->obsCatg, "%s", localFormat->obsCatg);
00175                     sprintf (format->obsType, "%s", localFormat->obsType);
00176                     sprintf (format->obsTech, "%s", localFormat->obsTech);
00177                     sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
00178                     sprintf (format->shutterId, "%s", localFormat->shutterId);
00179                     sprintf (format->grismId, "%s", localFormat->grismId);
00180                     sprintf (format->targetName, "%s", localFormat->targetName);
00181                     sprintf (format->tplStart, "%s", localFormat->tplStart);
00182                     sprintf (format->cameraId, "%s", localFormat->cameraId);
00183                     sprintf (format->filterName, "%s", localFormat->filterName);
00184                 }
00185 
00186                 //    Save and cummulate size
00187                 format->numOfFrames = localFormat->numOfFrames;
00188                 format->subWindowSize = localFormat->subWindowSize;
00189                 format->framesPerScan = localFormat->framesPerScan;
00190                 format->iXWidth = localFormat->iXWidth;
00191                 format->iYWidth = localFormat->iYWidth;
00192             }
00193             else
00194             {
00195                 sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
00196                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00197             }
00198         }
00199         else
00200         {
00201             if (diagnostic)
00202             {
00203                 sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
00204                 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00205             }
00206         }
00207     }
00208 
00209 
00210     //    Close the file list
00211     fclose (inFitsBatchPtr);
00212     
00213     //    Check if the FITS files contained useful data
00214     if ((*numOfFiles > 0) && !(*error))
00215     {
00216        cpl_msg_info(cpl_func,"   Maximum image size \n");
00217        cpl_msg_info(cpl_func,"   ------------------ \n");
00218        cpl_msg_info(cpl_func,"   Number of Frames      = %d \n", format->numOfFrames);
00219        cpl_msg_info(cpl_func,"   X, column dimension   = %d \n", format->iXWidth);
00220        cpl_msg_info(cpl_func,"   Y, column dimension   = %d \n", format->iYWidth);
00221        cpl_msg_info(cpl_func,"   Sub-window size       = %d \n", format->subWindowSize);
00222        cpl_msg_info(cpl_func,"   Number of Data Files  = %d \n", *numOfFiles);
00223        cpl_msg_info(cpl_func,"\n");
00224                 
00225         fprintf (midiReportPtr, "   Maximum image size \n");
00226         fprintf (midiReportPtr, "   ------------------ \n");
00227         fprintf (midiReportPtr, "   Number of Frames      = %d \n", format->numOfFrames);
00228         fprintf (midiReportPtr, "   X, column dimension   = %d \n", format->iXWidth);
00229         fprintf (midiReportPtr, "   Y, column dimension   = %d \n", format->iYWidth);
00230         fprintf (midiReportPtr, "   Sub-window size       = %d \n", format->subWindowSize);
00231         fprintf (midiReportPtr, "   Number of Data Files  = %d \n", *numOfFiles);
00232         fprintf (midiReportPtr, "\n");
00233     }
00234     else
00235     {
00236         *error = 1;
00237         sprintf (fileTemp, "%d", batchNumber);
00238         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
00239     }
00240 
00241     //    Release memory
00242     free (fileTemp);
00243     freeImageFormat (localFormat);
00244     free (classification);
00245      
00246     return;
00247 }
00248 /******************************************************************************/
00249 
00250 
00251  
00252 
00253 /******************************************************************************
00254 *               European Southern Observatory
00255 *          VLTI MIDI Maintenance Templates Software
00256 *
00257 * Module name:  analyseFitDetRon
00258 * Input/Output: See function arguments to avoid duplication
00259 * Description:  Analyses all the FITS files in the given list. This routine
00260 *                determines if the FITS list contains useful data files. If
00261 *                not it will discard the list.
00262 *
00263 * History:      
00264 * 14-Jun-04     (csabet) created
00265 ******************************************************************************/
00266 void analyseFitsDetRon (
00267     MidiFiles   *fileNames,        /*  IO: Pointer to midi files structure */
00268     ImageFormat *format,        /*  Ou: Pointer to the image format structure */
00269     int            *numOfFiles,    /*    Ou: Number of files with data */
00270     int            *error)            /*    Ou:    Error status */
00271 {
00272 
00273     //    Local Declarations
00274     //    ------------------
00275     const char              routine[] = "analyseFitDetRon";
00276     char                        *fileTemp=NULL, *classification=NULL;
00277     FILE                    *inFitsBatchPtr=NULL;
00278     ImageFormat             *localFormat=NULL;
00279     int                     extNumOfImagingDataFile;
00280         
00281     //    Algorithm
00282     //    ---------
00283     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00284     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00285 
00286    cpl_msg_info(cpl_func,"\nAnalysing batch  %d  for Detector Readout Noise \n", batchNumber);
00287    cpl_msg_info(cpl_func,"--------------- \n");
00288     fprintf (midiReportPtr, "\nAnalysing batch  %d  for Detector Readout Noise \n", batchNumber);
00289     fprintf (midiReportPtr, "--------------- \n");
00290 
00291     //    Reset status
00292     *error = 0;
00293     *numOfFiles = 0;
00294     
00295     //    Allocate memory for a temporary file name buffer
00296     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00297     fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00298     localFormat = callocImageFormat ();
00299     
00300     //    Open the list of files
00301     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00302     {
00303         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
00304         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
00305         free (fileTemp);
00306         freeImageFormat (localFormat);
00307         free (classification);
00308         *error = 1;
00309         return;
00310     }
00311 
00312     //    Reset image format
00313     format->numOfScans = 0;
00314     format->numOfFrames = 0;
00315     format->subWindowSize = 0;
00316     format->framesPerScan = 0;
00317     format->iXWidth = 0;
00318     format->iYWidth = 0;
00319     
00320     //    Loop through the files and analyse
00321     while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
00322     {
00323         sprintf (classification, "%s", "");
00324         sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
00325         if (diagnostic)cpl_msg_info(cpl_func,"\n   Analysing file   %s \n", fileNames->inFitsName);
00326         fprintf(midiReportPtr, "\n   Analysing file   %s \n", fileNames->inFitsName);
00327 
00328         //    Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
00329         extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
00330         if (*error) break;
00331 
00332         //    Get Image Format parameters
00333         if (extNumOfImagingDataFile > 0)
00334         {
00335             getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
00336             if (*error) break;
00337         }
00338         else localFormat->hasData = 0;
00339 
00340         //    Check if the file has data
00341         if (localFormat->hasData)
00342         {
00343             if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
00344                 (strcmp (localFormat->obsTech, "IMAGE") == 0) &&
00345                 (strcmp (localFormat->obsType, "BIAS") == 0))
00346             {
00347                 //    Increment file counter
00348                 (*numOfFiles)++;
00349 
00350                 //    Log results
00351                cpl_msg_info(cpl_func,"File number           = %d \n", *numOfFiles);
00352                cpl_msg_info(cpl_func,"Observation Category  = %s \n", localFormat->obsCatg);
00353                cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
00354                cpl_msg_info(cpl_func,"Observation Type      = %s \n", localFormat->obsType);
00355                cpl_msg_info(cpl_func,"Beam Combiner         = %s \n", localFormat->beamCombiner);
00356                cpl_msg_info(cpl_func,"Shutter ID            = %s \n", localFormat->shutterId);
00357                cpl_msg_info(cpl_func,"Grism ID              = %s \n", localFormat->grismId);
00358                cpl_msg_info(cpl_func,"Filter Name           = %s \n", localFormat->filterName);
00359                cpl_msg_info(cpl_func,"Target Name           = %s \n", localFormat->targetName);
00360                cpl_msg_info(cpl_func,"Number of Frames      = %d \n", localFormat->numOfFrames);
00361                cpl_msg_info(cpl_func,"Frames per scan       = %d \n", localFormat->framesPerScan);
00362                cpl_msg_info(cpl_func,"Number of Scans       = %d \n", localFormat->numOfScans);
00363                cpl_msg_info(cpl_func,"X, Column dimension   = %d \n", localFormat->iXWidth);
00364                cpl_msg_info(cpl_func,"Y, Column dimension   = %d \n", localFormat->iYWidth);
00365                cpl_msg_info(cpl_func,"Sub-window size       = %d \n", localFormat->subWindowSize);
00366                cpl_msg_info(cpl_func,"\n");
00367 
00368                 fprintf (midiReportPtr, "File number           = %d \n", *numOfFiles);
00369                 fprintf (midiReportPtr, "Observation Category  = %s \n", localFormat->obsCatg);
00370                 fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
00371                 fprintf (midiReportPtr, "Observation Type      = %s \n", localFormat->obsType);
00372                 fprintf (midiReportPtr, "Beam Combiner         = %s \n", localFormat->beamCombiner);
00373                 fprintf (midiReportPtr, "Shutter ID            = %s \n", localFormat->shutterId);
00374                 fprintf (midiReportPtr, "Grism ID              = %s \n", localFormat->grismId);
00375                 fprintf (midiReportPtr, "Filter Name           = %s \n", localFormat->filterName);
00376                 fprintf (midiReportPtr, "Target Name           = %s \n", localFormat->targetName);
00377                 fprintf (midiReportPtr, "Number of Frames      = %d \n", localFormat->numOfFrames);
00378                 fprintf (midiReportPtr, "Frames per scan       = %d \n", localFormat->framesPerScan);
00379                 fprintf (midiReportPtr, "Number of Scans       = %d \n", localFormat->numOfScans);
00380                 fprintf (midiReportPtr, "X, Column dimension   = %d \n", localFormat->iXWidth);
00381                 fprintf (midiReportPtr, "Y, Column dimension   = %d \n", localFormat->iYWidth);
00382                 fprintf (midiReportPtr, "Sub-window size       = %d \n", localFormat->subWindowSize);
00383                 fprintf (midiReportPtr, "\n");
00384                  
00385                 //    Compute maximum image format. Save local parameters
00386                 format->hasData = 1;
00387                 if (*numOfFiles == 1)
00388                 {
00389                     sprintf (format->obsCatg, "%s", localFormat->obsCatg);
00390                     sprintf (format->obsType, "%s", localFormat->obsType);
00391                     sprintf (format->obsTech, "%s", localFormat->obsTech);
00392                     sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
00393                     sprintf (format->shutterId, "%s", localFormat->shutterId);
00394                     sprintf (format->grismId, "%s", localFormat->grismId);
00395                     sprintf (format->targetName, "%s", localFormat->targetName);
00396                     sprintf (format->tplStart, "%s", localFormat->tplStart);
00397                     sprintf (format->cameraId, "%s", localFormat->cameraId);
00398                     sprintf (format->filterName, "%s", localFormat->filterName);
00399                 }
00400 
00401                 //    Save and cummulate size
00402                 format->numOfFrames += localFormat->numOfFrames;
00403                 format->subWindowSize = localFormat->subWindowSize;
00404                 format->iXWidth = localFormat->iXWidth;
00405                 format->iYWidth = localFormat->iYWidth;
00406             }
00407             else
00408             {
00409                 sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
00410                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00411             }
00412         }
00413         else
00414         {
00415             if (diagnostic)
00416             {
00417                 sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
00418                 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00419             }
00420         }
00421     }
00422     
00423     //    Check if the FITS files contained useful data
00424     if ((*numOfFiles > 0) && !(*error))
00425     {
00426        cpl_msg_info(cpl_func,"   Maximum image size \n");
00427        cpl_msg_info(cpl_func,"   ------------------ \n");
00428        cpl_msg_info(cpl_func,"   Number of Frames      = %d \n", format->numOfFrames);
00429        cpl_msg_info(cpl_func,"   X, column dimension   = %d \n", format->iXWidth);
00430        cpl_msg_info(cpl_func,"   Y, column dimension   = %d \n", format->iYWidth);
00431        cpl_msg_info(cpl_func,"   Sub-window size       = %d \n", format->subWindowSize);
00432        cpl_msg_info(cpl_func,"   Number of Data Files  = %d \n", *numOfFiles);
00433        cpl_msg_info(cpl_func,"\n");
00434                 
00435         fprintf (midiReportPtr, "   Maximum image size \n");
00436         fprintf (midiReportPtr, "   ------------------ \n");
00437         fprintf (midiReportPtr, "   Number of Frames      = %d \n", format->numOfFrames);
00438         fprintf (midiReportPtr, "   X, column dimension   = %d \n", format->iXWidth);
00439         fprintf (midiReportPtr, "   Y, column dimension   = %d \n", format->iYWidth);
00440         fprintf (midiReportPtr, "   Sub-window size       = %d \n", format->subWindowSize);
00441         fprintf (midiReportPtr, "   Number of Data Files  = %d \n", *numOfFiles);
00442         fprintf (midiReportPtr, "\n");
00443     }
00444     else
00445     {
00446         *error = 1;
00447         sprintf (fileTemp, "%d", batchNumber);
00448         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
00449     }
00450 
00451     //    Release memory and close files
00452     fclose (inFitsBatchPtr);
00453     free (fileTemp);
00454     freeImageFormat (localFormat);
00455     free (classification);
00456      
00457     return;
00458 }
00459 /******************************************************************************/
00460 
00461 
00462 
00463 
00464 /******************************************************************************
00465 *               European Southern Observatory
00466 *          VLTI MIDI Maintenance Templates Software
00467 *
00468 * Module name:  analyseFitsDspTrn
00469 * Input/Output: See function arguments to avoid duplication
00470 * Description:  Analyses all the FITS files in the given list. This routine
00471 *                determines if the FITS list contains useful data files. If
00472 *                not it will discard the list.
00473 *
00474 * History:      
00475 * 14-Jun-04     (csabet) created
00476 ******************************************************************************/
00477 void analyseFitsDspTrn (
00478     MidiFiles   *fileNames,        /*  IO: Pointer to midi files structure */
00479     ImageFormat *format,        /*  Ou: Pointer to the image format structure */
00480     int            *numOfFiles,    /*    Ou: Number of files with data */
00481     int            *error)            /*    Ou:    Error status */
00482 {
00483 
00484     //    Local Declarations
00485     //    ------------------
00486     const char              routine[] = "analyseFitsDspTrn";
00487     char                        *fileTemp=NULL, *classification=NULL;
00488     FILE                    *inFitsBatchPtr=NULL;
00489     ImageFormat             *localFormat=NULL;
00490     int                     extNumOfImagingDataFile;
00491         
00492     //    Algorithm
00493     //    ---------
00494     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00495     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00496 
00497    cpl_msg_info(cpl_func,"\nAnalysing batch  %d  for Dispersive Transmission Assessment \n", batchNumber);
00498    cpl_msg_info(cpl_func,"--------------- \n");
00499     fprintf (midiReportPtr, "\nAnalysing batch  %d  for Dispersive Transmission Assessment \n", batchNumber);
00500     fprintf (midiReportPtr, "--------------- \n");
00501 
00502     //    Reset status
00503     *error = 0;
00504     *numOfFiles = 0;
00505     
00506     //    Allocate memory for a temporary file name buffer
00507     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00508     fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00509     localFormat = callocImageFormat ();
00510     
00511     //    Open the list of files
00512     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00513     {
00514         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
00515         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
00516         free (fileTemp);
00517         freeImageFormat (localFormat);
00518         free (classification);
00519         *error = 1;
00520         return;
00521     }
00522 
00523     //    Reset image format
00524     format->numOfScans = 0;
00525     format->numOfFrames = 0;
00526     format->subWindowSize = 0;
00527     format->framesPerScan = 0;
00528     format->iXWidth = 0;
00529     format->iYWidth = 0;
00530     
00531     //    Loop through the files and analyse
00532     while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
00533     {
00534         sprintf (classification, "%s", "");
00535         sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
00536         if (diagnostic)cpl_msg_info(cpl_func,"\n   Analysing file   %s \n", fileNames->inFitsName);
00537         fprintf(midiReportPtr, "\n   Analysing file   %s \n", fileNames->inFitsName);
00538 
00539         //    Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
00540         extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
00541         if (*error) break;
00542 
00543         //    Get Image Format parameters
00544         if (extNumOfImagingDataFile > 0)
00545         {
00546             getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
00547             if (*error) break;
00548         }
00549         else localFormat->hasData = 0;
00550 
00551         //    Check if the file has data
00552         if (localFormat->hasData)
00553         {
00554             if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
00555                 (strcmp (localFormat->obsTech, "SPECTRUM") == 0) &&
00556                 (strcmp (localFormat->obsType, "WAVE") == 0))
00557             {
00558                 //    Increment file counter
00559                 (*numOfFiles)++;
00560 
00561                 //    Log results
00562                cpl_msg_info(cpl_func,"File number           = %d \n", *numOfFiles);
00563                cpl_msg_info(cpl_func,"Observation Category  = %s \n", localFormat->obsCatg);
00564                cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
00565                cpl_msg_info(cpl_func,"Observation Type      = %s \n", localFormat->obsType);
00566                cpl_msg_info(cpl_func,"Beam Combiner         = %s \n", localFormat->beamCombiner);
00567                cpl_msg_info(cpl_func,"Shutter ID            = %s \n", localFormat->shutterId);
00568                cpl_msg_info(cpl_func,"Grism ID              = %s \n", localFormat->grismId);
00569                cpl_msg_info(cpl_func,"Filter Name           = %s \n", localFormat->filterName);
00570                cpl_msg_info(cpl_func,"Target Name           = %s \n", localFormat->targetName);
00571                cpl_msg_info(cpl_func,"Number of Frames      = %d \n", localFormat->numOfFrames);
00572                cpl_msg_info(cpl_func,"Frames per scan       = %d \n", localFormat->framesPerScan);
00573                cpl_msg_info(cpl_func,"Number of Scans       = %d \n", localFormat->numOfScans);
00574                cpl_msg_info(cpl_func,"X, Column dimension   = %d \n", localFormat->iXWidth);
00575                cpl_msg_info(cpl_func,"Y, Column dimension   = %d \n", localFormat->iYWidth);
00576                cpl_msg_info(cpl_func,"Sub-window size       = %d \n", localFormat->subWindowSize);
00577                cpl_msg_info(cpl_func,"\n");
00578 
00579                 fprintf (midiReportPtr, "File number           = %d \n", *numOfFiles);
00580                 fprintf (midiReportPtr, "Observation Category  = %s \n", localFormat->obsCatg);
00581                 fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
00582                 fprintf (midiReportPtr, "Observation Type      = %s \n", localFormat->obsType);
00583                 fprintf (midiReportPtr, "Beam Combiner         = %s \n", localFormat->beamCombiner);
00584                 fprintf (midiReportPtr, "Shutter ID            = %s \n", localFormat->shutterId);
00585                 fprintf (midiReportPtr, "Grism ID              = %s \n", localFormat->grismId);
00586                 fprintf (midiReportPtr, "Filter Name           = %s \n", localFormat->filterName);
00587                 fprintf (midiReportPtr, "Target Name           = %s \n", localFormat->targetName);
00588                 fprintf (midiReportPtr, "Number of Frames      = %d \n", localFormat->numOfFrames);
00589                 fprintf (midiReportPtr, "Frames per scan       = %d \n", localFormat->framesPerScan);
00590                 fprintf (midiReportPtr, "Number of Scans       = %d \n", localFormat->numOfScans);
00591                 fprintf (midiReportPtr, "X, Column dimension   = %d \n", localFormat->iXWidth);
00592                 fprintf (midiReportPtr, "Y, Column dimension   = %d \n", localFormat->iYWidth);
00593                 fprintf (midiReportPtr, "Sub-window size       = %d \n", localFormat->subWindowSize);
00594                 fprintf (midiReportPtr, "\n");
00595                  
00596                 //    Compute maximum image format. Save local parameters
00597                 format->hasData = 1;
00598                 if (*numOfFiles == 1)
00599                 {
00600                     sprintf (format->obsCatg, "%s", localFormat->obsCatg);
00601                     sprintf (format->obsType, "%s", localFormat->obsType);
00602                     sprintf (format->obsTech, "%s", localFormat->obsTech);
00603                     sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
00604                     sprintf (format->shutterId, "%s", localFormat->shutterId);
00605                     sprintf (format->grismId, "%s", localFormat->grismId);
00606                     sprintf (format->targetName, "%s", localFormat->targetName);
00607                     sprintf (format->tplStart, "%s", localFormat->tplStart);
00608                     sprintf (format->cameraId, "%s", localFormat->cameraId);
00609                     sprintf (format->filterName, "%s", localFormat->filterName);
00610                 }
00611 
00612                 if (localFormat->numOfScans > format->numOfScans) 
00613                     format->numOfScans = localFormat->numOfScans;
00614                     
00615                 if (localFormat->numOfFrames > format->numOfFrames) 
00616                     format->numOfFrames = localFormat->numOfFrames;
00617                     
00618                 if (localFormat->subWindowSize > format->subWindowSize) 
00619                     format->subWindowSize = localFormat->subWindowSize;
00620                     
00621                 if (localFormat->framesPerScan > format->framesPerScan) 
00622                     format->framesPerScan = localFormat->framesPerScan;
00623                     
00624                 if (localFormat->iXWidth > format->iXWidth) 
00625                     format->iXWidth = localFormat->iXWidth;
00626                     
00627                 if (localFormat->iYWidth > format->iYWidth) 
00628                     format->iYWidth = localFormat->iYWidth;
00629             }
00630             else
00631             {
00632                 sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
00633                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00634             }
00635         }
00636         else
00637         {
00638             if (diagnostic)
00639             {
00640                 sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
00641                 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00642             }
00643         }
00644     }
00645 
00646 
00647     //    Close the file list
00648     fclose (inFitsBatchPtr);
00649     
00650     //    Check if the FITS files contained useful data
00651     if ((*numOfFiles > 0) && !(*error))
00652     {
00653        cpl_msg_info(cpl_func,"   Maximum image size \n");
00654        cpl_msg_info(cpl_func,"   ------------------ \n");
00655        cpl_msg_info(cpl_func,"   Number of Scans       = %d \n", format->numOfScans);
00656        cpl_msg_info(cpl_func,"   Number of Frames      = %d \n", format->numOfFrames);
00657        cpl_msg_info(cpl_func,"   Frames per scan       = %d \n", format->framesPerScan);
00658        cpl_msg_info(cpl_func,"   X, column dimension   = %d \n", format->iXWidth);
00659        cpl_msg_info(cpl_func,"   Y, column dimension   = %d \n", format->iYWidth);
00660        cpl_msg_info(cpl_func,"   Sub-window size       = %d \n", format->subWindowSize);
00661        cpl_msg_info(cpl_func,"   Number of Data Files  = %d \n", *numOfFiles);
00662        cpl_msg_info(cpl_func,"\n");
00663                 
00664         fprintf (midiReportPtr, "   Maximum image size \n");
00665         fprintf (midiReportPtr, "   ------------------ \n");
00666         fprintf (midiReportPtr, "   Number of Scans       = %d \n", format->numOfScans);
00667         fprintf (midiReportPtr, "   Number of Frames      = %d \n", format->numOfFrames);
00668         fprintf (midiReportPtr, "   Frames per scan       = %d \n", format->framesPerScan);
00669         fprintf (midiReportPtr, "   X, column dimension   = %d \n", format->iXWidth);
00670         fprintf (midiReportPtr, "   Y, column dimension   = %d \n", format->iYWidth);
00671         fprintf (midiReportPtr, "   Sub-window size       = %d \n", format->subWindowSize);
00672         fprintf (midiReportPtr, "   Number of Data Files  = %d \n", *numOfFiles);
00673         fprintf (midiReportPtr, "\n");
00674     }
00675     else
00676     {
00677         *error = 1;
00678         sprintf (fileTemp, "%d", batchNumber);
00679         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
00680     }
00681 
00682     //    Release memory
00683     free (fileTemp);
00684     freeImageFormat (localFormat);
00685     free (classification);
00686      
00687     return;
00688 }
00689 /******************************************************************************/
00690 
00691 
00692 /******************************************************************************
00693 *               European Southern Observatory
00694 *          VLTI MIDI Maintenance Templates Software
00695 *
00696 * Module name:  analyseFitsRefPix
00697 * Input/Output: See function arguments to avoid duplication
00698 * Description:  Analyses all the FITS files in the given list. This routine
00699 *                determines if the FITS list contains useful data files. If
00700 *                not it will discard the list.
00701 *
00702 * History:      
00703 * 14-Jun-04     (csabet) created
00704 ******************************************************************************/
00705 void analyseFitsRefPix (
00706     MidiFiles   *fileNames,        //  IO: Pointer to midi files structure */
00707     ImageFormat *format,        //  Ou: Pointer to the image format structure */
00708     int            *numOfFiles,    //    Ou: Number of files with data */
00709     int            *numOfBeams,    //    Ou:    Maximum number of beams
00710     int            *error)            //    Ou:    Error status */
00711 {
00712 
00713     //    Local Declarations
00714     //    ------------------
00715     const char              routine[] = "analyseFitsRefPix";
00716     char                        *fileTemp=NULL, *classification=NULL;
00717     FILE                    *inFitsBatchPtr=NULL;
00718     ImageFormat             *localFormat=NULL;
00719     int                     extNumOfImagingDataFile;
00720         
00721     //    Algorithm
00722     //    ---------
00723     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00724     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00725 
00726    cpl_msg_info(cpl_func,"\nAnalysing batch  %d  for Reference Pixel Alignment \n", batchNumber);
00727    cpl_msg_info(cpl_func,"--------------- \n");
00728     fprintf (midiReportPtr, "\nAnalysing batch  %d  for Reference Pixel Alignment \n", batchNumber);
00729     fprintf (midiReportPtr, "--------------- \n");
00730 
00731     //    Reset status
00732     *error = 0;
00733     *numOfFiles = 0;
00734     *numOfBeams = 2;
00735     
00736     //    Allocate memory for a temporary file name buffer
00737     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00738     fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00739     localFormat = callocImageFormat ();
00740     
00741     //    Open the list of files
00742     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00743     {
00744         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
00745         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
00746         free (fileTemp);
00747         freeImageFormat (localFormat);
00748         free (classification);
00749         *error = 1;
00750         return;
00751     }
00752 
00753     //    Reset image format
00754     format->numOfScans = 0;
00755     format->numOfFrames = 0;
00756     format->subWindowSize = 0;
00757     format->framesPerScan = 0;
00758     format->iXWidth = 0;
00759     format->iYWidth = 0;
00760     
00761     //    Loop through the files and analyse
00762     while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
00763     {
00764         sprintf (classification, "%s", "");
00765         sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
00766         if (diagnostic)cpl_msg_info(cpl_func,"\n   Analysing file   %s \n", fileNames->inFitsName);
00767         fprintf(midiReportPtr, "\n   Analysing file   %s \n", fileNames->inFitsName);
00768 
00769         //    Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
00770         extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
00771         if (*error) break;
00772 
00773         //    Get Image Format parameters
00774         if (extNumOfImagingDataFile > 0)
00775         {
00776             getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
00777             if (*error) break;
00778         }
00779         else localFormat->hasData = 0;
00780 
00781         //    Check if the file has data
00782         if (localFormat->hasData)
00783         {
00784             if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
00785             (strcmp (localFormat->obsTech, "IMAGE") == 0) &&
00786             (strcmp (localFormat->obsType, "FMTCHCK") == 0))
00787             {
00788                 //    Increment file counter
00789                 (*numOfFiles)++;
00790 
00791                 //    Compute maximum number of beams per exposure
00792                 if (strcmp (localFormat->beamCombiner, "SCI_PHOT") == 0) *numOfBeams = 3;
00793 
00794                 //    Log results
00795                cpl_msg_info(cpl_func,"File number           = %d \n", *numOfFiles);
00796                cpl_msg_info(cpl_func,"Observation Category  = %s \n", localFormat->obsCatg);
00797                cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
00798                cpl_msg_info(cpl_func,"Observation Type      = %s \n", localFormat->obsType);
00799                cpl_msg_info(cpl_func,"Beam Combiner         = %s \n", localFormat->beamCombiner);
00800                cpl_msg_info(cpl_func,"Shutter ID            = %s \n", localFormat->shutterId);
00801                cpl_msg_info(cpl_func,"Grism ID              = %s \n", localFormat->grismId);
00802                cpl_msg_info(cpl_func,"Filter Name           = %s \n", localFormat->filterName);
00803                cpl_msg_info(cpl_func,"Target Name           = %s \n", localFormat->targetName);
00804                cpl_msg_info(cpl_func,"Number of Frames      = %d \n", localFormat->numOfFrames);
00805                cpl_msg_info(cpl_func,"Frames per scan       = %d \n", localFormat->framesPerScan);
00806                cpl_msg_info(cpl_func,"Number of Scans       = %d \n", localFormat->numOfScans);
00807                cpl_msg_info(cpl_func,"X, Column dimension   = %d \n", localFormat->iXWidth);
00808                cpl_msg_info(cpl_func,"Y, Column dimension   = %d \n", localFormat->iYWidth);
00809                cpl_msg_info(cpl_func,"Sub-window size       = %d \n", localFormat->subWindowSize);
00810                cpl_msg_info(cpl_func,"\n");
00811 
00812                 fprintf (midiReportPtr, "File number           = %d \n", *numOfFiles);
00813                 fprintf (midiReportPtr, "Observation Category  = %s \n", localFormat->obsCatg);
00814                 fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
00815                 fprintf (midiReportPtr, "Observation Type      = %s \n", localFormat->obsType);
00816                 fprintf (midiReportPtr, "Beam Combiner         = %s \n", localFormat->beamCombiner);
00817                 fprintf (midiReportPtr, "Shutter ID            = %s \n", localFormat->shutterId);
00818                 fprintf (midiReportPtr, "Grism ID              = %s \n", localFormat->grismId);
00819                 fprintf (midiReportPtr, "Filter Name           = %s \n", localFormat->filterName);
00820                 fprintf (midiReportPtr, "Target Name           = %s \n", localFormat->targetName);
00821                 fprintf (midiReportPtr, "Number of Frames      = %d \n", localFormat->numOfFrames);
00822                 fprintf (midiReportPtr, "Frames per scan       = %d \n", localFormat->framesPerScan);
00823                 fprintf (midiReportPtr, "Number of Scans       = %d \n", localFormat->numOfScans);
00824                 fprintf (midiReportPtr, "X, Column dimension   = %d \n", localFormat->iXWidth);
00825                 fprintf (midiReportPtr, "Y, Column dimension   = %d \n", localFormat->iYWidth);
00826                 fprintf (midiReportPtr, "Sub-window size       = %d \n", localFormat->subWindowSize);
00827                 fprintf (midiReportPtr, "\n");
00828                  
00829                 //    Compute maximum image format. Save local parameters
00830                 format->hasData = 1;
00831                 if (*numOfFiles == 1)
00832                 {
00833                     sprintf (format->obsCatg, "%s", localFormat->obsCatg);
00834                     sprintf (format->obsType, "%s", localFormat->obsType);
00835                     sprintf (format->obsTech, "%s", localFormat->obsTech);
00836                     sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
00837                     sprintf (format->shutterId, "%s", localFormat->shutterId);
00838                     sprintf (format->grismId, "%s", localFormat->grismId);
00839                     sprintf (format->targetName, "%s", localFormat->targetName);
00840                     sprintf (format->tplStart, "%s", localFormat->tplStart);
00841                     sprintf (format->cameraId, "%s", localFormat->cameraId);
00842                     sprintf (format->filterName, "%s", localFormat->filterName);
00843                 }
00844 
00845                 if (localFormat->numOfScans > format->numOfScans) 
00846                     format->numOfScans = localFormat->numOfScans;
00847                     
00848                 if (localFormat->numOfFrames > format->numOfFrames) 
00849                     format->numOfFrames = localFormat->numOfFrames;
00850                     
00851                 if (localFormat->subWindowSize > format->subWindowSize) 
00852                     format->subWindowSize = localFormat->subWindowSize;
00853                     
00854                 if (localFormat->framesPerScan > format->framesPerScan) 
00855                     format->framesPerScan = localFormat->framesPerScan;
00856                     
00857                 if (localFormat->iXWidth > format->iXWidth) 
00858                     format->iXWidth = localFormat->iXWidth;
00859                     
00860                 if (localFormat->iYWidth > format->iYWidth) 
00861                     format->iYWidth = localFormat->iYWidth;
00862             }
00863             else
00864             {
00865                 sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
00866                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00867             }
00868         }
00869         else
00870         {
00871             if (diagnostic)
00872             {
00873                 sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
00874                 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00875             }
00876         }
00877     }
00878 
00879 
00880     //    Close the file list
00881     fclose (inFitsBatchPtr);
00882     
00883     //    Check if the FITS files contained useful data
00884     if ((*numOfFiles > 0) && !(*error))
00885     {
00886        cpl_msg_info(cpl_func,"   Maximum image size \n");
00887        cpl_msg_info(cpl_func,"   ------------------ \n");
00888        cpl_msg_info(cpl_func,"   Number of Scans       = %d \n", format->numOfScans);
00889        cpl_msg_info(cpl_func,"   Number of Frames      = %d \n", format->numOfFrames);
00890        cpl_msg_info(cpl_func,"   Frames per scan       = %d \n", format->framesPerScan);
00891        cpl_msg_info(cpl_func,"   Number of Beams       = %d \n", *numOfBeams);
00892        cpl_msg_info(cpl_func,"   X, column dimension   = %d \n", format->iXWidth);
00893        cpl_msg_info(cpl_func,"   Y, column dimension   = %d \n", format->iYWidth);
00894        cpl_msg_info(cpl_func,"   Sub-window size       = %d \n", format->subWindowSize);
00895        cpl_msg_info(cpl_func,"   Number of Data Files  = %d \n", *numOfFiles);
00896        cpl_msg_info(cpl_func,"\n");
00897                 
00898         fprintf (midiReportPtr, "   Maximum image size \n");
00899         fprintf (midiReportPtr, "   ------------------ \n");
00900         fprintf (midiReportPtr, "   Number of Scans       = %d \n", format->numOfScans);
00901         fprintf (midiReportPtr, "   Number of Frames      = %d \n", format->numOfFrames);
00902         fprintf (midiReportPtr, "   Frames per scan       = %d \n", format->framesPerScan);
00903         fprintf (midiReportPtr, "   Number of Beams       = %d \n", *numOfBeams);
00904         fprintf (midiReportPtr, "   X, column dimension   = %d \n", format->iXWidth);
00905         fprintf (midiReportPtr, "   Y, column dimension   = %d \n", format->iYWidth);
00906         fprintf (midiReportPtr, "   Sub-window size       = %d \n", format->subWindowSize);
00907         fprintf (midiReportPtr, "   Number of Data Files  = %d \n", *numOfFiles);
00908         fprintf (midiReportPtr, "\n");
00909     }
00910     else
00911     {
00912         *error = 1;
00913         sprintf (fileTemp, "%d", batchNumber);
00914         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
00915     }
00916 
00917     //    Release memory
00918     free (fileTemp);
00919     freeImageFormat (localFormat);
00920     free (classification);
00921      
00922     return;
00923 }
00924 /******************************************************************************/
00925 
00926 
00927 
00928 /******************************************************************************
00929 *               European Southern Observatory
00930 *          VLTI MIDI Maintenance Templates Software
00931 *
00932 * Module name:  analyseFitsWaveCal
00933 * Input/Output: See function arguments to avoid duplication
00934 * Description:  Analyses all the FITS files in the given list. This routine
00935 *                determines if the FITS list contains useful data files. If
00936 *                not it will discard the list.
00937 *
00938 * History:      
00939 * 10-Jun-05     (csabet) created
00940 ******************************************************************************/
00941 void analyseFitsWaveCal (
00942     MidiFiles   *fileNames,        // IO: Pointer to midi files structure
00943     ImageFormat *format,        // Ou: Pointer to the image format structure
00944     int            *numOfFiles,    // Ou: Number of files with data
00945     int            *error)            // Ou:    Error status
00946 {
00947 
00948     //    Local Declarations
00949     //    ------------------
00950     const char              routine[] = "analyseFitsWaveCal";
00951     char                        *fileTemp=NULL, *classification=NULL;
00952     FILE                    *inFitsBatchPtr=NULL;
00953     ImageFormat             *localFormat=NULL;
00954     int                     extNumOfImagingDataFile;
00955         
00956     //    Algorithm
00957     //    ---------
00958     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00959     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00960 
00961    cpl_msg_info(cpl_func,"\nAnalysing batch  %d  for Wavelength Calibration \n", batchNumber);
00962    cpl_msg_info(cpl_func,"--------------- \n");
00963     fprintf (midiReportPtr, "\nAnalysing batch  %d  for Wavelength Calibration \n", batchNumber);
00964     fprintf (midiReportPtr, "--------------- \n");
00965 
00966     //    Reset status
00967     *error = 0;
00968     *numOfFiles = 0;
00969     
00970     //    Allocate memory for a temporary file name buffer
00971     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00972     fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00973     localFormat = callocImageFormat ();
00974     
00975     //    Open the list of files
00976     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00977     {
00978         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
00979         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
00980         free (fileTemp);
00981         freeImageFormat (localFormat);
00982         free (classification);
00983         *error = 1;
00984         return;
00985     }
00986 
00987     //    Reset image format
00988     format->hasData = 0;
00989     format->numOfDetectorRegions = 0;
00990     format->numOfRegionsToProcess = 0;
00991     format->numOfPinholes = 0;
00992     format->numOfFrames = 0;
00993     format->framesPerScan = 0;
00994     format->numOfScans = 0;
00995     format->subWindowSize = 0;
00996     format->iXWidth = 0;
00997     format->iYWidth = 0;
00998 
00999     //    Loop through the files and analyse
01000     while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
01001     {
01002         sprintf (classification, "%s", "");
01003         sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
01004         if (diagnostic)cpl_msg_info(cpl_func,"\n   Analysing file   %s \n", fileNames->inFitsName);
01005         fprintf(midiReportPtr, "\n   Analysing file   %s \n", fileNames->inFitsName);
01006 
01007         //    Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
01008         extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
01009         if (*error) break;
01010 
01011         //    Get Image Format parameters
01012         if (extNumOfImagingDataFile > 0)
01013         {
01014             getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
01015             if (*error) break;
01016         }
01017         else localFormat->hasData = 0;
01018 
01019         //    Check if the file has data
01020         if (localFormat->hasData)
01021         {
01022             if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
01023                 (strcmp (localFormat->obsTech, "SPECTRUM") == 0) &&
01024                 (strcmp (localFormat->obsType, "WAVE,SPECTEMPL") == 0))
01025             {
01026                 //    Increment file counter
01027                 (*numOfFiles)++;
01028 
01029                 //    Log results
01030                cpl_msg_info(cpl_func,"File number           = %d \n", *numOfFiles);
01031                cpl_msg_info(cpl_func,"Observation Category  = %s \n", localFormat->obsCatg);
01032                cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
01033                cpl_msg_info(cpl_func,"Observation Type      = %s \n", localFormat->obsType);
01034                cpl_msg_info(cpl_func,"Beam Combiner         = %s \n", localFormat->beamCombiner);
01035                cpl_msg_info(cpl_func,"Shutter ID            = %s \n", localFormat->shutterId);
01036                cpl_msg_info(cpl_func,"Filter Name           = %s \n", localFormat->filterName);
01037                cpl_msg_info(cpl_func,"Grism ID              = %s \n", localFormat->grismId);
01038                cpl_msg_info(cpl_func,"Target Name           = %s \n", localFormat->targetName);
01039                cpl_msg_info(cpl_func,"Number of Frames      = %d \n", localFormat->numOfFrames);
01040                cpl_msg_info(cpl_func,"Frames per scan       = %d \n", localFormat->framesPerScan);
01041                cpl_msg_info(cpl_func,"Number of Scans       = %d \n", localFormat->numOfScans);
01042                cpl_msg_info(cpl_func,"X, Column dimension   = %d \n", localFormat->iXWidth);
01043                cpl_msg_info(cpl_func,"Y, Column dimension   = %d \n", localFormat->iYWidth);
01044                cpl_msg_info(cpl_func,"Sub-window size       = %d \n", localFormat->subWindowSize);
01045                cpl_msg_info(cpl_func,"\n");
01046 
01047                 fprintf (midiReportPtr, "File number           = %d \n", *numOfFiles);
01048                 fprintf (midiReportPtr, "Observation Category  = %s \n", localFormat->obsCatg);
01049                 fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
01050                 fprintf (midiReportPtr, "Observation Type      = %s \n", localFormat->obsType);
01051                 fprintf (midiReportPtr, "Beam Combiner         = %s \n", localFormat->beamCombiner);
01052                 fprintf (midiReportPtr, "Shutter ID            = %s \n", localFormat->shutterId);
01053                 fprintf (midiReportPtr, "Filter Name           = %s \n", localFormat->filterName);
01054                 fprintf (midiReportPtr, "Grism ID              = %s \n", localFormat->grismId);
01055                 fprintf (midiReportPtr, "Target Name           = %s \n", localFormat->targetName);
01056                 fprintf (midiReportPtr, "Number of Frames      = %d \n", localFormat->numOfFrames);
01057                 fprintf (midiReportPtr, "Frames per scan       = %d \n", localFormat->framesPerScan);
01058                 fprintf (midiReportPtr, "Number of Scans       = %d \n", localFormat->numOfScans);
01059                 fprintf (midiReportPtr, "X, Column dimension   = %d \n", localFormat->iXWidth);
01060                 fprintf (midiReportPtr, "Y, Column dimension   = %d \n", localFormat->iYWidth);
01061                 fprintf (midiReportPtr, "Sub-window size       = %d \n", localFormat->subWindowSize);
01062                 fprintf (midiReportPtr, "\n");
01063                  
01064                 //    Save local parameters
01065                 if (*numOfFiles == 1)
01066                 {
01067                     format->hasData = 1;
01068                     sprintf (format->obsCatg, "%s", localFormat->obsCatg);
01069                     sprintf (format->obsTech, "%s", localFormat->obsTech);
01070                     sprintf (format->obsType, "%s", localFormat->obsType);
01071                     sprintf (format->cameraId, "%s", localFormat->cameraId);
01072                     sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
01073                     sprintf (format->filterName, "%s", localFormat->filterName);
01074                     sprintf (format->shutterId, "%s", localFormat->shutterId);
01075                     sprintf (format->grismId, "%s", localFormat->grismId);
01076                     sprintf (format->targetName, "%s", localFormat->targetName);
01077                     sprintf (format->slitName, "%s", localFormat->slitName);
01078                     sprintf (format->tplStart, "%s", localFormat->tplStart);
01079                     sprintf (format->tplName, "%s", localFormat->tplName);
01080                     format->numOfDetectorRegions = localFormat->numOfDetectorRegions;
01081                     format->numOfRegionsToProcess = localFormat->numOfRegionsToProcess;
01082                     format->numOfPinholes = localFormat->numOfPinholes;
01083                     format->framesPerScan = localFormat->framesPerScan;
01084                     format->subWindowSize = localFormat->subWindowSize;
01085                     format->iXWidth = localFormat->iXWidth;
01086                     format->iYWidth = localFormat->iYWidth;
01087                     format->numOfFrames = localFormat->numOfFrames;
01088                     format->subWindowSize = localFormat->subWindowSize;
01089                 }
01090                 else // Check consistency
01091                 {
01092                     if (strcmp (format->obsCatg, localFormat->obsCatg) != 0) *error = 1;
01093                     if (strcmp (format->obsTech, localFormat->obsTech) != 0) *error = 1;
01094                     if (strcmp (format->obsType, localFormat->obsType) != 0) *error = 1;
01095                     if (strcmp (format->cameraId, localFormat->cameraId) != 0) *error = 1;
01096                     if (strcmp (format->beamCombiner, localFormat->beamCombiner) != 0) *error = 1;
01097                     if (strcmp (format->grismId, localFormat->grismId) != 0) *error = 1;
01098                     if (strcmp (format->targetName, localFormat->targetName) != 0) *error = 1;
01099                     if (strcmp (format->slitName, localFormat->slitName) != 0) *error = 1;
01100                     if (strcmp (format->tplStart, localFormat->tplStart) != 0) *error = 1;
01101                     if (strcmp (format->tplName, localFormat->tplName) != 0) *error = 1;
01102                     if (format->numOfDetectorRegions != localFormat->numOfDetectorRegions) *error = 1;
01103                     if (format->numOfRegionsToProcess != localFormat->numOfRegionsToProcess) *error = 1;
01104                     if (format->numOfPinholes != localFormat->numOfPinholes) *error = 1;
01105                     if (format->framesPerScan != localFormat->framesPerScan) *error = 1;
01106                     if (format->subWindowSize != localFormat->subWindowSize) *error = 1;
01107                     if (format->iXWidth != localFormat->iXWidth) *error = 1;
01108                     if (format->iYWidth != localFormat->iYWidth) *error = 1;
01109                     if (format->numOfFrames != localFormat->numOfFrames) *error = 1;
01110                     if (format->subWindowSize != localFormat->subWindowSize) *error = 1;
01111                 }
01112                 if (*error)
01113                 {
01114                     sprintf (midiMessage, "Inconsistent FITS files. %s", fileNames->inFitsName);
01115                     midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
01116                 }
01117             }
01118             else
01119             {
01120                 sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
01121                 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
01122             }
01123         }
01124         else
01125         {
01126             if (diagnostic)
01127             {
01128                 sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
01129                 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
01130             }
01131         }
01132     }
01133 
01134 
01135     //    Close the file list
01136     fclose (inFitsBatchPtr);
01137     
01138     //    Check if the FITS files contained useful data
01139     if ((*numOfFiles > 0) && !(*error))
01140     {
01141        cpl_msg_info(cpl_func,"   Maximum image size \n");
01142        cpl_msg_info(cpl_func,"   ------------------ \n");
01143        cpl_msg_info(cpl_func,"   Number of Scans       = %d \n", format->numOfScans);
01144        cpl_msg_info(cpl_func,"   Number of Frames      = %d \n", format->numOfFrames);
01145        cpl_msg_info(cpl_func,"   Frames per scan       = %d \n", format->framesPerScan);
01146        cpl_msg_info(cpl_func,"   X, column dimension   = %d \n", format->iXWidth);
01147        cpl_msg_info(cpl_func,"   Y, column dimension   = %d \n", format->iYWidth);
01148        cpl_msg_info(cpl_func,"   Number of Regions     = %d \n", format->numOfDetectorRegions);
01149        cpl_msg_info(cpl_func,"   Sub-window size       = %d \n", format->subWindowSize);
01150        cpl_msg_info(cpl_func,"   Number of Data Files  = %d \n", *numOfFiles);
01151        cpl_msg_info(cpl_func,"\n");
01152                 
01153         fprintf (midiReportPtr, "   Maximum image size \n");
01154         fprintf (midiReportPtr, "   ------------------ \n");
01155         fprintf (midiReportPtr, "   Number of Scans       = %d \n", format->numOfScans);
01156         fprintf (midiReportPtr, "   Number of Frames      = %d \n", format->numOfFrames);
01157         fprintf (midiReportPtr, "   Frames per scan       = %d \n", format->framesPerScan);
01158         fprintf (midiReportPtr, "   X, column dimension   = %d \n", format->iXWidth);
01159         fprintf (midiReportPtr, "   Y, column dimension   = %d \n", format->iYWidth);
01160         fprintf (midiReportPtr, "   Number of Regions     = %d \n", format->numOfDetectorRegions);
01161         fprintf (midiReportPtr, "   Sub-window size       = %d \n", format->subWindowSize);
01162         fprintf (midiReportPtr, "   Number of Data Files  = %d \n", *numOfFiles);
01163         fprintf (midiReportPtr, "\n");
01164     }
01165     else
01166     {
01167         *error = 1;
01168         sprintf (fileTemp, "%d", batchNumber);
01169         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
01170     }
01171 
01172     //    Release memory
01173     free (fileTemp);
01174     freeImageFormat (localFormat);
01175     free (classification);
01176      
01177     return;
01178 }
01179 /******************************************************************************/
01180 

Generated on 5 Mar 2013 for MIDI Pipeline Reference Manual by  doxygen 1.6.1