00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <stdio.h>
00023 #include <cpl.h>
00024 #include <math.h>
00025 #include "midiGlobal.h"
00026 #include "midiLib.h"
00027 #include "fft.h"
00028 #include "errorHandling.h"
00029 #include "memoryHandling.h"
00030 #include "midiFitsUtility.h"
00031 #include "fitsAnalysisFrgSP.h"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 void analyseFitsFrgSP (
00058 MidiFiles *fileNames,
00059 ImageFormat *formatInterf,
00060 ImageFormat *formatPhotomA,
00061 ImageFormat *formatPhotomB,
00062 int *error)
00063 {
00064
00065
00066
00067 const char routine[] = "analyseFitsFrgSP";
00068 char *fileTemp, *classification;
00069 FILE *inFitsBatchPtr=NULL;
00070 int extNumOfImagingDataFile, aprioriDataIsDisp=0;
00071 ImageFormat *localFormat=NULL;
00072 char *cleanString=NULL, *aprioriCatg=NULL;
00073 unsigned int numOfInterf;
00074
00075
00076
00077 if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
00078 if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
00079
00080 cpl_msg_info(cpl_func,"\nAnalysing batch %d \n", batchNumber);
00081 cpl_msg_info(cpl_func,"--------------- \n");
00082 fprintf (midiReportPtr, "\nAnalysing batch %d \n", batchNumber);
00083 fprintf (midiReportPtr, "--------------- \n");
00084
00085
00086 *error = 0;
00087
00088
00089 classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00090 cleanString = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00091 fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00092 aprioriCatg = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00093 localFormat = callocImageFormat ();
00094
00095
00096 if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00097 {
00098 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
00099 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "No analysis has been carried out for this batch");
00100 free (fileTemp);
00101 free (cleanString);
00102 freeImageFormat (localFormat);
00103 free (classification);
00104 *error = 1;
00105 return;
00106 }
00107
00108
00109 numOfInterf = 0;
00110 midiInitFormat (formatInterf);
00111
00112
00113 while (fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
00114 {
00115 sprintf (classification, "%s", "");
00116 sscanf (fileTemp, "%s%s", fileNames->inFitsName, classification);
00117 if (diagnostic)cpl_msg_info(cpl_func,"\nAnalysing file %s \n", fileNames->inFitsName);
00118 fprintf(midiReportPtr, "\nAnalysing file %s \n", fileNames->inFitsName);
00119
00120
00121 extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
00122 if (*error) break;
00123
00124
00125 if (extNumOfImagingDataFile > 0)
00126 {
00127 getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
00128 if (*error) break;
00129 }
00130 else localFormat->hasData = 0;
00131
00132
00133 if (localFormat->hasData)
00134 {
00135
00136 if (numOfInterf == 0)
00137 {
00138 aprioriDataIsDisp = localFormat->isDisp;
00139 sprintf (aprioriCatg, "%s", localFormat->obsCatg);
00140 }
00141
00142
00143 if (localFormat->isDisp != aprioriDataIsDisp)
00144 {
00145 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent Beam Combiner");
00146 *error = 1;
00147 break;
00148 }
00149 else
00150 aprioriDataIsDisp = localFormat->isDisp;
00151
00152
00153 if (strcmp (localFormat->obsCatg, aprioriCatg) != 0)
00154 {
00155 sprintf (midiMessage, "Inconsistent Observation Category. Expected: %s", aprioriCatg);
00156 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00157 *error = 1;
00158 break;
00159 }
00160 else
00161 sprintf (aprioriCatg, "%s", localFormat->obsCatg);
00162
00163
00164 if (strcmp (localFormat->obsTech, "INTERFEROMETRY") == 0)
00165 {
00166
00167 if (numOfInterf == 0)
00168 {
00169 formatInterf->hasData = 1;
00170 formatInterf->chopped = 1;
00171 midiCopyFormat (localFormat, formatInterf);
00172
00173 formatPhotomA->hasData = 1;
00174 formatPhotomA->chopped = 1;
00175 midiCopyFormat (localFormat, formatPhotomA);
00176 formatPhotomA->numOfRegionsToProcess = 1;
00177
00178 formatPhotomB->hasData = 1;
00179 formatPhotomB->chopped = 1;
00180 midiCopyFormat (localFormat, formatPhotomB);
00181 formatPhotomB->numOfRegionsToProcess = 1;
00182 }
00183
00184
00185 formatInterf->numOfFrames += localFormat->numOfFrames;
00186 formatPhotomA->numOfFrames += localFormat->numOfFrames;
00187 formatPhotomB->numOfFrames += localFormat->numOfFrames;
00188
00189
00190 ++numOfInterf;
00191 }
00192 else if (strcmp (localFormat->obsTech, "IMAGE,WINDOW,CHOPNOD") == 0)
00193 {
00194 if (diagnostic > 1) midiReportInfo (midiReportPtr,
00195 routine, __FILE__, __LINE__, "The above Photometry file will not be processed");
00196 }
00197 else
00198 {
00199 sprintf (midiMessage, "Unknown Category, Tech or Type in ... %s. Not processed",
00200 fileNames->inFitsName);
00201 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00202 }
00203 }
00204 else
00205 {
00206 if (diagnostic)
00207 {
00208 sprintf (midiMessage, "No data tables in ... %s. Not processed", fileNames->inFitsName);
00209 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00210 }
00211 }
00212 }
00213
00214
00215 if (fclose (inFitsBatchPtr))
00216 midiReportError (midiReportPtr, routine, __FILE__, __LINE__, "Cannot close batch file");
00217
00218
00219 if (!(*error) && (numOfInterf > 0))
00220 {
00221
00222 if ((formatInterf->framesPerScan == 0) || (formatPhotomA->framesPerScan == 0) ||
00223 (formatPhotomB->framesPerScan == 0))
00224 {
00225 if (fileTemp) free (fileTemp);
00226 if (localFormat) freeImageFormat (localFormat);
00227 if (cleanString) free (cleanString);
00228 if (classification) free (classification);
00229 if (aprioriCatg) free (aprioriCatg);
00230 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Potential singularity detected");
00231 *error = 1;
00232 return;
00233 }
00234
00235
00236 formatInterf->numOfScans = formatInterf->numOfFrames / formatInterf->framesPerScan;
00237 formatPhotomA->numOfScans = formatPhotomA->numOfFrames / formatPhotomA->framesPerScan;
00238 formatPhotomB->numOfScans = formatPhotomB->numOfFrames / formatPhotomB->framesPerScan;
00239
00240
00241 formatInterf->numOfFrames = formatInterf->numOfScans * formatInterf->framesPerScan;
00242 formatPhotomA->numOfFrames = formatPhotomA->numOfScans * formatPhotomA->framesPerScan;
00243 formatPhotomB->numOfFrames = formatPhotomB->numOfScans * formatPhotomB->framesPerScan;
00244
00245
00246 formatInterf->fftsize = determineFFTsize (formatInterf->framesPerScan);
00247
00248
00249 formatInterf->allSpectrumLength = REGIONS_UNDISPERSED * formatInterf->numOfScans * (formatInterf->fftsize/2);
00250
00251
00252 midiReportFormat ("INTERFEROMETRY", aprioriDataIsDisp, formatInterf);
00253 midiReportFormat ("PHOTOMETRY A", aprioriDataIsDisp, formatPhotomA);
00254 midiReportFormat ("PHOTOMETRY B", aprioriDataIsDisp, formatPhotomB);
00255
00256 sprintf (midiMessage, "Detected %d Interferometry files", numOfInterf);
00257 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00258 }
00259 else
00260 {
00261 sprintf (fileTemp, "%d", batchNumber);
00262 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent batch files");
00263 *error = 1;
00264 }
00265
00266
00267 if (!(*error))
00268 {
00269 if (!aprioriDataIsDisp)
00270 {
00271 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
00272 "Data is UNDISPERSED\n Algorithm for processing this type of data is not ready");
00273 *error = 1;
00274 }
00275 }
00276
00277
00278 if (fileTemp) free (fileTemp);
00279 if (localFormat) freeImageFormat (localFormat);
00280 if (cleanString) free (cleanString);
00281 if (classification) free (classification);
00282 if (aprioriCatg) free (aprioriCatg);
00283
00284 return;
00285 }
00286
00287