21 #include <sys/types.h>
27 #include "midiGlobal.h"
29 #include "memoryHandling.h"
30 #include "errorHandling.h"
31 #include "midiFitsUtility.h"
32 #include "diagnostics.h"
33 #include "preProcFrgHS.h"
64 FilterData *filterInfo,
66 CompressedData *compressedInterf,
67 CompressedData *compressedPhotomA,
68 CompressedData *compressedPhotomB,
69 ImageFormat *formatInterf,
70 ImageFormat *formatPhotomA,
71 ImageFormat *formatPhotomB,
77 const char routine[] =
"preProcFrgHS";
78 FILE *inFitsBatchPtr = NULL;
79 int newFile, extNumOfImagingDataFile, extNumOfImagingDataMask, R;
80 char *maskFile, *cleanString, *classification, *stringTemp, *obsTech, *fileName, *title;
81 unsigned int loopCount = 0;
82 ImageFormat *localFormat;
86 if (diagnostic > 4)cpl_msg_info(cpl_func,
"Invoking routine '%s' \n", routine);
87 if (diagnostic > 4) fprintf(midiReportPtr,
"Invoking routine '%s' \n", routine);
89 cpl_msg_info(cpl_func,
"\nReducing data of batch %d \n", batchNumber);
90 cpl_msg_info(cpl_func,
"---------------------- \n");
91 fprintf (midiReportPtr,
"\nReducing data of batch %d \n", batchNumber);
92 fprintf (midiReportPtr,
"---------------------- \n");
95 obsTech = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
96 stringTemp = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
97 classification = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
98 cleanString = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
99 localFormat = callocImageFormat ();
100 maskFile = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
104 compressedInterf->exists = 0;
105 compressedPhotomA->exists = 0;
106 compressedPhotomB->exists = 0;
107 sprintf (obsTech,
"UNKNOWN");
111 if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch,
"r")) == NULL)
113 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
114 "Cannot open input FITS file list. No compression has been carried out for this batch");
118 free (classification);
119 freeImageFormat (localFormat);
127 while (fgets (stringTemp, MAX_STRING_LENGTH, inFitsBatchPtr) != NULL)
129 sprintf (classification,
"%s",
"");
130 sscanf (stringTemp,
"%s%s", fileNames->inFitsName, classification);
131 cpl_msg_info(cpl_func,
"\nProcessing file %s \n", fileNames->inFitsName);
132 fprintf (midiReportPtr,
"\nProcessing file %s \n", fileNames->inFitsName);
135 extNumOfImagingDataFile = findImagingDataExtension (fileNames->inFitsName, TAB_IMAGING_DATA, error);
139 if (extNumOfImagingDataFile > 0)
141 getImageFormat (fileNames->inFitsName, extNumOfImagingDataFile, localFormat, error);
144 else localFormat->hasData = 0;
149 getFilterData (fileNames->inFitsName, filterInfo, error);
151 else fprintf (midiReportPtr,
"First file of batch = %s (QCLOG)\n", fileNames->inFitsName);
154 selectMask (options->maskMode, fileNames, maskFile, error);
158 extNumOfImagingDataMask = findImagingDataExtension (maskFile, MASK_IMAGING_DATA, error);
161 cpl_msg_info(cpl_func,
"Mask File is %s\n", maskFile);
162 fprintf( midiReportPtr,
"Mask File is %s\n", maskFile);
166 if (localFormat->hasData)
169 if (strcmp (localFormat->obsTech,
"INTERFEROMETRY") == 0)
172 if (strcmp (obsTech,
"INTERF") != 0) newFile = 1;
175 sprintf (obsTech,
"INTERF");
178 if ((formatInterf->numOfDetectorRegions != localFormat->numOfDetectorRegions) ||
179 (formatInterf->iXWidth != localFormat->iXWidth) || (formatInterf->iYWidth != localFormat->iYWidth))
181 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Expected format is incorrect");
187 organiseFrgHS (newFile, obsTech, fileNames->inFitsName, maskFile,
188 extNumOfImagingDataFile, extNumOfImagingDataMask, localFormat, formatInterf,
189 compressedInterf, error);
194 else if ((strcmp (localFormat->obsTech,
"IMAGE,WINDOW,CHOPNOD") == 0) &&
195 (strcmp(localFormat->shutterId,
"AOPEN") == 0))
198 if (strcmp (obsTech,
"PHOTOMA") != 0) newFile = 1;
201 sprintf (obsTech,
"PHOTOMA");
204 if ((formatPhotomA->numOfDetectorRegions != localFormat->numOfDetectorRegions) ||
205 (formatPhotomA->iXWidth != localFormat->iXWidth) || (formatPhotomA->iYWidth != localFormat->iYWidth))
207 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Expected format is incorrect");
213 organiseFrgHS (newFile, obsTech, fileNames->inFitsName, maskFile,
214 extNumOfImagingDataFile, extNumOfImagingDataMask, localFormat, formatPhotomA,
215 compressedPhotomA, error);
220 else if ((strcmp (localFormat->obsTech,
"IMAGE,WINDOW,CHOPNOD") == 0) &&
221 (strcmp(localFormat->shutterId,
"BOPEN") == 0))
224 if (strcmp (obsTech,
"PHOTOMB") != 0) newFile = 1;
227 sprintf (obsTech,
"PHOTOMB");
230 if ((formatPhotomB->numOfDetectorRegions != localFormat->numOfDetectorRegions) ||
231 (formatPhotomB->iXWidth != localFormat->iXWidth) || (formatPhotomB->iYWidth != localFormat->iYWidth))
233 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Expected format is incorrect");
239 organiseFrgHS (newFile, obsTech, fileNames->inFitsName, maskFile,
240 extNumOfImagingDataFile, extNumOfImagingDataMask, localFormat, formatPhotomB,
241 compressedPhotomB, error);
248 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Unknown Catg, Type or Tech");
257 sprintf (midiMessage,
"No data tables in %s. Not processed", fileNames->inFitsName);
258 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
265 fclose (inFitsBatchPtr);
268 free (classification);
269 freeImageFormat (localFormat);
274 cpl_msg_info(cpl_func,
"\nCompression status \n");
275 cpl_msg_info(cpl_func,
"------------------ \n");
276 if (compressedInterf->exists)cpl_msg_info(cpl_func,
"Created Compressed Interferometry Data\n");
277 if (compressedPhotomA->exists)cpl_msg_info(cpl_func,
"Created Compressed Photometry A Data\n");
278 if (compressedPhotomB->exists)cpl_msg_info(cpl_func,
"Created Compressed Photometry B Data\n");
279 cpl_msg_info(cpl_func,
"\n");
281 fprintf (midiReportPtr,
"\nCompression status \n");
282 fprintf (midiReportPtr,
"------------------ \n");
283 if (compressedInterf->exists) fprintf (midiReportPtr,
"Created Compressed Interferometry Data\n");
284 if (compressedPhotomA->exists) fprintf (midiReportPtr,
"Created Compressed Photometry A Data\n");
285 if (compressedPhotomB->exists) fprintf (midiReportPtr,
"Created Compressed Photometry B Data\n");
286 fprintf (midiReportPtr,
"\n");
288 if (!(compressedInterf->exists) ||
289 !(compressedPhotomA->exists) || !(compressedPhotomB->exists) || *error)
292 sprintf (midiMessage,
293 "Cannot continue. Need the following compressed data: Interf, PhotomA, PhotomB");
294 midiReportWarning (midiReportPtr,
295 routine, __FILE__, __LINE__, midiMessage);
300 if (diagnostic > 1 && plotFile)
302 fileName = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
303 title = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
305 for (R = 0; R < formatPhotomA->numOfRegionsToProcess; R++)
307 sprintf (fileName,
"3dPhotomADATA%d", R+1);
308 sprintf (title,
"Photometry A DATA %d (Masked and Sky removed)", R+1);
309 midiCreatePlotFile3D (fileName, title,
"X",
"Y",
"Flux", 0,
310 compressedPhotomA->image[R], formatPhotomA->iXWidth, formatPhotomA->iYWidth,
"lines",
"3");
313 for (R = 0; R < formatPhotomB->numOfRegionsToProcess; R++)
315 sprintf (fileName,
"3dPhotomBDATA%d", R+1);
316 sprintf (title,
"Photometry B DATA %d (Masked and Sky removed)", R+1);
317 midiCreatePlotFile3D (fileName, title,
"X",
"Y",
"Flux", 0,
318 compressedPhotomB->image[R], formatPhotomB->iXWidth, formatPhotomB->iYWidth,
"lines",
"3");
346 int extNumOfImagingDataFile,
347 int extNumOfImagingDataMask,
348 ImageFormat *localFormat,
349 ImageFormat *formatMax,
350 CompressedData *compressed,
356 const char routine[] =
"organiseFrgHS";
361 if (diagnostic > 4)cpl_msg_info(cpl_func,
"Invoking routine '%s' \n", routine);
362 if (diagnostic > 4) fprintf(midiReportPtr,
"Invoking routine '%s' \n", routine);
368 frame0 = compressFrgHS (newFile, obsTech, fitsFile, maskFile, extNumOfImagingDataFile,
369 extNumOfImagingDataMask, compressed, localFormat, formatMax->numOfFrames, error);
375 sprintf (midiMessage,
"\nWrote %d frames into %s, starting at frame %d\nThus now %d frames total,"
376 " expecting %d altogether. Error=%d \n\n", localFormat->numOfFrames, obsTech, frame0,
377 localFormat->numOfFrames+frame0, formatMax->numOfFrames, *error);
378 midiReportInfo (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
382 if ((frame0 + localFormat->numOfFrames) == formatMax->numOfFrames)
384 compressed->exists = 1;
387 if (plotFile && (strcmp (obsTech,
"INTERF") == 0) && diagnostic)
389 midiCreatePlotFile2D (
"Time",
"TIME",
"Frame",
"Time", 0, compressed->time, 0,
390 formatMax->numOfFrames, 1, 0);
391 midiCreatePlotFile2D (
"BigDelayLine",
"Net VLTI Delay Line Positions",
"Frame",
392 "Net Position", 0, compressed->bigDL, 0, formatMax->numOfFrames, 1, 0);
393 midiCreatePlotFile2D (
"PiezoDelayLine",
"Net Piezo Delay Line Position",
"Frame",
"Net Delay", 0,
394 compressed->localOPD, 0, formatMax->numOfFrames, 1, 0);
426 int extNumOfImagingDataFile,
427 int extNumOfImagingDataMask,
428 CompressedData *compressed,
429 ImageFormat *localFormat,
436 const char routine[] =
"compressFrgHS";
437 qfits_table *pTable = NULL, *pMask = NULL;
438 short int **inData, *inSteppingPhase;
440 float accum, current;
441 float *normalization;
443 int frameOffset, indexOPD = - 1, indexLOCALOPD = - 1, indexTIME = - 1, maxstep;
444 char **inTARTYP = NULL, *tempStr, fitsColumnString[10], *dataName, *title=NULL, *fileString=NULL;
445 double *inTIME = NULL;
447 double (*inLOCALOPD)[2] = NULL, (*inOPD)[2] = NULL;
448 static int aprioriSteppingPhase, iF, chopInterval, channelSelected = 0;
449 static double zeroTime ;
450 int i, k, fps, *foundData, foundSteppingPhase = 0, indexSteppingPhase, scalingOffset, *indexData ,
451 *indexMask, maskWidthX, maskWidthY, maskSubWindow, F, X, Y, R,
452 *indexTARTYP, *foundTARTYP = 0, startframe=0;
458 int i2, fst, snd, found;
463 if (diagnostic > 4)cpl_msg_info(cpl_func,
"Invoking routine '%s' \n", routine);
464 if (diagnostic > 4) fprintf (midiReportPtr,
"Invoking routine '%s' \n", routine);
468 fps = localFormat->framesPerScan;
471 inData = (
short int **) calloc (localFormat->numOfDetectorRegions, sizeof (
short int *));
472 inTARTYP = (
char **) calloc (localFormat->numOfDetectorRegions, sizeof (
char *));
473 inMask = (
float **) calloc (localFormat->numOfRegionsToProcess, sizeof (
float *));
474 foundData = (
int *) calloc (localFormat->numOfDetectorRegions, sizeof (
int));
475 indexData = (
int *) calloc (localFormat->numOfDetectorRegions, sizeof (
int));
476 foundTARTYP = (
int *) calloc (localFormat->numOfDetectorRegions, sizeof (
int));
477 indexTARTYP = (
int *) calloc (localFormat->numOfDetectorRegions, sizeof (
int));
478 indexMask = (
int *) calloc (localFormat->numOfDetectorRegions, sizeof (
int));
479 normalization = (
float *) calloc (localFormat->iXWidth, sizeof (
float));
480 dataName = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
486 aprioriSteppingPhase = 0;
491 if ((iF + localFormat->numOfFrames) > numOfFramesMax)
492 localFormat->numOfFrames = numOfFramesMax - iF;
495 pMask = qfits_table_open (maskFile, extNumOfImagingDataMask);
498 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot load IMAGING_DATA");
507 free (normalization);
512 pTable = qfits_table_open (inFitsFile, extNumOfImagingDataFile);
515 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot load IMAGING_DATA");
516 qfits_table_close (pMask);
525 free (normalization);
532 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
537 for (i = 0; i < pTable->nc; i++)
539 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
541 sprintf (dataName,
"DATA%d", R+1);
542 if (strcmp (pTable->col[i].tlabel, dataName) == 0)
548 cpl_msg_info(cpl_func,
"Found 'DATA%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
549 fprintf(midiReportPtr,
"Found 'DATA%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
553 sprintf (dataName,
"TARTYP%d", R+1);
554 if (strcmp (pTable->col[i].tlabel, dataName) == 0)
560 cpl_msg_info(cpl_func,
"Found 'TARTYP%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
561 fprintf(midiReportPtr,
"Found 'TARTYP%d' at column %d in data file %s \n", R+1, i+1, inFitsFile);
565 if (strcmp (pTable->col[i].tlabel,
"STEPPING_PHASE") == 0)
567 foundSteppingPhase = 1;
568 indexSteppingPhase = i;
570 if (strcmp (pTable->col[i].tlabel,
"OPD") == 0)
574 if (strcmp (pTable->col[i].tlabel,
"LOCALOPD") == 0)
578 if (strcmp (pTable->col[i].tlabel,
"TIME") == 0)
585 if (foundSteppingPhase == 0)
587 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find STEPPING_PHASE in data FITS file");
592 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find column for OPD in data FITS file");
595 if (indexLOCALOPD < 0)
597 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find column for LOCALOPD in data FITS file");
602 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot find column for TIME in data FITS file");
605 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
607 if (foundData[R] == 0)
609 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
610 "Cannot find requested DATA column in data FITS file");
613 if (foundTARTYP[R] == 0)
615 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
616 "Cannot find requested TARTYP column in data FITS file");
622 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
627 for (i = 0; i < pMask->nc; i++)
629 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
631 sprintf (dataName,
"DATA%d", R+1);
632 if (strcmp (pMask->col[i].tlabel, dataName) == 0)
638 cpl_msg_info(cpl_func,
"Found 'DATA%d' at column %d in mask file %s \n", R+1, i+1, maskFile);
639 fprintf(midiReportPtr,
"Found 'DATA%d' at column %d in mask file %s \n", R+1, i+1, maskFile);
646 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
648 if (foundData[R] == 0)
650 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
651 "Cannot find requested DATA column in mask FITS file");
657 sprintf (fitsColumnString,
"TDIM%d", indexMask[1]+1);
658 tempStr = qfits_query_ext (maskFile, fitsColumnString, extNumOfImagingDataMask);
659 sscanf (tempStr,
"'(%d,%d) '", &maskWidthX, &maskWidthY);
660 maskSubWindow = maskWidthX * maskWidthY;
661 if (newSet && diagnostic)cpl_msg_info(cpl_func,
"Mask sub-window size = %d\n", maskSubWindow);
662 if (diagnostic)cpl_msg_info(cpl_func,
"Data sub-window size = %d\n", localFormat->subWindowSize);
663 if (newSet) fprintf (midiReportPtr,
"Mask sub-window size = %d\n", maskSubWindow);
664 fprintf (midiReportPtr,
"Data sub-window size = %d\n", localFormat->subWindowSize);
665 if (maskSubWindow != localFormat->subWindowSize)
667 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Mask has incompatible sub window size");
672 tempStr = qfits_query_ext (inFitsFile,
"MAXSTEP", extNumOfImagingDataFile);
675 if (diagnostic)cpl_msg_info(cpl_func,
"MAXSTEP = %s\n", tempStr);
676 fprintf( midiReportPtr,
"MAXSTEP = %s\n", tempStr);
677 sscanf (tempStr,
"%d", &maxstep);
681 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot read MAXSTEP");
686 inSteppingPhase = (
short int*)qfits_query_column (pTable, indexSteppingPhase, NULL);
687 if (inSteppingPhase[0] != ((aprioriSteppingPhase % localFormat->framesPerScan) + 1))
689 sprintf (midiMessage,
"Incorrect Stepping Phase. Expected %d to %d. Instead found %d to %d",
690 aprioriSteppingPhase+1, maxstep, inSteppingPhase[0], maxstep-1);
691 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
698 qfits_table_close (pTable);
699 qfits_table_close (pMask);
708 free (inSteppingPhase);
709 free (normalization);
715 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
717 inData[R] = (
short int*) qfits_query_column (pTable, indexData[R], NULL);
718 inTARTYP[R] = (
char *) qfits_query_column (pTable, indexTARTYP[R], NULL);
721 for (F = 0; F < localFormat->numOfFrames; F++)
724 if (newSet && (strcmp (obsTech,
"INTERF") != 0))
726 if (inTARTYP[R][F*tartypMult] ==
'U')
729 inTARTYP[R][F*tartypMult] =
'U';
733 (compressed->tarType)[iF+F] = inTARTYP[R][F*tartypMult];
737 if (inTARTYP[R][F*tartypMult] != inTARTYP[R-1][F*tartypMult])
739 sprintf (midiMessage,
"Incompatible Interferometry TARTYP%d & TARTYP%d at frame %d", R, R-1, iF+F);
740 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
743 for (i = 0; i < localFormat->iXWidth; i++)
744 compressed->rejectList[i][iF+F] |= BSL_TARTYPE_CROSS;
747 if (strcmp (obsTech,
"INTERF") == 0) compressed->badScanList[(iF+F)/fps] |= BSL_TARTYPE_CROSS;
757 inTIME = (
double *) qfits_query_column (pTable, indexTIME, NULL);
759 if (iF == 0) zeroTime = inTIME[0];
764 for (startframe = 0; startframe < ARB_NUM_OF_FRAMES; startframe++)
766 if ((zeroTime = inTIME[startframe]) > 1.0)
774 cpl_msg_info(cpl_func,
"\nLOOK: frames 0 - %d had ZERO for their time field!!\n", startframe-1);
775 fprintf(midiReportPtr,
"\nLOOK: frames 0 - %d had ZERO for their time field!!\n", startframe-1);
779 for (F = startframe; F < localFormat->numOfFrames; F++)
781 compressed->time[iF+F] = (float)(inTIME[F] - zeroTime);
782 if (isnan ((compressed->time[iF+F])))
784 sprintf (midiMessage,
"inTIME has an INVALID value at frame %d", iF+F);
785 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
788 for (i = 0; i < localFormat->iXWidth; i++)
789 compressed->rejectList[i][iF+F] |= BSL_TIME_ERROR;
792 if (strcmp (obsTech,
"INTERF") == 0) compressed->badScanList[(iF+F)/fps] |= BSL_TIME_ERROR;
798 if (indexLOCALOPD >= 0)
800 inLOCALOPD = (double (*)[2]) qfits_query_column (pTable, indexLOCALOPD, NULL);
802 for (F = 0; F < localFormat->numOfFrames; F++)
804 compressed->localOPD[iF+F] = (float)(inLOCALOPD[F][0] + inLOCALOPD[F][1]);
805 if (isnan ((compressed->localOPD[iF+F])))
807 sprintf (midiMessage,
"localOPD has an INVALID value at frame %d", iF+F);
808 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
811 for (i = 0; i < localFormat->iXWidth; i++)
812 compressed->rejectList[i][iF+F] |= BSL_LOCALOPD_ERROR;
815 if (strcmp (obsTech,
"INTERF") == 0) compressed->badScanList[(iF+F)/fps] |= BSL_LOCALOPD_ERROR;
823 inOPD = (double (*)[2]) qfits_query_column (pTable, indexOPD, NULL);
825 for (F = 0; F < localFormat->numOfFrames; F++)
827 (compressed->bigDL)[iF+F] = (
float)(inOPD[F][0] + inOPD[F][1]);
828 if (isnan ((compressed->bigDL)[iF+F]))
830 sprintf (midiMessage,
"bigDL has an INVALID value at frame %d", iF+F);
831 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
834 for (i = 0; i < localFormat->iXWidth; i++)
835 compressed->rejectList[i][iF+F] |= BSL_OPD_ERROR;
838 if (strcmp (obsTech,
"INTERF") == 0) compressed->badScanList[(iF+F)/fps] |= BSL_OPD_ERROR;
844 if (newSet && (strcmp (obsTech,
"INTERF") != 0))
848 for (F = 0; F < localFormat->numOfFrames; F++)
850 if (compressed->tarType[F] ==
'U' && (lastType ==
'T' || lastType ==
'S'))
856 lastType = compressed->tarType[F];
863 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
865 inMask[R] = (
float*) qfits_query_column (pMask, indexMask[R], NULL);
868 if (diagnostic > 1 && plotFile && newSet && (strcmp(obsTech,
"INTERF") == 0))
870 fileString = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
871 title = (
char *) calloc (MAX_STRING_LENGTH,
sizeof (
char));
872 sprintf (fileString,
"3dMaskDATA%d", R+1);
873 sprintf (title,
"3D Mask DATA %d", R+1);
874 midiCreatePlotFile3D (fileString, title,
"X",
"Y",
"Flux", 0,
875 inMask[R], localFormat->iXWidth, localFormat->iYWidth,
"lines",
"3");
882 if ((newSet || !channelSelected) && (strcmp(obsTech,
"INTERF") == 0))
884 selectChannels (0, localFormat->numOfDetectorRegions, localFormat, inMask);
889 for (i = 14; i < 25; i++)
891 sprintf (dataName,
"TZERO%d", i);
892 tempStr = qfits_query_ext (inFitsFile, dataName, extNumOfImagingDataFile);
895 if (diagnostic)cpl_msg_info(cpl_func,
"Scaling Offset = %s\n", tempStr);
896 if (diagnostic) fprintf (midiReportPtr,
"Scaling Offset = %s\n", tempStr);
897 sscanf (tempStr,
"%d", &scalingOffset);
904 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
"Cannot read Scaling Offset. It is set to 0");
908 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
911 for (X = 0; X < localFormat->iXWidth; X++)
914 for (Y = 0; Y < localFormat->iYWidth; Y++)
915 accum += inMask[R][Y * localFormat->iXWidth + X];
918 normalization[X] = 1.F/accum;
920 normalization[X] = 1.F;
923 for (F = 0; F < localFormat->numOfFrames; F++)
925 frameOffset = F * localFormat->subWindowSize;
926 for (X = 0; X < localFormat->iXWidth; X++)
929 for (Y = 0; Y < localFormat->iYWidth; Y++)
931 k = Y * localFormat->iXWidth + X;
935 if (isnan (inData[R][i]))
937 sprintf (midiMessage,
"inData has an INVALID value at frame %d", (iF+F));
938 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
940 compressed->rejectList[X][iF+F] |= BSL_DATA_ERROR;
943 if (strcmp (obsTech,
"INTERF") == 0) compressed->badScanList[(iF+F)/fps] |= BSL_DATA_ERROR;
947 current = (inData[R][i] + scalingOffset) * inMask[R][k];
953 (((compressed->iDispFringe)[R])[X])[iF+F] = accum * normalization[X];
956 (compressed->iFringe1)[iF+F] += accum;
957 (compressed->iFringe)[iF+F] += accum;
961 (compressed->iFringe2)[iF+F] += accum;
962 (compressed->iFringe)[iF+F] -= accum;
968 if (diagnostic > 1 && (strcmp (obsTech,
"INTERF") != 0))
970 for (F = 0; F < localFormat->numOfFrames-chopInterval; F++)
972 fst = F * localFormat->subWindowSize;
973 snd = (F+chopInterval) * localFormat->subWindowSize;
974 if (compressed->tarType[F] !=
'U')
976 for (Y = 0; Y < localFormat->iYWidth; Y++)
978 for (X = 0; X < localFormat->iXWidth; X++)
980 k = X * localFormat->iYWidth + Y;
983 if ((compressed->tarType[F] ==
'T') && (compressed->tarType[F+chopInterval] ==
'S'))
984 current = (inData[R][i] + scalingOffset) - (inData[R][i2] + scalingOffset);
985 else if ((compressed->tarType[F] ==
'S') && (compressed->tarType[F+chopInterval] ==
'T'))
986 current = (inData[R][i2] + scalingOffset) - (inData[R][i] + scalingOffset);
989 compressed->image[R][k] += current;
998 aprioriSteppingPhase = inSteppingPhase[F-1];
999 if (aprioriSteppingPhase == localFormat->framesPerScan) aprioriSteppingPhase = 0;
1002 iF += localFormat->numOfFrames;
1005 for (R = 0; R < localFormat->numOfDetectorRegions; R++)
1011 if (pMask) qfits_table_close (pMask);
1012 if (pTable) qfits_table_close (pTable);
1013 if (inLOCALOPD) free(inLOCALOPD);
1014 if (inOPD) free(inOPD);
1015 if (inTIME) free(inTIME);
1019 free (inSteppingPhase);
1025 free (normalization);