MIDI Pipeline Reference Manual  2.8.3
fitsAnalysisTec.c
1 
2 /******************************************************************************
3 *******************************************************************************
4 * European Southern Observatory
5 * VLTI MIDI Maintenance Templates Software
6 *
7 * Module name: fitsAnalysisTec.c
8 * Description: Contains all routines for FITS format analysis
9 *
10 * History:
11 * 14-Jun-02 (csabet) created
12 *******************************************************************************
13 ******************************************************************************/
14 
15 /******************************************************************************
16 * Compiler directives
17 ******************************************************************************/
18 
19 /******************************************************************************
20 * Include files
21 ******************************************************************************/
22 #include <stdio.h>
23 #include <cpl.h>
24 #include "midiGlobal.h"
25 #include "midiLib.h"
26 #include "fft.h"
27 #include "errorHandling.h"
28 #include "memoryHandling.h"
29 #include "midiFitsUtility.h"
30 #include "fitsAnalysisTec.h"
31 
32 /**********************************************************
33 * Global Variables
34 **********************************************************/
35 
36 
37 
38 /*============================ C O D E A R E A ===========================*/
39 
40 
41 /******************************************************************************
42 * European Southern Observatory
43 * VLTI MIDI Maintenance Templates Software
44 *
45 * Module name: analyseFitsDetLin
46 * Input/Output: See function arguments to avoid duplication
47 * Description: Analyses all the FITS files in the given list. This routine
48 * determines if the FITS list contains useful data files. If
49 * not it will discard the list.
50 *
51 * History:
52 * 14-Jun-04 (csabet) created
53 ******************************************************************************/
54 void analyseFitsDetLin (
55  MidiFiles *fileNames, /* IO: Pointer to midi files structure */
56  ImageFormat *format, /* Ou: Pointer to the image format structure */
57  int *numOfFiles, /* Ou: Number of files with data */
58  int *error) /* Ou: Error status */
59 {
60 
61  // Local Declarations
62  // ------------------
63  const char routine[] = "analyseFitsDetLin";
64  char *fileTemp=NULL, *classification=NULL;
65  FILE *inFitsBatchPtr=NULL;
66  ImageFormat *localFormat=NULL;
67  int extNumOfImagingDataFile;
68 
69  // Algorithm
70  // ---------
71  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
72  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
73 
74  cpl_msg_info(cpl_func,"\nAnalysing batch %d for Detector Linearity \n", batchNumber);
75  cpl_msg_info(cpl_func,"--------------- \n");
76  fprintf (midiReportPtr, "\nAnalysing batch %d for Detector Linearity \n", batchNumber);
77  fprintf (midiReportPtr, "--------------- \n");
78 
79  // Reset status
80  *error = 0;
81  *numOfFiles = 0;
82 
83  // Allocate memory for a temporary file name buffer
84  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
85  fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
86  localFormat = callocImageFormat ();
87 
88  // Open the list of files
89  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
90  {
91  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
92  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
93  free (fileTemp);
94  freeImageFormat (localFormat);
95  free (classification);
96  *error = 1;
97  return;
98  }
99 
100  // Reset image format
101  format->numOfScans = 0;
102  format->numOfFrames = 0;
103  format->subWindowSize = 0;
104  format->framesPerScan = 0;
105  format->iXWidth = 0;
106  format->iYWidth = 0;
107 
108  // Loop through the files and analyse
109  while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
110  {
111  sprintf (classification, "%s", "");
112  sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
113  if (diagnostic)cpl_msg_info(cpl_func,"\n Analysing file %s \n", fileNames->inFitsName);
114  fprintf(midiReportPtr, "\n Analysing file %s \n", fileNames->inFitsName);
115 
116  // Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
117  extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
118  if (*error) break;
119 
120  // Get Image Format parameters
121  if (extNumOfImagingDataFile > 0)
122  {
123  getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
124  if (*error) break;
125  }
126  else localFormat->hasData = 0;
127 
128  // Check if the file has data
129  if (localFormat->hasData)
130  {
131  if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
132  ((strcmp (localFormat->obsTech, "IMAGE") == 0) ||
133  (strcmp (localFormat->obsTech, "SPECTRUM") == 0)) &&
134  (strcmp (localFormat->obsType, "FLAT") == 0))
135  {
136  // Increment file counter
137  (*numOfFiles)++;
138 
139  // Log results
140  cpl_msg_info(cpl_func,"File number = %d \n", *numOfFiles);
141  cpl_msg_info(cpl_func,"Observation Category = %s \n", localFormat->obsCatg);
142  cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
143  cpl_msg_info(cpl_func,"Observation Type = %s \n", localFormat->obsType);
144  cpl_msg_info(cpl_func,"Beam Combiner = %s \n", localFormat->beamCombiner);
145  cpl_msg_info(cpl_func,"Shutter ID = %s \n", localFormat->shutterId);
146  cpl_msg_info(cpl_func,"Filter Name = %s \n", localFormat->filterName);
147  cpl_msg_info(cpl_func,"Grism ID = %s \n", localFormat->grismId);
148  cpl_msg_info(cpl_func,"Target Name = %s \n", localFormat->targetName);
149  cpl_msg_info(cpl_func,"Number of Frames = %d \n", localFormat->numOfFrames);
150  cpl_msg_info(cpl_func,"X, Column dimension = %d \n", localFormat->iXWidth);
151  cpl_msg_info(cpl_func,"Y, Column dimension = %d \n", localFormat->iYWidth);
152  cpl_msg_info(cpl_func,"Sub-window size = %d \n", localFormat->subWindowSize);
153  cpl_msg_info(cpl_func,"\n");
154 
155  fprintf (midiReportPtr, "File number = %d \n", *numOfFiles);
156  fprintf (midiReportPtr, "Observation Category = %s \n", localFormat->obsCatg);
157  fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
158  fprintf (midiReportPtr, "Observation Type = %s \n", localFormat->obsType);
159  fprintf (midiReportPtr, "Beam Combiner = %s \n", localFormat->beamCombiner);
160  fprintf (midiReportPtr, "Shutter ID = %s \n", localFormat->shutterId);
161  fprintf (midiReportPtr, "Filter Name = %s \n", localFormat->filterName);
162  fprintf (midiReportPtr, "Grism ID = %s \n", localFormat->grismId);
163  fprintf (midiReportPtr, "Target Name = %s \n", localFormat->targetName);
164  fprintf (midiReportPtr, "Number of Frames = %d \n", localFormat->numOfFrames);
165  fprintf (midiReportPtr, "X, Column dimension = %d \n", localFormat->iXWidth);
166  fprintf (midiReportPtr, "Y, Column dimension = %d \n", localFormat->iYWidth);
167  fprintf (midiReportPtr, "Sub-window size = %d \n", localFormat->subWindowSize);
168  fprintf (midiReportPtr, "\n");
169 
170  // Compute maximum image format. Save local parameters
171  format->hasData = 1;
172  if (*numOfFiles == 1)
173  {
174  sprintf (format->obsCatg, "%s", localFormat->obsCatg);
175  sprintf (format->obsType, "%s", localFormat->obsType);
176  sprintf (format->obsTech, "%s", localFormat->obsTech);
177  sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
178  sprintf (format->shutterId, "%s", localFormat->shutterId);
179  sprintf (format->grismId, "%s", localFormat->grismId);
180  sprintf (format->targetName, "%s", localFormat->targetName);
181  sprintf (format->tplStart, "%s", localFormat->tplStart);
182  sprintf (format->cameraId, "%s", localFormat->cameraId);
183  sprintf (format->filterName, "%s", localFormat->filterName);
184  }
185 
186  // Save and cummulate size
187  format->numOfFrames = localFormat->numOfFrames;
188  format->subWindowSize = localFormat->subWindowSize;
189  format->framesPerScan = localFormat->framesPerScan;
190  format->iXWidth = localFormat->iXWidth;
191  format->iYWidth = localFormat->iYWidth;
192  }
193  else
194  {
195  sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
196  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
197  }
198  }
199  else
200  {
201  if (diagnostic)
202  {
203  sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
204  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
205  }
206  }
207  }
208 
209 
210  // Close the file list
211  fclose (inFitsBatchPtr);
212 
213  // Check if the FITS files contained useful data
214  if ((*numOfFiles > 0) && !(*error))
215  {
216  cpl_msg_info(cpl_func," Maximum image size \n");
217  cpl_msg_info(cpl_func," ------------------ \n");
218  cpl_msg_info(cpl_func," Number of Frames = %d \n", format->numOfFrames);
219  cpl_msg_info(cpl_func," X, column dimension = %d \n", format->iXWidth);
220  cpl_msg_info(cpl_func," Y, column dimension = %d \n", format->iYWidth);
221  cpl_msg_info(cpl_func," Sub-window size = %d \n", format->subWindowSize);
222  cpl_msg_info(cpl_func," Number of Data Files = %d \n", *numOfFiles);
223  cpl_msg_info(cpl_func,"\n");
224 
225  fprintf (midiReportPtr, " Maximum image size \n");
226  fprintf (midiReportPtr, " ------------------ \n");
227  fprintf (midiReportPtr, " Number of Frames = %d \n", format->numOfFrames);
228  fprintf (midiReportPtr, " X, column dimension = %d \n", format->iXWidth);
229  fprintf (midiReportPtr, " Y, column dimension = %d \n", format->iYWidth);
230  fprintf (midiReportPtr, " Sub-window size = %d \n", format->subWindowSize);
231  fprintf (midiReportPtr, " Number of Data Files = %d \n", *numOfFiles);
232  fprintf (midiReportPtr, "\n");
233  }
234  else
235  {
236  *error = 1;
237  sprintf (fileTemp, "%d", batchNumber);
238  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
239  }
240 
241  // Release memory
242  free (fileTemp);
243  freeImageFormat (localFormat);
244  free (classification);
245 
246  return;
247 }
248 /******************************************************************************/
249 
250 
251 
252 
253 /******************************************************************************
254 * European Southern Observatory
255 * VLTI MIDI Maintenance Templates Software
256 *
257 * Module name: analyseFitDetRon
258 * Input/Output: See function arguments to avoid duplication
259 * Description: Analyses all the FITS files in the given list. This routine
260 * determines if the FITS list contains useful data files. If
261 * not it will discard the list.
262 *
263 * History:
264 * 14-Jun-04 (csabet) created
265 ******************************************************************************/
266 void analyseFitsDetRon (
267  MidiFiles *fileNames, /* IO: Pointer to midi files structure */
268  ImageFormat *format, /* Ou: Pointer to the image format structure */
269  int *numOfFiles, /* Ou: Number of files with data */
270  int *error) /* Ou: Error status */
271 {
272 
273  // Local Declarations
274  // ------------------
275  const char routine[] = "analyseFitDetRon";
276  char *fileTemp=NULL, *classification=NULL;
277  FILE *inFitsBatchPtr=NULL;
278  ImageFormat *localFormat=NULL;
279  int extNumOfImagingDataFile;
280 
281  // Algorithm
282  // ---------
283  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
284  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
285 
286  cpl_msg_info(cpl_func,"\nAnalysing batch %d for Detector Readout Noise \n", batchNumber);
287  cpl_msg_info(cpl_func,"--------------- \n");
288  fprintf (midiReportPtr, "\nAnalysing batch %d for Detector Readout Noise \n", batchNumber);
289  fprintf (midiReportPtr, "--------------- \n");
290 
291  // Reset status
292  *error = 0;
293  *numOfFiles = 0;
294 
295  // Allocate memory for a temporary file name buffer
296  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
297  fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
298  localFormat = callocImageFormat ();
299 
300  // Open the list of files
301  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
302  {
303  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
304  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
305  free (fileTemp);
306  freeImageFormat (localFormat);
307  free (classification);
308  *error = 1;
309  return;
310  }
311 
312  // Reset image format
313  format->numOfScans = 0;
314  format->numOfFrames = 0;
315  format->subWindowSize = 0;
316  format->framesPerScan = 0;
317  format->iXWidth = 0;
318  format->iYWidth = 0;
319 
320  // Loop through the files and analyse
321  while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
322  {
323  sprintf (classification, "%s", "");
324  sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
325  if (diagnostic)cpl_msg_info(cpl_func,"\n Analysing file %s \n", fileNames->inFitsName);
326  fprintf(midiReportPtr, "\n Analysing file %s \n", fileNames->inFitsName);
327 
328  // Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
329  extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
330  if (*error) break;
331 
332  // Get Image Format parameters
333  if (extNumOfImagingDataFile > 0)
334  {
335  getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
336  if (*error) break;
337  }
338  else localFormat->hasData = 0;
339 
340  // Check if the file has data
341  if (localFormat->hasData)
342  {
343  if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
344  (strcmp (localFormat->obsTech, "IMAGE") == 0) &&
345  (strcmp (localFormat->obsType, "BIAS") == 0))
346  {
347  // Increment file counter
348  (*numOfFiles)++;
349 
350  // Log results
351  cpl_msg_info(cpl_func,"File number = %d \n", *numOfFiles);
352  cpl_msg_info(cpl_func,"Observation Category = %s \n", localFormat->obsCatg);
353  cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
354  cpl_msg_info(cpl_func,"Observation Type = %s \n", localFormat->obsType);
355  cpl_msg_info(cpl_func,"Beam Combiner = %s \n", localFormat->beamCombiner);
356  cpl_msg_info(cpl_func,"Shutter ID = %s \n", localFormat->shutterId);
357  cpl_msg_info(cpl_func,"Grism ID = %s \n", localFormat->grismId);
358  cpl_msg_info(cpl_func,"Filter Name = %s \n", localFormat->filterName);
359  cpl_msg_info(cpl_func,"Target Name = %s \n", localFormat->targetName);
360  cpl_msg_info(cpl_func,"Number of Frames = %d \n", localFormat->numOfFrames);
361  cpl_msg_info(cpl_func,"Frames per scan = %d \n", localFormat->framesPerScan);
362  cpl_msg_info(cpl_func,"Number of Scans = %d \n", localFormat->numOfScans);
363  cpl_msg_info(cpl_func,"X, Column dimension = %d \n", localFormat->iXWidth);
364  cpl_msg_info(cpl_func,"Y, Column dimension = %d \n", localFormat->iYWidth);
365  cpl_msg_info(cpl_func,"Sub-window size = %d \n", localFormat->subWindowSize);
366  cpl_msg_info(cpl_func,"\n");
367 
368  fprintf (midiReportPtr, "File number = %d \n", *numOfFiles);
369  fprintf (midiReportPtr, "Observation Category = %s \n", localFormat->obsCatg);
370  fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
371  fprintf (midiReportPtr, "Observation Type = %s \n", localFormat->obsType);
372  fprintf (midiReportPtr, "Beam Combiner = %s \n", localFormat->beamCombiner);
373  fprintf (midiReportPtr, "Shutter ID = %s \n", localFormat->shutterId);
374  fprintf (midiReportPtr, "Grism ID = %s \n", localFormat->grismId);
375  fprintf (midiReportPtr, "Filter Name = %s \n", localFormat->filterName);
376  fprintf (midiReportPtr, "Target Name = %s \n", localFormat->targetName);
377  fprintf (midiReportPtr, "Number of Frames = %d \n", localFormat->numOfFrames);
378  fprintf (midiReportPtr, "Frames per scan = %d \n", localFormat->framesPerScan);
379  fprintf (midiReportPtr, "Number of Scans = %d \n", localFormat->numOfScans);
380  fprintf (midiReportPtr, "X, Column dimension = %d \n", localFormat->iXWidth);
381  fprintf (midiReportPtr, "Y, Column dimension = %d \n", localFormat->iYWidth);
382  fprintf (midiReportPtr, "Sub-window size = %d \n", localFormat->subWindowSize);
383  fprintf (midiReportPtr, "\n");
384 
385  // Compute maximum image format. Save local parameters
386  format->hasData = 1;
387  if (*numOfFiles == 1)
388  {
389  sprintf (format->obsCatg, "%s", localFormat->obsCatg);
390  sprintf (format->obsType, "%s", localFormat->obsType);
391  sprintf (format->obsTech, "%s", localFormat->obsTech);
392  sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
393  sprintf (format->shutterId, "%s", localFormat->shutterId);
394  sprintf (format->grismId, "%s", localFormat->grismId);
395  sprintf (format->targetName, "%s", localFormat->targetName);
396  sprintf (format->tplStart, "%s", localFormat->tplStart);
397  sprintf (format->cameraId, "%s", localFormat->cameraId);
398  sprintf (format->filterName, "%s", localFormat->filterName);
399  }
400 
401  // Save and cummulate size
402  format->numOfFrames += localFormat->numOfFrames;
403  format->subWindowSize = localFormat->subWindowSize;
404  format->iXWidth = localFormat->iXWidth;
405  format->iYWidth = localFormat->iYWidth;
406  }
407  else
408  {
409  sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
410  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
411  }
412  }
413  else
414  {
415  if (diagnostic)
416  {
417  sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
418  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
419  }
420  }
421  }
422 
423  // Check if the FITS files contained useful data
424  if ((*numOfFiles > 0) && !(*error))
425  {
426  cpl_msg_info(cpl_func," Maximum image size \n");
427  cpl_msg_info(cpl_func," ------------------ \n");
428  cpl_msg_info(cpl_func," Number of Frames = %d \n", format->numOfFrames);
429  cpl_msg_info(cpl_func," X, column dimension = %d \n", format->iXWidth);
430  cpl_msg_info(cpl_func," Y, column dimension = %d \n", format->iYWidth);
431  cpl_msg_info(cpl_func," Sub-window size = %d \n", format->subWindowSize);
432  cpl_msg_info(cpl_func," Number of Data Files = %d \n", *numOfFiles);
433  cpl_msg_info(cpl_func,"\n");
434 
435  fprintf (midiReportPtr, " Maximum image size \n");
436  fprintf (midiReportPtr, " ------------------ \n");
437  fprintf (midiReportPtr, " Number of Frames = %d \n", format->numOfFrames);
438  fprintf (midiReportPtr, " X, column dimension = %d \n", format->iXWidth);
439  fprintf (midiReportPtr, " Y, column dimension = %d \n", format->iYWidth);
440  fprintf (midiReportPtr, " Sub-window size = %d \n", format->subWindowSize);
441  fprintf (midiReportPtr, " Number of Data Files = %d \n", *numOfFiles);
442  fprintf (midiReportPtr, "\n");
443  }
444  else
445  {
446  *error = 1;
447  sprintf (fileTemp, "%d", batchNumber);
448  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
449  }
450 
451  // Release memory and close files
452  fclose (inFitsBatchPtr);
453  free (fileTemp);
454  freeImageFormat (localFormat);
455  free (classification);
456 
457  return;
458 }
459 /******************************************************************************/
460 
461 
462 
463 
464 /******************************************************************************
465 * European Southern Observatory
466 * VLTI MIDI Maintenance Templates Software
467 *
468 * Module name: analyseFitsDspTrn
469 * Input/Output: See function arguments to avoid duplication
470 * Description: Analyses all the FITS files in the given list. This routine
471 * determines if the FITS list contains useful data files. If
472 * not it will discard the list.
473 *
474 * History:
475 * 14-Jun-04 (csabet) created
476 ******************************************************************************/
477 void analyseFitsDspTrn (
478  MidiFiles *fileNames, /* IO: Pointer to midi files structure */
479  ImageFormat *format, /* Ou: Pointer to the image format structure */
480  int *numOfFiles, /* Ou: Number of files with data */
481  int *error) /* Ou: Error status */
482 {
483 
484  // Local Declarations
485  // ------------------
486  const char routine[] = "analyseFitsDspTrn";
487  char *fileTemp=NULL, *classification=NULL;
488  FILE *inFitsBatchPtr=NULL;
489  ImageFormat *localFormat=NULL;
490  int extNumOfImagingDataFile;
491 
492  // Algorithm
493  // ---------
494  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
495  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
496 
497  cpl_msg_info(cpl_func,"\nAnalysing batch %d for Dispersive Transmission Assessment \n", batchNumber);
498  cpl_msg_info(cpl_func,"--------------- \n");
499  fprintf (midiReportPtr, "\nAnalysing batch %d for Dispersive Transmission Assessment \n", batchNumber);
500  fprintf (midiReportPtr, "--------------- \n");
501 
502  // Reset status
503  *error = 0;
504  *numOfFiles = 0;
505 
506  // Allocate memory for a temporary file name buffer
507  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
508  fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
509  localFormat = callocImageFormat ();
510 
511  // Open the list of files
512  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
513  {
514  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
515  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
516  free (fileTemp);
517  freeImageFormat (localFormat);
518  free (classification);
519  *error = 1;
520  return;
521  }
522 
523  // Reset image format
524  format->numOfScans = 0;
525  format->numOfFrames = 0;
526  format->subWindowSize = 0;
527  format->framesPerScan = 0;
528  format->iXWidth = 0;
529  format->iYWidth = 0;
530 
531  // Loop through the files and analyse
532  while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
533  {
534  sprintf (classification, "%s", "");
535  sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
536  if (diagnostic)cpl_msg_info(cpl_func,"\n Analysing file %s \n", fileNames->inFitsName);
537  fprintf(midiReportPtr, "\n Analysing file %s \n", fileNames->inFitsName);
538 
539  // Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
540  extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
541  if (*error) break;
542 
543  // Get Image Format parameters
544  if (extNumOfImagingDataFile > 0)
545  {
546  getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
547  if (*error) break;
548  }
549  else localFormat->hasData = 0;
550 
551  // Check if the file has data
552  if (localFormat->hasData)
553  {
554  if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
555  (strcmp (localFormat->obsTech, "SPECTRUM") == 0) &&
556  (strcmp (localFormat->obsType, "WAVE") == 0))
557  {
558  // Increment file counter
559  (*numOfFiles)++;
560 
561  // Log results
562  cpl_msg_info(cpl_func,"File number = %d \n", *numOfFiles);
563  cpl_msg_info(cpl_func,"Observation Category = %s \n", localFormat->obsCatg);
564  cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
565  cpl_msg_info(cpl_func,"Observation Type = %s \n", localFormat->obsType);
566  cpl_msg_info(cpl_func,"Beam Combiner = %s \n", localFormat->beamCombiner);
567  cpl_msg_info(cpl_func,"Shutter ID = %s \n", localFormat->shutterId);
568  cpl_msg_info(cpl_func,"Grism ID = %s \n", localFormat->grismId);
569  cpl_msg_info(cpl_func,"Filter Name = %s \n", localFormat->filterName);
570  cpl_msg_info(cpl_func,"Target Name = %s \n", localFormat->targetName);
571  cpl_msg_info(cpl_func,"Number of Frames = %d \n", localFormat->numOfFrames);
572  cpl_msg_info(cpl_func,"Frames per scan = %d \n", localFormat->framesPerScan);
573  cpl_msg_info(cpl_func,"Number of Scans = %d \n", localFormat->numOfScans);
574  cpl_msg_info(cpl_func,"X, Column dimension = %d \n", localFormat->iXWidth);
575  cpl_msg_info(cpl_func,"Y, Column dimension = %d \n", localFormat->iYWidth);
576  cpl_msg_info(cpl_func,"Sub-window size = %d \n", localFormat->subWindowSize);
577  cpl_msg_info(cpl_func,"\n");
578 
579  fprintf (midiReportPtr, "File number = %d \n", *numOfFiles);
580  fprintf (midiReportPtr, "Observation Category = %s \n", localFormat->obsCatg);
581  fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
582  fprintf (midiReportPtr, "Observation Type = %s \n", localFormat->obsType);
583  fprintf (midiReportPtr, "Beam Combiner = %s \n", localFormat->beamCombiner);
584  fprintf (midiReportPtr, "Shutter ID = %s \n", localFormat->shutterId);
585  fprintf (midiReportPtr, "Grism ID = %s \n", localFormat->grismId);
586  fprintf (midiReportPtr, "Filter Name = %s \n", localFormat->filterName);
587  fprintf (midiReportPtr, "Target Name = %s \n", localFormat->targetName);
588  fprintf (midiReportPtr, "Number of Frames = %d \n", localFormat->numOfFrames);
589  fprintf (midiReportPtr, "Frames per scan = %d \n", localFormat->framesPerScan);
590  fprintf (midiReportPtr, "Number of Scans = %d \n", localFormat->numOfScans);
591  fprintf (midiReportPtr, "X, Column dimension = %d \n", localFormat->iXWidth);
592  fprintf (midiReportPtr, "Y, Column dimension = %d \n", localFormat->iYWidth);
593  fprintf (midiReportPtr, "Sub-window size = %d \n", localFormat->subWindowSize);
594  fprintf (midiReportPtr, "\n");
595 
596  // Compute maximum image format. Save local parameters
597  format->hasData = 1;
598  if (*numOfFiles == 1)
599  {
600  sprintf (format->obsCatg, "%s", localFormat->obsCatg);
601  sprintf (format->obsType, "%s", localFormat->obsType);
602  sprintf (format->obsTech, "%s", localFormat->obsTech);
603  sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
604  sprintf (format->shutterId, "%s", localFormat->shutterId);
605  sprintf (format->grismId, "%s", localFormat->grismId);
606  sprintf (format->targetName, "%s", localFormat->targetName);
607  sprintf (format->tplStart, "%s", localFormat->tplStart);
608  sprintf (format->cameraId, "%s", localFormat->cameraId);
609  sprintf (format->filterName, "%s", localFormat->filterName);
610  }
611 
612  if (localFormat->numOfScans > format->numOfScans)
613  format->numOfScans = localFormat->numOfScans;
614 
615  if (localFormat->numOfFrames > format->numOfFrames)
616  format->numOfFrames = localFormat->numOfFrames;
617 
618  if (localFormat->subWindowSize > format->subWindowSize)
619  format->subWindowSize = localFormat->subWindowSize;
620 
621  if (localFormat->framesPerScan > format->framesPerScan)
622  format->framesPerScan = localFormat->framesPerScan;
623 
624  if (localFormat->iXWidth > format->iXWidth)
625  format->iXWidth = localFormat->iXWidth;
626 
627  if (localFormat->iYWidth > format->iYWidth)
628  format->iYWidth = localFormat->iYWidth;
629  }
630  else
631  {
632  sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
633  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
634  }
635  }
636  else
637  {
638  if (diagnostic)
639  {
640  sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
641  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
642  }
643  }
644  }
645 
646 
647  // Close the file list
648  fclose (inFitsBatchPtr);
649 
650  // Check if the FITS files contained useful data
651  if ((*numOfFiles > 0) && !(*error))
652  {
653  cpl_msg_info(cpl_func," Maximum image size \n");
654  cpl_msg_info(cpl_func," ------------------ \n");
655  cpl_msg_info(cpl_func," Number of Scans = %d \n", format->numOfScans);
656  cpl_msg_info(cpl_func," Number of Frames = %d \n", format->numOfFrames);
657  cpl_msg_info(cpl_func," Frames per scan = %d \n", format->framesPerScan);
658  cpl_msg_info(cpl_func," X, column dimension = %d \n", format->iXWidth);
659  cpl_msg_info(cpl_func," Y, column dimension = %d \n", format->iYWidth);
660  cpl_msg_info(cpl_func," Sub-window size = %d \n", format->subWindowSize);
661  cpl_msg_info(cpl_func," Number of Data Files = %d \n", *numOfFiles);
662  cpl_msg_info(cpl_func,"\n");
663 
664  fprintf (midiReportPtr, " Maximum image size \n");
665  fprintf (midiReportPtr, " ------------------ \n");
666  fprintf (midiReportPtr, " Number of Scans = %d \n", format->numOfScans);
667  fprintf (midiReportPtr, " Number of Frames = %d \n", format->numOfFrames);
668  fprintf (midiReportPtr, " Frames per scan = %d \n", format->framesPerScan);
669  fprintf (midiReportPtr, " X, column dimension = %d \n", format->iXWidth);
670  fprintf (midiReportPtr, " Y, column dimension = %d \n", format->iYWidth);
671  fprintf (midiReportPtr, " Sub-window size = %d \n", format->subWindowSize);
672  fprintf (midiReportPtr, " Number of Data Files = %d \n", *numOfFiles);
673  fprintf (midiReportPtr, "\n");
674  }
675  else
676  {
677  *error = 1;
678  sprintf (fileTemp, "%d", batchNumber);
679  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
680  }
681 
682  // Release memory
683  free (fileTemp);
684  freeImageFormat (localFormat);
685  free (classification);
686 
687  return;
688 }
689 /******************************************************************************/
690 
691 
692 /******************************************************************************
693 * European Southern Observatory
694 * VLTI MIDI Maintenance Templates Software
695 *
696 * Module name: analyseFitsRefPix
697 * Input/Output: See function arguments to avoid duplication
698 * Description: Analyses all the FITS files in the given list. This routine
699 * determines if the FITS list contains useful data files. If
700 * not it will discard the list.
701 *
702 * History:
703 * 14-Jun-04 (csabet) created
704 ******************************************************************************/
705 void analyseFitsRefPix (
706  MidiFiles *fileNames, // IO: Pointer to midi files structure */
707  ImageFormat *format, // Ou: Pointer to the image format structure */
708  int *numOfFiles, // Ou: Number of files with data */
709  int *numOfBeams, // Ou: Maximum number of beams
710  int *error) // Ou: Error status */
711 {
712 
713  // Local Declarations
714  // ------------------
715  const char routine[] = "analyseFitsRefPix";
716  char *fileTemp=NULL, *classification=NULL;
717  FILE *inFitsBatchPtr=NULL;
718  ImageFormat *localFormat=NULL;
719  int extNumOfImagingDataFile;
720 
721  // Algorithm
722  // ---------
723  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
724  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
725 
726  cpl_msg_info(cpl_func,"\nAnalysing batch %d for Reference Pixel Alignment \n", batchNumber);
727  cpl_msg_info(cpl_func,"--------------- \n");
728  fprintf (midiReportPtr, "\nAnalysing batch %d for Reference Pixel Alignment \n", batchNumber);
729  fprintf (midiReportPtr, "--------------- \n");
730 
731  // Reset status
732  *error = 0;
733  *numOfFiles = 0;
734  *numOfBeams = 2;
735 
736  // Allocate memory for a temporary file name buffer
737  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
738  fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
739  localFormat = callocImageFormat ();
740 
741  // Open the list of files
742  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
743  {
744  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
745  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
746  free (fileTemp);
747  freeImageFormat (localFormat);
748  free (classification);
749  *error = 1;
750  return;
751  }
752 
753  // Reset image format
754  format->numOfScans = 0;
755  format->numOfFrames = 0;
756  format->subWindowSize = 0;
757  format->framesPerScan = 0;
758  format->iXWidth = 0;
759  format->iYWidth = 0;
760 
761  // Loop through the files and analyse
762  while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
763  {
764  sprintf (classification, "%s", "");
765  sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
766  if (diagnostic)cpl_msg_info(cpl_func,"\n Analysing file %s \n", fileNames->inFitsName);
767  fprintf(midiReportPtr, "\n Analysing file %s \n", fileNames->inFitsName);
768 
769  // Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
770  extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
771  if (*error) break;
772 
773  // Get Image Format parameters
774  if (extNumOfImagingDataFile > 0)
775  {
776  getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
777  if (*error) break;
778  }
779  else localFormat->hasData = 0;
780 
781  // Check if the file has data
782  if (localFormat->hasData)
783  {
784  if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
785  (strcmp (localFormat->obsTech, "IMAGE") == 0) &&
786  (strcmp (localFormat->obsType, "FMTCHCK") == 0))
787  {
788  // Increment file counter
789  (*numOfFiles)++;
790 
791  // Compute maximum number of beams per exposure
792  if (strcmp (localFormat->beamCombiner, "SCI_PHOT") == 0) *numOfBeams = 3;
793 
794  // Log results
795  cpl_msg_info(cpl_func,"File number = %d \n", *numOfFiles);
796  cpl_msg_info(cpl_func,"Observation Category = %s \n", localFormat->obsCatg);
797  cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
798  cpl_msg_info(cpl_func,"Observation Type = %s \n", localFormat->obsType);
799  cpl_msg_info(cpl_func,"Beam Combiner = %s \n", localFormat->beamCombiner);
800  cpl_msg_info(cpl_func,"Shutter ID = %s \n", localFormat->shutterId);
801  cpl_msg_info(cpl_func,"Grism ID = %s \n", localFormat->grismId);
802  cpl_msg_info(cpl_func,"Filter Name = %s \n", localFormat->filterName);
803  cpl_msg_info(cpl_func,"Target Name = %s \n", localFormat->targetName);
804  cpl_msg_info(cpl_func,"Number of Frames = %d \n", localFormat->numOfFrames);
805  cpl_msg_info(cpl_func,"Frames per scan = %d \n", localFormat->framesPerScan);
806  cpl_msg_info(cpl_func,"Number of Scans = %d \n", localFormat->numOfScans);
807  cpl_msg_info(cpl_func,"X, Column dimension = %d \n", localFormat->iXWidth);
808  cpl_msg_info(cpl_func,"Y, Column dimension = %d \n", localFormat->iYWidth);
809  cpl_msg_info(cpl_func,"Sub-window size = %d \n", localFormat->subWindowSize);
810  cpl_msg_info(cpl_func,"\n");
811 
812  fprintf (midiReportPtr, "File number = %d \n", *numOfFiles);
813  fprintf (midiReportPtr, "Observation Category = %s \n", localFormat->obsCatg);
814  fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
815  fprintf (midiReportPtr, "Observation Type = %s \n", localFormat->obsType);
816  fprintf (midiReportPtr, "Beam Combiner = %s \n", localFormat->beamCombiner);
817  fprintf (midiReportPtr, "Shutter ID = %s \n", localFormat->shutterId);
818  fprintf (midiReportPtr, "Grism ID = %s \n", localFormat->grismId);
819  fprintf (midiReportPtr, "Filter Name = %s \n", localFormat->filterName);
820  fprintf (midiReportPtr, "Target Name = %s \n", localFormat->targetName);
821  fprintf (midiReportPtr, "Number of Frames = %d \n", localFormat->numOfFrames);
822  fprintf (midiReportPtr, "Frames per scan = %d \n", localFormat->framesPerScan);
823  fprintf (midiReportPtr, "Number of Scans = %d \n", localFormat->numOfScans);
824  fprintf (midiReportPtr, "X, Column dimension = %d \n", localFormat->iXWidth);
825  fprintf (midiReportPtr, "Y, Column dimension = %d \n", localFormat->iYWidth);
826  fprintf (midiReportPtr, "Sub-window size = %d \n", localFormat->subWindowSize);
827  fprintf (midiReportPtr, "\n");
828 
829  // Compute maximum image format. Save local parameters
830  format->hasData = 1;
831  if (*numOfFiles == 1)
832  {
833  sprintf (format->obsCatg, "%s", localFormat->obsCatg);
834  sprintf (format->obsType, "%s", localFormat->obsType);
835  sprintf (format->obsTech, "%s", localFormat->obsTech);
836  sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
837  sprintf (format->shutterId, "%s", localFormat->shutterId);
838  sprintf (format->grismId, "%s", localFormat->grismId);
839  sprintf (format->targetName, "%s", localFormat->targetName);
840  sprintf (format->tplStart, "%s", localFormat->tplStart);
841  sprintf (format->cameraId, "%s", localFormat->cameraId);
842  sprintf (format->filterName, "%s", localFormat->filterName);
843  }
844 
845  if (localFormat->numOfScans > format->numOfScans)
846  format->numOfScans = localFormat->numOfScans;
847 
848  if (localFormat->numOfFrames > format->numOfFrames)
849  format->numOfFrames = localFormat->numOfFrames;
850 
851  if (localFormat->subWindowSize > format->subWindowSize)
852  format->subWindowSize = localFormat->subWindowSize;
853 
854  if (localFormat->framesPerScan > format->framesPerScan)
855  format->framesPerScan = localFormat->framesPerScan;
856 
857  if (localFormat->iXWidth > format->iXWidth)
858  format->iXWidth = localFormat->iXWidth;
859 
860  if (localFormat->iYWidth > format->iYWidth)
861  format->iYWidth = localFormat->iYWidth;
862  }
863  else
864  {
865  sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
866  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
867  }
868  }
869  else
870  {
871  if (diagnostic)
872  {
873  sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
874  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
875  }
876  }
877  }
878 
879 
880  // Close the file list
881  fclose (inFitsBatchPtr);
882 
883  // Check if the FITS files contained useful data
884  if ((*numOfFiles > 0) && !(*error))
885  {
886  cpl_msg_info(cpl_func," Maximum image size \n");
887  cpl_msg_info(cpl_func," ------------------ \n");
888  cpl_msg_info(cpl_func," Number of Scans = %d \n", format->numOfScans);
889  cpl_msg_info(cpl_func," Number of Frames = %d \n", format->numOfFrames);
890  cpl_msg_info(cpl_func," Frames per scan = %d \n", format->framesPerScan);
891  cpl_msg_info(cpl_func," Number of Beams = %d \n", *numOfBeams);
892  cpl_msg_info(cpl_func," X, column dimension = %d \n", format->iXWidth);
893  cpl_msg_info(cpl_func," Y, column dimension = %d \n", format->iYWidth);
894  cpl_msg_info(cpl_func," Sub-window size = %d \n", format->subWindowSize);
895  cpl_msg_info(cpl_func," Number of Data Files = %d \n", *numOfFiles);
896  cpl_msg_info(cpl_func,"\n");
897 
898  fprintf (midiReportPtr, " Maximum image size \n");
899  fprintf (midiReportPtr, " ------------------ \n");
900  fprintf (midiReportPtr, " Number of Scans = %d \n", format->numOfScans);
901  fprintf (midiReportPtr, " Number of Frames = %d \n", format->numOfFrames);
902  fprintf (midiReportPtr, " Frames per scan = %d \n", format->framesPerScan);
903  fprintf (midiReportPtr, " Number of Beams = %d \n", *numOfBeams);
904  fprintf (midiReportPtr, " X, column dimension = %d \n", format->iXWidth);
905  fprintf (midiReportPtr, " Y, column dimension = %d \n", format->iYWidth);
906  fprintf (midiReportPtr, " Sub-window size = %d \n", format->subWindowSize);
907  fprintf (midiReportPtr, " Number of Data Files = %d \n", *numOfFiles);
908  fprintf (midiReportPtr, "\n");
909  }
910  else
911  {
912  *error = 1;
913  sprintf (fileTemp, "%d", batchNumber);
914  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
915  }
916 
917  // Release memory
918  free (fileTemp);
919  freeImageFormat (localFormat);
920  free (classification);
921 
922  return;
923 }
924 /******************************************************************************/
925 
926 
927 
928 /******************************************************************************
929 * European Southern Observatory
930 * VLTI MIDI Maintenance Templates Software
931 *
932 * Module name: analyseFitsWaveCal
933 * Input/Output: See function arguments to avoid duplication
934 * Description: Analyses all the FITS files in the given list. This routine
935 * determines if the FITS list contains useful data files. If
936 * not it will discard the list.
937 *
938 * History:
939 * 10-Jun-05 (csabet) created
940 ******************************************************************************/
941 void analyseFitsWaveCal (
942  MidiFiles *fileNames, // IO: Pointer to midi files structure
943  ImageFormat *format, // Ou: Pointer to the image format structure
944  int *numOfFiles, // Ou: Number of files with data
945  int *error) // Ou: Error status
946 {
947 
948  // Local Declarations
949  // ------------------
950  const char routine[] = "analyseFitsWaveCal";
951  char *fileTemp=NULL, *classification=NULL;
952  FILE *inFitsBatchPtr=NULL;
953  ImageFormat *localFormat=NULL;
954  int extNumOfImagingDataFile;
955 
956  // Algorithm
957  // ---------
958  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
959  if (diagnostic > 4) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
960 
961  cpl_msg_info(cpl_func,"\nAnalysing batch %d for Wavelength Calibration \n", batchNumber);
962  cpl_msg_info(cpl_func,"--------------- \n");
963  fprintf (midiReportPtr, "\nAnalysing batch %d for Wavelength Calibration \n", batchNumber);
964  fprintf (midiReportPtr, "--------------- \n");
965 
966  // Reset status
967  *error = 0;
968  *numOfFiles = 0;
969 
970  // Allocate memory for a temporary file name buffer
971  classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
972  fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
973  localFormat = callocImageFormat ();
974 
975  // Open the list of files
976  if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
977  {
978  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
979  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
980  free (fileTemp);
981  freeImageFormat (localFormat);
982  free (classification);
983  *error = 1;
984  return;
985  }
986 
987  // Reset image format
988  format->hasData = 0;
989  format->numOfDetectorRegions = 0;
990  format->numOfRegionsToProcess = 0;
991  format->numOfPinholes = 0;
992  format->numOfFrames = 0;
993  format->framesPerScan = 0;
994  format->numOfScans = 0;
995  format->subWindowSize = 0;
996  format->iXWidth = 0;
997  format->iYWidth = 0;
998 
999  // Loop through the files and analyse
1000  while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
1001  {
1002  sprintf (classification, "%s", "");
1003  sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
1004  if (diagnostic)cpl_msg_info(cpl_func,"\n Analysing file %s \n", fileNames->inFitsName);
1005  fprintf(midiReportPtr, "\n Analysing file %s \n", fileNames->inFitsName);
1006 
1007  // Get 'extNumOfImagingDataFile' extension number of IMAGING_DATA in input file
1008  extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
1009  if (*error) break;
1010 
1011  // Get Image Format parameters
1012  if (extNumOfImagingDataFile > 0)
1013  {
1014  getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
1015  if (*error) break;
1016  }
1017  else localFormat->hasData = 0;
1018 
1019  // Check if the file has data
1020  if (localFormat->hasData)
1021  {
1022  if ((strcmp (localFormat->obsCatg, "CALIB") == 0) &&
1023  (strcmp (localFormat->obsTech, "SPECTRUM") == 0) &&
1024  (strcmp (localFormat->obsType, "WAVE,SPECTEMPL") == 0))
1025  {
1026  // Increment file counter
1027  (*numOfFiles)++;
1028 
1029  // Log results
1030  cpl_msg_info(cpl_func,"File number = %d \n", *numOfFiles);
1031  cpl_msg_info(cpl_func,"Observation Category = %s \n", localFormat->obsCatg);
1032  cpl_msg_info(cpl_func,"Observation Technique = %s \n", localFormat->obsTech);
1033  cpl_msg_info(cpl_func,"Observation Type = %s \n", localFormat->obsType);
1034  cpl_msg_info(cpl_func,"Beam Combiner = %s \n", localFormat->beamCombiner);
1035  cpl_msg_info(cpl_func,"Shutter ID = %s \n", localFormat->shutterId);
1036  cpl_msg_info(cpl_func,"Filter Name = %s \n", localFormat->filterName);
1037  cpl_msg_info(cpl_func,"Grism ID = %s \n", localFormat->grismId);
1038  cpl_msg_info(cpl_func,"Target Name = %s \n", localFormat->targetName);
1039  cpl_msg_info(cpl_func,"Number of Frames = %d \n", localFormat->numOfFrames);
1040  cpl_msg_info(cpl_func,"Frames per scan = %d \n", localFormat->framesPerScan);
1041  cpl_msg_info(cpl_func,"Number of Scans = %d \n", localFormat->numOfScans);
1042  cpl_msg_info(cpl_func,"X, Column dimension = %d \n", localFormat->iXWidth);
1043  cpl_msg_info(cpl_func,"Y, Column dimension = %d \n", localFormat->iYWidth);
1044  cpl_msg_info(cpl_func,"Sub-window size = %d \n", localFormat->subWindowSize);
1045  cpl_msg_info(cpl_func,"\n");
1046 
1047  fprintf (midiReportPtr, "File number = %d \n", *numOfFiles);
1048  fprintf (midiReportPtr, "Observation Category = %s \n", localFormat->obsCatg);
1049  fprintf (midiReportPtr, "Observation Technique = %s \n", localFormat->obsTech);
1050  fprintf (midiReportPtr, "Observation Type = %s \n", localFormat->obsType);
1051  fprintf (midiReportPtr, "Beam Combiner = %s \n", localFormat->beamCombiner);
1052  fprintf (midiReportPtr, "Shutter ID = %s \n", localFormat->shutterId);
1053  fprintf (midiReportPtr, "Filter Name = %s \n", localFormat->filterName);
1054  fprintf (midiReportPtr, "Grism ID = %s \n", localFormat->grismId);
1055  fprintf (midiReportPtr, "Target Name = %s \n", localFormat->targetName);
1056  fprintf (midiReportPtr, "Number of Frames = %d \n", localFormat->numOfFrames);
1057  fprintf (midiReportPtr, "Frames per scan = %d \n", localFormat->framesPerScan);
1058  fprintf (midiReportPtr, "Number of Scans = %d \n", localFormat->numOfScans);
1059  fprintf (midiReportPtr, "X, Column dimension = %d \n", localFormat->iXWidth);
1060  fprintf (midiReportPtr, "Y, Column dimension = %d \n", localFormat->iYWidth);
1061  fprintf (midiReportPtr, "Sub-window size = %d \n", localFormat->subWindowSize);
1062  fprintf (midiReportPtr, "\n");
1063 
1064  // Save local parameters
1065  if (*numOfFiles == 1)
1066  {
1067  format->hasData = 1;
1068  sprintf (format->obsCatg, "%s", localFormat->obsCatg);
1069  sprintf (format->obsTech, "%s", localFormat->obsTech);
1070  sprintf (format->obsType, "%s", localFormat->obsType);
1071  sprintf (format->cameraId, "%s", localFormat->cameraId);
1072  sprintf (format->beamCombiner, "%s", localFormat->beamCombiner);
1073  sprintf (format->filterName, "%s", localFormat->filterName);
1074  sprintf (format->shutterId, "%s", localFormat->shutterId);
1075  sprintf (format->grismId, "%s", localFormat->grismId);
1076  sprintf (format->targetName, "%s", localFormat->targetName);
1077  sprintf (format->slitName, "%s", localFormat->slitName);
1078  sprintf (format->tplStart, "%s", localFormat->tplStart);
1079  sprintf (format->tplName, "%s", localFormat->tplName);
1080  format->numOfDetectorRegions = localFormat->numOfDetectorRegions;
1081  format->numOfRegionsToProcess = localFormat->numOfRegionsToProcess;
1082  format->numOfPinholes = localFormat->numOfPinholes;
1083  format->framesPerScan = localFormat->framesPerScan;
1084  format->subWindowSize = localFormat->subWindowSize;
1085  format->iXWidth = localFormat->iXWidth;
1086  format->iYWidth = localFormat->iYWidth;
1087  format->numOfFrames = localFormat->numOfFrames;
1088  format->subWindowSize = localFormat->subWindowSize;
1089  }
1090  else // Check consistency
1091  {
1092  if (strcmp (format->obsCatg, localFormat->obsCatg) != 0) *error = 1;
1093  if (strcmp (format->obsTech, localFormat->obsTech) != 0) *error = 1;
1094  if (strcmp (format->obsType, localFormat->obsType) != 0) *error = 1;
1095  if (strcmp (format->cameraId, localFormat->cameraId) != 0) *error = 1;
1096  if (strcmp (format->beamCombiner, localFormat->beamCombiner) != 0) *error = 1;
1097  if (strcmp (format->grismId, localFormat->grismId) != 0) *error = 1;
1098  if (strcmp (format->targetName, localFormat->targetName) != 0) *error = 1;
1099  if (strcmp (format->slitName, localFormat->slitName) != 0) *error = 1;
1100  if (strcmp (format->tplStart, localFormat->tplStart) != 0) *error = 1;
1101  if (strcmp (format->tplName, localFormat->tplName) != 0) *error = 1;
1102  if (format->numOfDetectorRegions != localFormat->numOfDetectorRegions) *error = 1;
1103  if (format->numOfRegionsToProcess != localFormat->numOfRegionsToProcess) *error = 1;
1104  if (format->numOfPinholes != localFormat->numOfPinholes) *error = 1;
1105  if (format->framesPerScan != localFormat->framesPerScan) *error = 1;
1106  if (format->subWindowSize != localFormat->subWindowSize) *error = 1;
1107  if (format->iXWidth != localFormat->iXWidth) *error = 1;
1108  if (format->iYWidth != localFormat->iYWidth) *error = 1;
1109  if (format->numOfFrames != localFormat->numOfFrames) *error = 1;
1110  if (format->subWindowSize != localFormat->subWindowSize) *error = 1;
1111  }
1112  if (*error)
1113  {
1114  sprintf (midiMessage, "Inconsistent FITS files. %s", fileNames->inFitsName);
1115  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
1116  }
1117  }
1118  else
1119  {
1120  sprintf (midiMessage, "Unknown Category, Tech or Type %s Not processed", fileNames->inFitsName);
1121  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
1122  }
1123  }
1124  else
1125  {
1126  if (diagnostic)
1127  {
1128  sprintf (midiMessage, "No data tables in %s. Not processed", fileNames->inFitsName);
1129  midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
1130  }
1131  }
1132  }
1133 
1134 
1135  // Close the file list
1136  fclose (inFitsBatchPtr);
1137 
1138  // Check if the FITS files contained useful data
1139  if ((*numOfFiles > 0) && !(*error))
1140  {
1141  cpl_msg_info(cpl_func," Maximum image size \n");
1142  cpl_msg_info(cpl_func," ------------------ \n");
1143  cpl_msg_info(cpl_func," Number of Scans = %d \n", format->numOfScans);
1144  cpl_msg_info(cpl_func," Number of Frames = %d \n", format->numOfFrames);
1145  cpl_msg_info(cpl_func," Frames per scan = %d \n", format->framesPerScan);
1146  cpl_msg_info(cpl_func," X, column dimension = %d \n", format->iXWidth);
1147  cpl_msg_info(cpl_func," Y, column dimension = %d \n", format->iYWidth);
1148  cpl_msg_info(cpl_func," Number of Regions = %d \n", format->numOfDetectorRegions);
1149  cpl_msg_info(cpl_func," Sub-window size = %d \n", format->subWindowSize);
1150  cpl_msg_info(cpl_func," Number of Data Files = %d \n", *numOfFiles);
1151  cpl_msg_info(cpl_func,"\n");
1152 
1153  fprintf (midiReportPtr, " Maximum image size \n");
1154  fprintf (midiReportPtr, " ------------------ \n");
1155  fprintf (midiReportPtr, " Number of Scans = %d \n", format->numOfScans);
1156  fprintf (midiReportPtr, " Number of Frames = %d \n", format->numOfFrames);
1157  fprintf (midiReportPtr, " Frames per scan = %d \n", format->framesPerScan);
1158  fprintf (midiReportPtr, " X, column dimension = %d \n", format->iXWidth);
1159  fprintf (midiReportPtr, " Y, column dimension = %d \n", format->iYWidth);
1160  fprintf (midiReportPtr, " Number of Regions = %d \n", format->numOfDetectorRegions);
1161  fprintf (midiReportPtr, " Sub-window size = %d \n", format->subWindowSize);
1162  fprintf (midiReportPtr, " Number of Data Files = %d \n", *numOfFiles);
1163  fprintf (midiReportPtr, "\n");
1164  }
1165  else
1166  {
1167  *error = 1;
1168  sprintf (fileTemp, "%d", batchNumber);
1169  midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
1170  }
1171 
1172  // Release memory
1173  free (fileTemp);
1174  freeImageFormat (localFormat);
1175  free (classification);
1176 
1177  return;
1178 }
1179 /******************************************************************************/
1180