18 #define SIMULATE_DATA_x // Only used when proper data was not available
26 #include "midiGlobal.h"
28 #include "memoryHandling.h"
29 #include "errorHandling.h"
30 #include "midiFitsUtility.h"
31 #include "diagnostics.h"
32 #include "preProcKappa.h"
59 FilterData *filterInfo,
61 CompressedData *compressedInterfA,
62 CompressedData *compressedInterfB,
63 CompressedData *compressedPhotomA,
64 CompressedData *compressedPhotomB,
65 ImageFormat *formatInterfA,
66 ImageFormat *formatInterfB,
67 ImageFormat *formatPhotomA,
68 ImageFormat *formatPhotomB,
74 const char routine[] =
"preProcKappa";
75 FILE *inFitsBatchPtr=NULL;
76 int newFile, extNumOfImagingDataFile, extNumOfImagingDataMask, R;
77 char *maskFile, *cleanString, *classification, *stringTemp, *fileName, *title;
78 unsigned int loopCount = 0;
79 ImageFormat *localFormat;
80 enum ObsTechnique obsTech;
84 if (diagnostic > 4)cpl_msg_info(cpl_func,
"Invoking routine '%s' \n", routine);
85 if (diagnostic > 4) fprintf(midiReportPtr,
"Invoking routine '%s' \n", routine);
87 cpl_msg_info(cpl_func,
"\nReducing data of batch %d \n", batchNumber);
88 cpl_msg_info(cpl_func,
"---------------------- \n");
89 fprintf (midiReportPtr,
"\nReducing data of batch %d \n", batchNumber);
90 fprintf (midiReportPtr,
"---------------------- \n");
94 compressedInterfA->exists = 0;
95 compressedInterfB->exists = 0;
96 compressedPhotomA->exists = 0;
97 compressedPhotomB->exists = 0;
102 stringTemp = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
103 classification = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
104 cleanString = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
105 localFormat = callocImageFormat ();
106 maskFile = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
109 if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch,
"r")) == NULL)
111 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
112 "Cannot open input FITS file list. No compression has been carried out for this batch");
116 free (classification);
117 freeImageFormat (localFormat);
123 while (fgets (stringTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
125 sprintf (classification,
"%s",
"");
126 sscanf (stringTemp,
"%s%s", fileNames->inFitsName, classification);
127 cpl_msg_info(cpl_func,
"\nProcessing file %s \n", fileNames->inFitsName);
128 fprintf (midiReportPtr,
"\nProcessing file %s \n", fileNames->inFitsName);
131 extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
135 if (extNumOfImagingDataFile > 0)
137 getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
140 else localFormat->hasData = 0;
145 getFilterData (fileNames->inFitsName, filterInfo, error);
147 else fprintf (midiReportPtr,
"First file of batch = %s (QCLOG)\n", fileNames->inFitsName);
150 selectMask (options->maskMode, fileNames, maskFile, error);
154 extNumOfImagingDataMask = findImagingDataExtension (maskFile, MASK_IMAGING_DATA, error);
157 cpl_msg_info(cpl_func,
"Mask File is %s\n", maskFile);
158 fprintf( midiReportPtr,
"Mask File is %s\n", maskFile);
162 if (localFormat->hasData)
165 if ((strcmp (localFormat->obsTech,
"INTERFEROMETRY") == 0))
167 if (diagnostic > 1) midiReportInfo (midiReportPtr,
168 routine, __FILE__, __LINE__,
"The above Interferometry file will not be processed");
171 else if ((strcmp (localFormat->obsTech,
"IMAGE,WINDOW,CHOPNOD") == 0) &&
172 (strcmp(localFormat->shutterId,
"AOPEN") == 0))
175 if (obsTech != PHOTOMA) newFile = 1;
182 if ((formatPhotomA->numOfDetectorRegions != localFormat->numOfDetectorRegions) ||
183 (formatPhotomA->iXWidth != localFormat->iXWidth) ||
184 (formatPhotomA->iYWidth != localFormat->iYWidth))
186 midiReportWarning (midiReportPtr,
187 routine, __FILE__, __LINE__,
"Expected format is incorrect");
194 organiseKappa (
"AOPEN", newFile, extNumOfImagingDataFile, fileNames,
195 extNumOfImagingDataMask, maskFile, localFormat, formatInterfA,
196 compressedInterfA, compressedPhotomA, error);
200 else if ((strcmp (localFormat->obsTech,
"IMAGE,WINDOW,CHOPNOD") == 0) &&
201 (strcmp(localFormat->shutterId,
"BOPEN") == 0))
204 if (obsTech != PHOTOMB) newFile = 1;
211 if ((formatPhotomA->numOfDetectorRegions != localFormat->numOfDetectorRegions) ||
212 (formatPhotomA->iXWidth != localFormat->iXWidth) ||
213 (formatPhotomA->iYWidth != localFormat->iYWidth))
215 midiReportWarning (midiReportPtr,
216 routine, __FILE__, __LINE__,
"Expected format is incorrect");
223 organiseKappa (
"BOPEN", newFile, extNumOfImagingDataFile, fileNames,
224 extNumOfImagingDataMask, maskFile, localFormat, formatInterfB,
225 compressedInterfB, compressedPhotomB, error);
231 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Unknown Catg, Type or Tech");
238 sprintf (midiMessage,
"No data tables in %s. Not processed", fileNames->inFitsName);
239 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
245 fclose (inFitsBatchPtr);
248 free (classification);
249 freeImageFormat (localFormat);
253 cpl_msg_info(cpl_func,
"\nCompression status \n");
254 cpl_msg_info(cpl_func,
"------------------ \n");
255 if (compressedInterfA->exists)cpl_msg_info(cpl_func,
"Created Compressed Interferometry A Data\n");
256 if (compressedInterfB->exists)cpl_msg_info(cpl_func,
"Created Compressed Interferometry B Data\n");
257 if (compressedPhotomA->exists)cpl_msg_info(cpl_func,
"Created Compressed Photometry A Data\n");
258 if (compressedPhotomB->exists)cpl_msg_info(cpl_func,
"Created Compressed Photometry B Data\n");
259 cpl_msg_info(cpl_func,
"\n");
261 fprintf (midiReportPtr,
"\nCompression status \n");
262 fprintf (midiReportPtr,
"------------------ \n");
263 if (compressedInterfA->exists) fprintf (midiReportPtr,
"Created Compressed Interferometry A Data\n");
264 if (compressedInterfA->exists) fprintf (midiReportPtr,
"Created Compressed Interferometry B Data\n");
265 if (compressedPhotomA->exists) fprintf (midiReportPtr,
"Created Compressed Photometry A Data\n");
266 if (compressedPhotomB->exists) fprintf (midiReportPtr,
"Created Compressed Photometry B Data\n");
267 fprintf (midiReportPtr,
"\n");
269 if (!(compressedInterfA->exists) || !(compressedInterfB->exists) ||
270 !(compressedPhotomA->exists) || !(compressedPhotomB->exists) || *error)
273 sprintf (midiMessage,
274 "Cannot continue. Need the following compressed data: InterfA, InterfB, PhotomA, PhotomB");
275 midiReportWarning (midiReportPtr,
276 routine, __FILE__, __LINE__, midiMessage);
281 if (diagnostic > 1 && plotFile)
283 fileName = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
284 title = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
286 for (R = 0; R < formatInterfA->numOfRegionsToProcess; R++)
288 sprintf (fileName,
"3dInterfADATA%d", R+2);
289 sprintf (title,
"Interferometry A DATA %d (Masked and Sky removed)", R+2);
290 midiCreatePlotFile3D (fileName, title,
"X",
"Y",
"Flux", 0,
291 compressedInterfA->image[R], formatInterfA->iXWidth, formatInterfA->iYWidth,
"lines",
"3");
294 for (R = 0; R < formatInterfB->numOfRegionsToProcess; R++)
296 sprintf (fileName,
"3dInterfBDATA%d", R+2);
297 sprintf (title,
"Interferometry B DATA %d (Masked and Sky removed)", R+2);
298 midiCreatePlotFile3D (fileName, title,
"X",
"Y",
"Flux", 0,
299 compressedInterfB->image[R], formatInterfB->iXWidth, formatInterfB->iYWidth,
"lines",
"3");
302 for (R = 0; R < formatPhotomA->numOfRegionsToProcess; R++)
304 sprintf (fileName,
"3dPhotomADATA%d", R+1);
305 sprintf (title,
"Photometry A DATA %d (Masked and Sky removed)", R+1);
306 midiCreatePlotFile3D (fileName, title,
"X",
"Y",
"Flux", 0,
307 compressedPhotomA->image[R], formatPhotomA->iXWidth, formatPhotomA->iYWidth,
"lines",
"3");
310 for (R = 0; R < formatPhotomB->numOfRegionsToProcess; R++)
312 sprintf (fileName,
"3dPhotomBDATA%d", R+4);
313 sprintf (title,
"Photometry B DATA %d (Masked and Sky removed)", R+4);
314 midiCreatePlotFile3D (fileName, title,
"X",
"Y",
"Flux", 0,
315 compressedPhotomB->image[R], formatPhotomB->iXWidth, formatPhotomB->iYWidth,
"lines",
"3");
344 int extNumOfImagingDataFile,
345 MidiFiles *fileNames,
346 int extNumOfImagingDataMask,
348 ImageFormat *localFormat,
349 ImageFormat *formatInterf,
350 CompressedData *compressedInterf,
351 CompressedData *compressedPhotom,
357 const char routine[] =
"organiseKappa";
362 if (diagnostic > 4)cpl_msg_info(cpl_func,
"Invoking routine '%s' \n", routine);
363 if (diagnostic > 4) fprintf(midiReportPtr,
"Invoking routine '%s' \n", routine);
369 frame0 = compressKappa (shutter, fileNames->inFitsName, maskFile,
370 extNumOfImagingDataFile, extNumOfImagingDataMask, compressedInterf,
371 compressedPhotom, newFile, localFormat, formatInterf->numOfFrames, error);
377 sprintf (midiMessage,
"\nWrote %d frames into Interf and Photom, starting at frame %d\nThus now %d frames total,"
378 " expecting %d altogether. Error=%d \n\n", localFormat->numOfFrames, frame0,
379 localFormat->numOfFrames+frame0, formatInterf->numOfFrames, *error);
380 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
384 if ((frame0 + localFormat->numOfFrames) == formatInterf->numOfFrames)
386 compressedInterf->exists = 1;
387 compressedPhotom->exists = 1;
431 int extNumOfImagingDataFile,
432 int extNumOfImagingDataMask,
433 CompressedData *compressedInterf,
434 CompressedData *compressedPhotom,
443 const char routine[] =
"compressKappa";
444 qfits_table *pTable = NULL, *pMask = NULL;
445 short int **inData, *inSteppingPhase;
446 float **inMask, accum, current,
449 char **inTARTYP = NULL, *tempStr, fitsColumnString[10], *dataName, *title=NULL, *fileString=NULL;
450 double *inTIME = NULL;
452 double (*inLOCALOPD)[2] = NULL, (*inOPD)[2] = NULL;
453 static int aprioriSteppingPhase, iF, channelSelected = 0;
454 static double zeroTime;
455 int i, k, *foundData, foundSteppingPhase = 0, indexSteppingPhase, scalingOffset, *indexData,
456 *indexMask, maskWidthX, maskWidthY, maskSubWindow, F, X, Y, R,
457 *indexTARTYP, *foundTARTYP, startframe=0, frameOffset, indexOPD= -1, indexLOCALOPD= -1,
458 indexTIME= -1, maxstep,
464 int startRegion, endRegion, i2, fst, snd, found;
469 if (diagnostic > 4)cpl_msg_info(cpl_func,
"Invoking routine '%s' \n", routine);
470 if (diagnostic > 4) fprintf (midiReportPtr,
"Invoking routine '%s' \n", routine);
474 if (format->numOfDetectorRegions != 4)
477 sprintf (midiMessage,
"Incorrect number of regions. Expected 4, found %d", format->numOfDetectorRegions);
478 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
483 if (strcmp (shutter,
"AOPEN") == 0)
486 endRegion = format->numOfDetectorRegions - 1;
491 endRegion = format->numOfDetectorRegions;
495 inData = (
short int **) calloc (format->numOfDetectorRegions, sizeof (
short int *));
496 inTARTYP = (
char **) calloc (format->numOfDetectorRegions, sizeof (
char *));
497 inMask = (
float **) calloc (format->numOfDetectorRegions, sizeof (
float *));
498 foundData = (
int *) calloc (format->numOfDetectorRegions, sizeof (
int));
499 indexData = (
int *) calloc (format->numOfDetectorRegions, sizeof (
int));
500 foundTARTYP = (
int *) calloc (format->numOfDetectorRegions, sizeof (
int));
501 indexTARTYP = (
int *) calloc (format->numOfDetectorRegions, sizeof (
int));
502 indexMask = (
int *) calloc (format->numOfDetectorRegions, sizeof (
int));
503 normalization = (
float *) calloc (format->iXWidth, sizeof (
float));
504 dataName = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
509 aprioriSteppingPhase = 0;
514 if ((iF + format->numOfFrames) > numOfFramesMax)
515 format->numOfFrames = numOfFramesMax - iF;
518 pMask = qfits_table_open (maskFile, extNumOfImagingDataMask);
521 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot load Mask's IMAGING_DATA");
530 free (normalization);
535 pTable = qfits_table_open (inFitsFile, extNumOfImagingDataFile);
538 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot load Data's IMAGING_DATA");
539 qfits_table_close (pMask);
548 free (normalization);
555 for (R = startRegion; R < endRegion; R++)
560 for (i = 0; i < pTable->nc; i++)
562 for (R = startRegion; R < endRegion; R++)
564 sprintf (dataName,
"DATA%d", R+1);
565 if (strcmp (pTable->col[i].tlabel, dataName) == 0)
571 cpl_msg_info(cpl_func,
"Found 'DATA%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
572 fprintf(midiReportPtr,
"Found 'DATA%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
576 sprintf (dataName,
"TARTYP%d", R+1);
577 if (strcmp (pTable->col[i].tlabel, dataName) == 0)
583 cpl_msg_info(cpl_func,
"Found 'TARTYP%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
584 fprintf(midiReportPtr,
"Found 'TARTYP%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
588 if (strcmp (pTable->col[i].tlabel,
"STEPPING_PHASE") == 0)
590 foundSteppingPhase = 1;
591 indexSteppingPhase = i;
593 if (strcmp (pTable->col[i].tlabel,
"OPD") == 0)
597 if (strcmp (pTable->col[i].tlabel,
"LOCALOPD") == 0)
601 if (strcmp (pTable->col[i].tlabel,
"TIME") == 0)
608 if (foundSteppingPhase == 0)
610 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find STEPPING_PHASE in data FITS file");
615 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find column for OPD in data FITS file");
618 if (indexLOCALOPD < 0)
620 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find column for LOCALOPD in data FITS file");
625 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find column for TIME in data FITS file");
628 for (R = startRegion; R < endRegion; R++)
630 if (foundData[R] == 0)
632 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
633 "Cannot find requested DATA column in data FITS file");
636 if (foundTARTYP[R] == 0)
638 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
639 "Cannot find requested TARTYP column in data FITS file");
645 for (R = startRegion; R < endRegion; R++)
650 for (i = 0; i < pMask->nc; i++)
652 for (R = startRegion; R < endRegion; R++)
654 sprintf (dataName,
"DATA%d", R+1);
655 if (strcmp (pMask->col[i].tlabel, dataName) == 0)
661 cpl_msg_info(cpl_func,
"Found 'DATA%d' at column %d in mask file %s \n", R+1, i+1, maskFile);
662 fprintf(midiReportPtr,
"Found 'DATA%d' at column %d in mask file %s \n", R+1, i+1, maskFile);
669 for (R = startRegion; R < endRegion; R++)
671 if (foundData[R] == 0)
673 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
674 "Cannot find requested DATA column in mask FITS file");
680 sprintf (fitsColumnString,
"TDIM%d", indexMask[1]+1);
681 tempStr = qfits_query_ext (maskFile, fitsColumnString, extNumOfImagingDataMask);
682 sscanf (tempStr,
"'(%d,%d) '", &maskWidthX, &maskWidthY);
683 maskSubWindow = maskWidthX * maskWidthY;
684 if (diagnostic)cpl_msg_info(cpl_func,
"Mask sub-window size = %d\n", maskSubWindow);
685 if (diagnostic)cpl_msg_info(cpl_func,
"Data sub-window size = %d\n", format->subWindowSize);
686 fprintf (midiReportPtr,
"Mask sub-window size = %d\n", maskSubWindow);
687 fprintf (midiReportPtr,
"Data sub-window size = %d\n", format->subWindowSize);
688 if (maskSubWindow != format->subWindowSize)
690 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Mask has incompatible sub window size");
695 tempStr = qfits_query_ext (inFitsFile,
"MAXSTEP", extNumOfImagingDataFile);
698 if (diagnostic)cpl_msg_info(cpl_func,
"MAXSTEP = %s\n", tempStr);
699 fprintf( midiReportPtr,
"MAXSTEP = %s\n", tempStr);
700 sscanf (tempStr,
"%d", &maxstep);
704 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot read MAXSTEP");
709 inSteppingPhase = (
short int*)qfits_query_column (pTable, indexSteppingPhase, NULL);
710 if (inSteppingPhase[0] != ((aprioriSteppingPhase % format->framesPerScan) + 1))
712 sprintf (midiMessage,
"Incorrect Stepping Phase. Expected %d to %d. Instead found %d to %d",
713 aprioriSteppingPhase+1, maxstep, inSteppingPhase[0], maxstep-1);
714 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
721 qfits_table_close (pTable);
722 qfits_table_close (pMask);
731 free (inSteppingPhase);
732 free (normalization);
738 for (R = startRegion; R < endRegion; R++)
740 inData[R] = (
short int*) qfits_query_column (pTable, indexData[R], NULL);
741 inTARTYP[R] = (
char *) qfits_query_column (pTable, indexTARTYP[R], NULL);
744 for (F = 0; F < format->numOfFrames; F++)
749 if (inTARTYP[R][F*tartypMult] ==
'U')
752 inTARTYP[R][F*tartypMult] =
'U';
756 if (strcmp (shutter,
"AOPEN") == 0)
759 (compressedPhotom->tarType)[iF+F] = inTARTYP[R][F*tartypMult];
761 (compressedInterf->tarType)[iF+F] = inTARTYP[R][F*tartypMult];
766 (compressedInterf->tarType)[iF+F] = inTARTYP[R][F*tartypMult];
768 (compressedPhotom->tarType)[iF+F] = inTARTYP[R][F*tartypMult];
777 inTIME = (
double *) qfits_query_column (pTable, indexTIME, NULL);
779 if (iF == 0) zeroTime = inTIME[0];
784 for (startframe = 0; startframe < ARB_NUM_OF_FRAMES; startframe++)
786 if ((zeroTime = inTIME[startframe]) > 1.0)
794 cpl_msg_info(cpl_func,
"\nLOOK: frames 0 - %d had ZERO for their time field!!\n", startframe-1);
795 fprintf(midiReportPtr,
"\nLOOK: frames 0 - %d had ZERO for their time field!!\n", startframe-1);
799 for (F = startframe; F < format->numOfFrames; F++)
801 compressedInterf->time[iF+F] = (float)(inTIME[F] - zeroTime);
802 compressedPhotom->time[iF+F] = (float)(inTIME[F] - zeroTime);
803 if (isnan (compressedInterf->time[iF+F]) ||
804 isnan (compressedPhotom->time[iF+F]))
807 for (i = 0; i < format->iXWidth; i++)
809 compressedInterf->rejectList[i][iF+F] |= BSL_TIME_ERROR;
810 compressedPhotom->rejectList[i][iF+F] |= BSL_TIME_ERROR;
812 sprintf (midiMessage,
"inTIME has an INVALID value at frame %d", iF+F);
813 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
819 if (indexLOCALOPD >= 0)
821 inLOCALOPD = (double (*)[2]) qfits_query_column (pTable, indexLOCALOPD, NULL);
823 for (F = 0; F < format->numOfFrames; F++)
825 compressedInterf->localOPD[iF+F] = (float)(inLOCALOPD[F][0] + inLOCALOPD[F][1]);
826 compressedPhotom->localOPD[iF+F] = (float)(inLOCALOPD[F][0] + inLOCALOPD[F][1]);
827 if (isnan (compressedInterf->localOPD[iF+F]) ||
828 isnan (compressedPhotom->localOPD[iF+F]))
831 for (i = 0; i < format->iXWidth; i++)
833 compressedInterf->rejectList[i][iF+F] |= BSL_LOCALOPD_ERROR;
834 compressedPhotom->rejectList[i][iF+F] |= BSL_LOCALOPD_ERROR;
836 sprintf (midiMessage,
"localOPD has an INVALID value at frame %d", iF+F);
837 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
845 inOPD = (double (*)[2]) qfits_query_column (pTable, indexOPD, NULL);
847 for (F = 0; F < format->numOfFrames; F++)
849 (compressedInterf->bigDL)[iF+F] = (
float)(inOPD[F][0] + inOPD[F][1]);
850 (compressedPhotom->bigDL)[iF+F] = (
float)(inOPD[F][0] + inOPD[F][1]);
851 if (isnan (compressedInterf->bigDL[iF+F]) ||
852 isnan (compressedPhotom->bigDL[iF+F]))
855 for (i = 0; i < format->iXWidth; i++)
857 compressedInterf->rejectList[i][iF+F] |= BSL_OPD_ERROR;
858 compressedPhotom->rejectList[i][iF+F] |= BSL_OPD_ERROR;
860 sprintf (midiMessage,
"bigDL has an INVALID value at frame %d", iF+F);
861 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
867 for (R = startRegion; R < endRegion; R++)
869 inMask[R] = (
float*) qfits_query_column (pMask, indexMask[R], NULL);
872 if (diagnostic && plotFile && newSet)
874 fileString = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
875 title = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
876 sprintf (fileString,
"3dMaskDATA%d", R+1);
877 sprintf (title,
"3D Mask DATA %d", R+1);
878 midiCreatePlotFile3D (fileString, title,
"X",
"Y",
"Flux", 0,
879 inMask[R], format->iXWidth, format->iYWidth,
"lines",
"3");
886 if (newSet || !channelSelected)
888 selectChannels (startRegion, endRegion, format, inMask);
893 for (i = 14; i < 25; i++)
895 sprintf (dataName,
"TZERO%d", i);
896 tempStr = qfits_query_ext (inFitsFile, dataName, extNumOfImagingDataFile);
899 if (diagnostic)cpl_msg_info(cpl_func,
"Scaling Offset = %s\n", tempStr);
900 if (diagnostic) fprintf (midiReportPtr,
"Scaling Offset = %s\n", tempStr);
901 sscanf (tempStr,
"%d", &scalingOffset);
908 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot read Scaling Offset. It is set to 0");
912 for (R = startRegion; R < endRegion; R++)
915 for (X = 0; X < format->iXWidth; X++)
918 for (Y = 0; Y < format->iYWidth; Y++)
919 accum += inMask[R][Y * format->iXWidth + X];
922 normalization[X] = 1.F/accum;
924 normalization[X] = 1.F;
927 for (F = 0; F < format->numOfFrames; F++)
929 frameOffset = F * format->subWindowSize;
930 for (X = 0; X < format->iXWidth; X++)
933 for (Y = 0; Y < format->iYWidth; Y++)
935 k = Y * format->iXWidth + X;
940 if ((compressedInterf->tarType[F] ==
'T') || (compressedPhotom->tarType[F] ==
'T'))
942 if ((R == 1) || (R == 2))
943 inData[R][i] = 20000;
945 inData[R][i] = 30000;
949 if ((R == 1) || (R == 2))
952 inData[R][i] = 10000;
956 if (isnan (inData[R][i]))
958 compressedInterf->rejectList[X][iF+F] |= BSL_DATA_ERROR;
959 compressedPhotom->rejectList[X][iF+F] |= BSL_DATA_ERROR;
960 sprintf (midiMessage,
"inData has an INVALID value at frame %d", (iF+F));
961 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
965 current = (inData[R][i] + scalingOffset) * inMask[R][k];
971 if ((R == 0) && (strcmp (shutter,
"AOPEN") == 0))
973 (((compressedPhotom->iDispFringe)[R])[X])[iF+F] =
974 accum * normalization[X];
975 (compressedPhotom->iFringe1)[iF+F] += accum;
979 (((compressedInterf->iDispFringe)[R-1])[X])[iF+F] =
980 accum * normalization[X];
981 (compressedInterf->iFringe1)[iF+F] += accum;
982 (compressedInterf->iFringe)[iF+F] += accum;
986 (((compressedInterf->iDispFringe)[R-1])[X])[iF+F] =
987 accum * normalization[X];
988 (compressedInterf->iFringe2)[iF+F] += accum;
989 (compressedInterf->iFringe)[iF+F] -= accum;
991 if ((R == 3) && (strcmp (shutter,
"BOPEN") == 0))
993 (((compressedPhotom->iDispFringe)[R-3])[X])[iF+F] =
994 accum * normalization[X];
995 (compressedPhotom->iFringe1)[iF+F] += accum;
1003 for (F = 0; F < format->numOfFrames-maxstep; F++)
1005 fst = F * format->subWindowSize;
1006 snd = (F+maxstep) * format->subWindowSize;
1007 if (compressedInterf->tarType[F] !=
'U')
1009 for (Y = 0; Y < format->iYWidth; Y++)
1011 for (X = 0; X < format->iXWidth; X++)
1013 k = X * format->iYWidth + Y;
1016 if ((compressedInterf->tarType[F] ==
'T') && (compressedInterf->tarType[F+maxstep] ==
'S'))
1017 current = (inData[R][i] + scalingOffset) - (inData[R][i2] + scalingOffset);
1018 else if ((compressedInterf->tarType[F] ==
'S') && (compressedInterf->tarType[F+maxstep] ==
'T'))
1019 current = (inData[R][i2] + scalingOffset) - (inData[R][i] + scalingOffset);
1022 if ((R == 0) && (strcmp (shutter,
"AOPEN") == 0))
1023 compressedPhotom->image[R][k] += (current * inMask[R][k]);
1024 if (R == 1 || R == 2)
1025 compressedInterf->image[R-1][k] += (current * inMask[R][k]);
1026 if ((R == 3) && (strcmp (shutter,
"BOPEN") == 0))
1027 compressedPhotom->image[R-3][k] += (current * inMask[R][k]);
1037 aprioriSteppingPhase = inSteppingPhase[F-1];
1038 if (aprioriSteppingPhase == format->framesPerScan) aprioriSteppingPhase = 0;
1041 iF += format->numOfFrames;
1044 for (R = 0; R < format->numOfDetectorRegions; R++) free (inData[R]);
1045 for (R = 0; R < format->numOfDetectorRegions; R++) free (inTARTYP[R]);
1046 for (R = 0; R < format->numOfDetectorRegions; R++) free (inMask[R]);
1047 if (pMask) qfits_table_close (pMask);
1048 if (pTable) qfits_table_close (pTable);
1049 if (inLOCALOPD) free(inLOCALOPD);
1050 if (inOPD) free(inOPD);
1051 if (inTIME) free(inTIME);
1055 free (inSteppingPhase);
1061 free (normalization);