00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <sys/stat.h>
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <time.h>
00027 #include "cpl_init.h"
00028 #include "midiGlobal.h"
00029 #include "midiLib.h"
00030 #include "midiControl.h"
00031 #include "memoryHandling.h"
00032 #include "procFrgHS.h"
00033 #include "procFrgSP.h"
00034 #include "procKappa.h"
00035 #include "procAcq.h"
00036 #include "procDetLin.h"
00037 #include "procDetRon.h"
00038 #include "procRefPix.h"
00039 #include "procDspTrn.h"
00040 #include "procWavCal.h"
00041 #include "errorHandling.h"
00042 #include "fileHandling.h"
00043 #include "midiFitsClassification.h"
00044 #include "calibration.h"
00045 #include "diagnostics.h"
00046 #include <cpl.h>
00047 #include "midi_dfs.h"
00048
00049
00050
00051
00052 int rootName = 1;
00053 int diagnostic = 0;
00054 int endOfTemplate = 0;
00055 int plotFile = 2;
00056 int plotDuration = 0;
00057 int batchNumber = 0;
00058 FILE *midiReportPtr=NULL;
00059 char *midiReportName=NULL;
00060 FILE *midiQcLogPtr=NULL;
00061 char *midiQcLogName=NULL;
00062 char outFileDir[MAX_STRING_LENGTH];
00063 char outRootName[MAX_STRING_LENGTH];
00064 char batchTemplate[MAX_STRING_LENGTH];
00065 char givenName[MAX_STRING_LENGTH];
00066 char midiMessage[MAX_STRING_LENGTH];
00067 int *badChannelList;
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 void executeDataReduction (
00087 const char *calibTempDir,
00088 const char *maskFileDir,
00089 const char *productDir,
00090 int givenDispDur,
00091 const char *inFitsList,
00092 int *error,
00093 cpl_parameterlist *parlist,
00094 cpl_frameset *frameset)
00095 {
00096
00097
00098
00099 const char routine[] = "executeDataReduction";
00100 FILE *inFitsClassifiedPtr=NULL, *inFitsBatchPtr=NULL, *tempReportPtr=NULL;
00101 char *stringTemp=NULL, *tempReportName=NULL, *fileNameStr=NULL,
00102 *classification=NULL;
00103 MidiFiles *fileNames=NULL;
00104 UserOptions *options=NULL;
00105 FILE *signaturePtr=NULL;
00106
00107
00108
00109
00110 *error = 0;
00111
00112
00113 tempReportName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00114 options = (UserOptions *) calloc (1, sizeof (UserOptions));
00115 fileNames = callocMidiFiles (MAX_STRING_LENGTH);
00116
00117
00118 sprintf (tempReportName, "midiPipelineTempReport.log");
00119 tempReportPtr = fopen (tempReportName, "w");
00120 sprintf (outFileDir, "%s", productDir);
00121 plotDuration = givenDispDur;
00122 if (plotDuration == 0) plotFile = 1;
00123 sprintf (givenName, "%s", "MIDI");
00124
00125
00126
00127 getMaskFileFromSof(fileNames,frameset);
00128
00129
00130
00131
00132 getParameters (calibTempDir, maskFileDir, inFitsList, tempReportPtr, options, fileNames, error);
00133 if (*error)
00134 {
00135 cpl_msg_info(cpl_func,"\n");
00136 fprintf (tempReportPtr, "\n");
00137 fclose (tempReportPtr);
00138 free (tempReportName);
00139 free (options);
00140 free (fileNames);
00141 return;
00142 }
00143
00144
00145
00146
00147 stringTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00148 midiQcLogName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00149 midiReportName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00150 fileNameStr = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00151 classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00152
00153
00154
00155 classifyFitsFiles (options, fileNames, tempReportPtr, error,
00156 parlist, frameset);
00157 if (*error)
00158 {
00159 if (*error > 1)
00160 {
00161 sprintf (midiMessage, "No FITS files to process. Check log file: %s", tempReportName);
00162 midiReportWarning (tempReportPtr, routine, __FILE__, __LINE__, midiMessage);
00163 }
00164 cpl_msg_info(cpl_func,"\n");
00165 fprintf (tempReportPtr, "\n");
00166 fclose (tempReportPtr);
00167 freeMidiFiles (fileNames);
00168 free (options);
00169 free (stringTemp);
00170 free (tempReportName);
00171 free (midiQcLogName);
00172 free (midiReportName);
00173 free (fileNameStr);
00174 free (classification);
00175 return;
00176 }
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 if ((inFitsClassifiedPtr = fopen (fileNames->inFitsClassified, "r")) == NULL)
00195 midiReportError (tempReportPtr, routine, __FILE__, __LINE__, "Cannot open list of classified input FITS files");
00196
00197
00198
00199 while (fgets (stringTemp, MAX_STRING_LENGTH, inFitsClassifiedPtr) != NULL)
00200 {
00201
00202 removeNewLine (stringTemp, batchTemplate);
00203
00204
00205 sprintf (fileNames->inFitsBatch, "%s", "inputFitsBatch.log");
00206 if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "w")) == NULL)
00207 midiReportError (tempReportPtr, routine, __FILE__, __LINE__, "Cannot open batch FITS files");
00208
00209
00210 while (fgets (stringTemp, MAX_STRING_LENGTH, inFitsClassifiedPtr) != NULL)
00211 {
00212 sprintf (classification, "%s", "");
00213 sscanf (stringTemp, "%s%s", fileNameStr, classification);
00214 if (strcmp (fileNameStr, "END_OF_BATCH") != 0)
00215 fprintf (inFitsBatchPtr, "%s %s\n", fileNameStr, classification);
00216 else
00217 break;
00218 }
00219 fclose (inFitsBatchPtr);
00220
00221
00222 batchNumber=1;
00223
00224
00225 createOutputFileNames (fileNames, tempReportPtr, error);
00226 if (*error)
00227 {
00228 midiReportWarning (tempReportPtr, routine, __FILE__, __LINE__, "This batch is rejected");
00229 continue;
00230 }
00231 handoverReport (tempReportName, &tempReportPtr);
00232
00233
00234
00235 if (options->maskMode == COMPUTED)
00236 {
00237 createMaskFile (fileNames, error);
00238 if (*error)
00239 {
00240 midiReportWarning (tempReportPtr, routine, __FILE__, __LINE__, "This batch is rejected");
00241 midiRejectBatch ();
00242 continue;
00243 }
00244 }
00245
00246
00247
00248 if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
00249 (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
00250 {
00251 if (options->drsFrg) procFrgHS (fileNames, options, error, parlist, frameset);
00252 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "This batch is rejected");
00253 }
00254 else if (strcmp (batchTemplate, "SCI_PHOT_KAPPA") == 0)
00255 {
00256 if (options->drsKap)
00257 {
00258
00259 signaturePtr = fopen ("MIDI_sig_spk.log", "w");
00260 fclose (signaturePtr);
00261 procKappa (fileNames, options, error);
00262 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "This batch is rejected");
00263 }
00264 }
00265 else if ((strcmp (batchTemplate, "SCI_PHOT_CALIB") == 0) ||
00266 (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0))
00267 {
00268 if (options->drsFrg)
00269 {
00270 if (strcmp (batchTemplate, "SCI_PHOT_CALIB") == 0)
00271 signaturePtr = fopen ("MIDI_sig_spc.log", "w");
00272 else
00273 signaturePtr = fopen ("MIDI_sig_sps.log", "w");
00274 fclose (signaturePtr);
00275 procFrgSP (fileNames, options, error, parlist, frameset);
00276 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "This batch is rejected");
00277 }
00278 }
00279 else if (strcmp (batchTemplate, "ACQ") == 0)
00280 {
00281 if (options->drsAcq)
00282 procAcq (fileNames, error);
00283 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
00284 "This batch is rejected");
00285 }
00286 else if (strcmp (batchTemplate, "DETLIN") == 0)
00287 {
00288 if (options->tecLin)
00289 procDetLin (fileNames, error);
00290 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
00291 "This batch is rejected");
00292 }
00293 else if (strcmp (batchTemplate, "DETRON") == 0)
00294 {
00295 if (options->tecRon)
00296 procDetRon (fileNames, error);
00297 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
00298 "This batch is rejected");
00299 }
00300 else if (strcmp (batchTemplate, "DSPTRN") == 0)
00301 {
00302 if (options->tecTrn)
00303 procDspTrn (fileNames, error);
00304 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
00305 "This batch is rejected");
00306 }
00307 else if (strcmp (batchTemplate, "REFPIX") == 0)
00308 {
00309 if (options->tecPix)
00310 procRefPix (fileNames, error);
00311 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
00312 "This batch is rejected");
00313 }
00314 else if (strcmp (batchTemplate, "WAVECAL") == 0)
00315 {
00316 if (options->tecWav)
00317 procWaveCal (options->tecWav, fileNames, error);
00318 if (*error) midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__,
00319 "This batch is rejected");
00320 }
00321 else
00322 {
00323 sprintf (midiMessage, "Cannot process template: %s", batchTemplate);
00324 midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00325 *error = 1;
00326 }
00327
00328
00329 if (*error) midiRejectBatch ();
00330 else midiCloseBatch ();
00331
00332 if (strcmp (batchTemplate, "SCI_PHOT_KAPPA") == 0)
00333 {
00334
00335 remove (midiQcLogName);
00336
00337 continue;
00338 }
00339 break;
00340
00341 }
00342
00343
00344
00345 if (diagnostic) cpl_msg_info(cpl_func,"\nClosing temporary files \n");
00346 if (diagnostic) cpl_msg_info(cpl_func,"----------------------- \n");
00347 if (diagnostic) cpl_msg_info(cpl_func,"\n\n");
00348 fclose (inFitsClassifiedPtr);
00349 fclose (tempReportPtr);
00350 remove (fileNames->inFitsClassified);
00351 remove (fileNames->inFitsBatch);
00352 remove (tempReportName);
00353
00354
00355 freeMidiFiles (fileNames);
00356 free (options);
00357 free (stringTemp);
00358 free (tempReportName);
00359 free (midiQcLogName);
00360 free (midiReportName);
00361 free (fileNameStr);
00362 free (classification);
00363
00364
00365 return;
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381 void midiRejectBatch (void)
00382 {
00383
00384
00385 const char routine[] = "midiRejectBatch";
00386
00387
00388
00389 if (diagnostic > 2) cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
00390 if (diagnostic > 2) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
00391
00392
00393
00394 if (diagnostic) cpl_msg_info(cpl_func,"Created Log files: %s \n", midiReportName);
00395 fprintf (midiReportPtr, "Created Log files: %s \n", midiReportName);
00396 if (diagnostic) cpl_msg_info(cpl_func,"\n");
00397 fprintf (midiReportPtr, "\n");
00398 if (midiReportPtr)
00399 {
00400 fclose (midiReportPtr);
00401 midiReportPtr = NULL;
00402 }
00403 if (midiQcLogPtr)
00404 {
00405 fclose (midiQcLogPtr);
00406 midiQcLogPtr = NULL;
00407 remove (midiQcLogName);
00408 }
00409
00410 return;
00411 }
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 void midiCloseBatch (void)
00427 {
00428
00429
00430 const char routine[] = "midiCloseBatch";
00431
00432
00433
00434 if (diagnostic > 2) cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
00435 if (diagnostic > 2) fprintf (midiReportPtr, "Invoking routine '%s' \n", routine);
00436
00437
00438
00439 cpl_msg_info(cpl_func,"Created Log files: %s %s \n", midiReportName, midiQcLogName);
00440 fprintf (midiReportPtr, "Created Log files: %s %s \n", midiReportName, midiQcLogName);
00441 cpl_msg_info(cpl_func,"\n\n");
00442 fprintf (midiReportPtr, "\n\n");
00443 if (midiReportPtr)
00444 {
00445 fclose (midiReportPtr);
00446 midiReportPtr = NULL;
00447 }
00448 if (midiQcLogPtr)
00449 {
00450 fclose (midiQcLogPtr);
00451 midiQcLogPtr = NULL;
00452 }
00453
00454 return;
00455 }
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471 void getParameters (
00472 const char *calibTempDir,
00473 const char *maskFileDir,
00474 const char *inFitsList,
00475 FILE *filePtr,
00476 UserOptions *options,
00477 MidiFiles *fileNames,
00478 int *error)
00479
00480 {
00481
00482
00483
00484 const char routine[] = "getParameters";
00485 FILE *inFitsListPtr=NULL, *inFitsClassifiedPtr=NULL;
00486 char *argument=NULL, *value=NULL, *tempStr=NULL;
00487
00488
00489
00490 *error = 0;
00491
00492
00493 tempStr = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00494 argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00495 value = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00496
00497
00498
00499 sprintf (fileNames->inFileDir, "%s", "");
00500 sprintf (fileNames->trfNameRead, "%s", "/tmp/MIDI.trf.dummy");
00501 sprintf (fileNames->trfNameWrite, "%s", "/tmp/MIDI.trf.dummy");
00502 sprintf (fileNames->wclNameRead, "%s", "/tmp/MIDI.wcl.dummy");
00503 sprintf (fileNames->wclNameWrite, "%s", "/tmp/MIDI.wcl.dummy");
00504 sprintf (fileNames->trrNameRead, "%s", "/tmp/MIDI.trr.dummy");
00505 sprintf (fileNames->trrNameWrite, "%s", "/tmp/MIDI.trr.dummy");
00506 sprintf (fileNames->calibDbDir, "%s", calibTempDir);
00507 sprintf (fileNames->maskFileDir, "%s", maskFileDir);
00508 sprintf (fileNames->inFitsList, "%s", inFitsList);
00509 options->processing = DISPERSED;
00510 options->drsFrg = 1;
00511 options->drsAcq = 1;
00512 options->drsKap = 0;
00513 options->tecRon = 1;
00514 options->tecLin = 1;
00515 options->tecPix = 1;
00516 options->tecTrn = 1;
00517 options->tecWav = 1;
00518
00519 options->maskMode = SPECIFIED;
00520
00521
00522 displayBanner (filePtr);
00523
00524 if (diagnostic > 2) cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
00525
00526
00527 sprintf (fileNames->calibDbName, "%scalibrator_database.dat", fileNames->calibDbDir);
00528 sprintf (fileNames->waveCalibName, "%swaveCalib", fileNames->calibDbDir);
00529 sprintf (fileNames->transferRatiosName, "%stransferRatios", fileNames->calibDbDir);
00530 sprintf (fileNames->grismFoilName, "%sgrism_foil_4lines.dat", fileNames->calibDbDir);
00531 sprintf (fileNames->prismFoilName, "%sprism_foil_4lines.dat", fileNames->calibDbDir);
00532
00533
00534 strcpy (fileNames->inFitsClassified, "inputFitsClassified.log");
00535
00536
00537
00538 if (((inFitsListPtr = fopen(fileNames->inFitsList, "r")) != NULL) &&
00539 (fscanf (inFitsListPtr, "%s\n", argument) != EOF))
00540 {
00541
00542 rewind (inFitsListPtr);
00543 inFitsClassifiedPtr = fopen (fileNames->inFitsClassified, "w");
00544
00545 while (fgets (tempStr, MAX_STRING_LENGTH, inFitsListPtr) != NULL)
00546 {
00547
00548 sprintf (value, "%s", "");
00549 sscanf (tempStr, "%s%s", argument, value);
00550 fprintf (inFitsClassifiedPtr, "%s %s\n", argument, value);
00551 }
00552 fclose (inFitsListPtr);
00553 fclose (inFitsClassifiedPtr);
00554 }
00555 else
00556 {
00557 cpl_msg_info(cpl_func,"\n<<Error>>: List of FITS file is not given or the list is empty \n");
00558 cpl_msg_info(cpl_func,"\n");
00559 fprintf(filePtr, "\n<<Error>>: List of FITS file is not given or the list is empty\n");
00560 fprintf(filePtr, "\n");
00561 *error = 1;
00562 if (argument) free (argument);
00563 if (tempStr) free (tempStr);
00564 if (value) free (value);
00565 return;
00566 }
00567
00568
00569 inFitsClassifiedPtr = fopen (fileNames->inFitsClassified, "r");
00570 cpl_msg_info(cpl_func,"\n");
00571 cpl_msg_info(cpl_func,"The FITS list contains the following files:\n");
00572 cpl_msg_info(cpl_func,"-------------------------------------------\n");
00573 fprintf (filePtr, "\n");
00574 fprintf (filePtr, "Given FITS list contains the following files:\n");
00575 fprintf (filePtr, "---------------------------------------------\n");
00576 while (fgets (tempStr, MAX_STRING_LENGTH, inFitsClassifiedPtr) != NULL)
00577 {
00578
00579 sprintf (value, "%s", "");
00580 sscanf (tempStr, "%s%s", argument, value);
00581 cpl_msg_info(cpl_func,"%s %s\n", argument, value);
00582 fprintf (filePtr, "%s %s\n", argument, value);
00583 }
00584 fclose (inFitsClassifiedPtr);
00585
00586
00587 if (argument) free (argument);
00588 if (tempStr) free (tempStr);
00589 if (value) free (value);
00590
00591 return;
00592 }
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609 void createOutputFileNames (
00610 MidiFiles *fileNames,
00611 FILE *filePtr,
00612 int *error)
00613
00614 {
00615
00616
00617
00618 const char routine[] = "createOutputFileNames";
00619 FILE *inFitsBatchPtr=NULL;
00620 size_t stringLength;
00621 char *fileTemp=NULL, *classification=NULL, *pipeFilePrefix=NULL,
00622 *fileNameStr=NULL, *suffix=NULL, *pipeRootName=NULL;
00623
00624
00625
00626 if (diagnostic > 2) cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
00627 if (diagnostic > 2) fprintf (filePtr, "Invoking routine '%s' \n", routine);
00628
00629
00630 *error = 0;
00631
00632
00633 fileTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00634 suffix = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00635 fileNameStr = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00636 classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00637 pipeFilePrefix = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00638 pipeRootName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00639
00640
00641 sprintf (pipeFilePrefix, "r.");
00642
00643
00644 if ((inFitsBatchPtr = fopen(fileNames->inFitsBatch, "r")) == NULL)
00645 midiReportError (filePtr, routine, __FILE__, __LINE__, "Cannot open FITS file list");
00646
00647 fgets (fileTemp, MAX_STRING_LENGTH, inFitsBatchPtr);
00648 sprintf (classification, "%s", "");
00649 sscanf (fileTemp, "%s%s", fileNameStr, classification);
00650 stringLength = strlen (fileNameStr);
00651 strncpy (pipeRootName, fileNameStr, stringLength-5);
00652
00653
00654
00655 removePathName (pipeRootName, filePtr);
00656 if (inFitsBatchPtr) fclose (inFitsBatchPtr);
00657 sprintf (fileNames->archFileName, "%s.fits", pipeRootName);
00658 sprintf (fileNames->pipeFileName, "%s%s_tpl_0000.fits", pipeFilePrefix, pipeRootName);
00659
00660
00661 if (strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0)
00662 {
00663 sprintf (suffix, "_b%d_hsc", batchNumber);
00664 }
00665 else if (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0)
00666 {
00667 sprintf (suffix, "_b%d_hss", batchNumber);
00668 }
00669 else if (strcmp (batchTemplate, "SCI_PHOT_CALIB") == 0)
00670 {
00671 sprintf (suffix, "_b%d_spc", batchNumber);
00672 }
00673 else if (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0)
00674 {
00675 sprintf (suffix, "_b%d_sps", batchNumber);
00676 }
00677 else if (strcmp (batchTemplate, "SCI_PHOT_KAPPA") == 0)
00678 {
00679 sprintf (suffix, "_b%d_spk", batchNumber);
00680 }
00681 else if (strcmp (batchTemplate, "ACQ") == 0)
00682 {
00683 sprintf (suffix, "_b%d_acq", batchNumber);
00684 }
00685 else if (strcmp (batchTemplate, "DETLIN") == 0)
00686 {
00687 sprintf (suffix, "_b%d_lin", batchNumber);
00688 }
00689 else if (strcmp (batchTemplate, "DETRON") == 0)
00690 {
00691 sprintf (suffix, "_b%d_ron", batchNumber);
00692 }
00693 else if (strcmp (batchTemplate, "DSPTRN") == 0)
00694 {
00695 sprintf (suffix, "_b%d_trn", batchNumber);
00696 }
00697 else if (strcmp (batchTemplate, "REFPIX") == 0)
00698 {
00699 sprintf (suffix, "_b%d_pix", batchNumber);
00700 }
00701 else if (strcmp (batchTemplate, "WAVECAL") == 0)
00702 {
00703 sprintf (suffix, "_b%d_wav", batchNumber);
00704 }
00705 else
00706 {
00707 *error = 1;
00708 sprintf (midiMessage, "Unknown Template: %s", batchTemplate);
00709 midiReportWarning (filePtr, routine, __FILE__, __LINE__, midiMessage);
00710 free (fileTemp);
00711 free (suffix);
00712 free (classification);
00713 free (fileNameStr);
00714 free (pipeFilePrefix);
00715 free (pipeRootName);
00716 return;
00717 }
00718 if (!rootName) sprintf (outRootName, "%s%s", pipeRootName, suffix);
00719 else sprintf (outRootName, "%s%s", givenName, suffix);
00720
00721 sprintf (midiReportName, "%s%s.log", outFileDir, outRootName);
00722 sprintf (midiQcLogName, "%s%s.qc.dummy", outFileDir, outRootName);
00723 sprintf (fileNames->trfHistoryName, "%s%s.trfh.dummy", outFileDir, outRootName);
00724 sprintf (fileNames->wclHistoryName, "%s%s.wclh.dummy", outFileDir, outRootName);
00725 sprintf (fileNames->trrHistoryName, "%s%s.trrh.dummy", outFileDir, outRootName);
00726 sprintf (fileNames->outFitsName, "%s%s.pro.fits", outFileDir, outRootName);
00727 sprintf (fileNames->outWaterfallName, "%s%s.waf.fits", outFileDir, outRootName);
00728 sprintf (fileNames->outWaterpowerName, "%s%s.wap.fits", outFileDir, outRootName);
00729 sprintf (fileNames->outAveImageName, "%s%s.aim.fits", outFileDir, outRootName);
00730 sprintf (fileNames->outChSpectrumName, "%s%s.chs.fits", outFileDir, outRootName);
00731
00732
00733 if (fileTemp) free (fileTemp);
00734 if (suffix) free (suffix);
00735 if (classification) free (classification);
00736 if (fileNameStr) free (fileNameStr);
00737 if (pipeFilePrefix) free (pipeFilePrefix);
00738 if (pipeRootName) free (pipeRootName);
00739
00740 return;
00741 }
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757 void displayBanner (
00758 FILE *filePtr)
00759
00760 {
00761
00762
00763
00764 const char routine[] = "displayBanner";
00765 time_t now;
00766 struct tm *newTime=NULL;
00767 char *currentTime=NULL;
00768
00769
00770
00771 if (diagnostic > 2) cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
00772 if (diagnostic > 2) fprintf (filePtr, "Invoking routine '%s' \n", routine);
00773
00774
00775 currentTime = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00776
00777 now = time(NULL);
00778 newTime = gmtime (&now);
00779 strftime (currentTime, MIN_STRING_LENGTH, "%a %d %b %Y at %H:%M:%S", newTime);
00780
00781 cpl_msg_info(cpl_func,"\n\n\n\n");
00782 cpl_msg_info(cpl_func," ,----------------------------------------------.\n");
00783 cpl_msg_info(cpl_func," | * European Southern Observatory |\n");
00784 cpl_msg_info(cpl_func," | *E S* VLTI DMD, Garching |\n");
00785 cpl_msg_info(cpl_func," | O MIDI Data Reduction Program |\n");
00786 cpl_msg_info(cpl_func," | * Version: %s\n", MIDI_PIPE_VERSION);
00787 cpl_msg_info(cpl_func," | |\n");
00788 cpl_msg_info(cpl_func," | For support e-mail to: |\n");
00789 cpl_msg_info(cpl_func," | pballest@eso.org or agabasch@eso.org |\n");
00790 cpl_msg_info(cpl_func," `----------------------------------------------'\n");
00791 cpl_msg_info(cpl_func,"\nMIDI pipeline started on: %s GMT \n", currentTime);
00792
00793 fprintf (filePtr, "\n\n\n\n");
00794 fprintf (filePtr, " ,----------------------------------------------.\n");
00795 fprintf (filePtr, " | * European Southern Observatory |\n");
00796 fprintf (filePtr, " | *E S* VLTI DMD, Garching |\n");
00797 fprintf (filePtr, " | O MIDI Data Reduction Program |\n");
00798 fprintf (filePtr, " | * Version: %s\n", MIDI_PIPE_VERSION);
00799 fprintf (filePtr, " | |\n");
00800 fprintf (filePtr, " | For support e-mail to: |\n");
00801 fprintf (filePtr, " | pballest@eso.org or agabasch@eso.org |\n");
00802 fprintf (filePtr, " `----------------------------------------------'\n");
00803 fprintf (filePtr, "\nMIDI pipeline started on: %s GMT \n", currentTime);
00804
00805
00806 if (currentTime) free (currentTime);
00807
00808 return;
00809 }
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828 void handoverReport (
00829 char *fileName,
00830 FILE **filePtr)
00831 {
00832
00833
00834
00835 const char routine[] = "handoverReport";
00836 char *tempStr=NULL;
00837 time_t now;
00838 struct tm *newTime=NULL;
00839 char *currentTime=NULL;
00840 struct stat buf;
00841
00842
00843
00844 if (diagnostic > 2) cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
00845 if (diagnostic > 2) fprintf(*filePtr, "Invoking routine '%s' \n", routine);
00846
00847
00848 tempStr = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00849 currentTime = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00850
00851
00852 if (stat (midiReportName, &buf) == 0) remove (midiReportName);
00853 midiReportPtr = fopen(midiReportName, "w");
00854 if (!midiReportPtr) midiReportError (*filePtr, routine, __FILE__, __LINE__, "Cannot create output event log file");
00855
00856 if (stat (midiQcLogName, &buf) == 0) remove (midiQcLogName);
00857 midiQcLogPtr = fopen(midiQcLogName, "w");
00858 if (!midiQcLogPtr) midiReportError (*filePtr, routine, __FILE__, __LINE__, "Cannot create output QC log file");
00859
00860 fclose (*filePtr);
00861
00862 *filePtr = fopen (fileName, "r");
00863 while (fgets (tempStr, MAX_STRING_LENGTH, *filePtr) != NULL)
00864 fprintf (midiReportPtr, "%s", tempStr);
00865
00866 now = time(NULL);
00867 newTime = gmtime (&now);
00868 strftime (currentTime, MIN_STRING_LENGTH, "%a %d %b %Y at %H:%M:%S", newTime);
00869 cpl_msg_info(cpl_func,"\nMIDI Data Reduction for batch %d started on: %s GMT \n", batchNumber, currentTime);
00870 fprintf (midiReportPtr, "\nMIDI Data Reduction for batch %d started on: %s GMT \n", batchNumber, currentTime);
00871
00872 fclose (*filePtr);
00873 *filePtr = fopen (fileName, "a");
00874
00875
00876 if (tempStr) free (tempStr);
00877 if (currentTime) free (currentTime);
00878
00879 return;
00880 }
00881
00882
00883
00889
00890
00891 void getMaskFileFromSof(MidiFiles * fileNames, cpl_frameset * frameset)
00892 {
00893
00894
00895 cpl_frame * cur_frame;
00896 char * tag_firstframe=NULL;
00897 char * tag_mask=NULL;
00898 char * tag=NULL;
00899 char gris_name[100]= "";
00900 cpl_propertylist * plist;
00901 int i;
00902
00903
00904
00905
00906
00907
00908 cpl_ensure_code(midi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
00909 cpl_error_get_code());
00910
00911
00912 cur_frame = cpl_frameset_get_first(frameset);
00913 if (cur_frame == NULL) {
00914 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00915 "SOF does not have any file");
00916 return;
00917 }
00918
00919
00920
00921 for(i=0; i<cpl_frameset_get_size(frameset);i++){
00922
00923
00924 if((cpl_frame_get_group(cur_frame) == CPL_FRAME_GROUP_RAW)){
00925 break;
00926 }
00927 else {
00928 cur_frame = cpl_frameset_get_next( frameset );
00929
00930 }
00931
00932 }
00933
00934 if (cur_frame == NULL) {
00935 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
00936 "SOF does not have any raw files");
00937 cpl_msg_error(cpl_func, "SOF does not have any raw files");
00938 return;
00939 }
00940
00941
00942 tag_firstframe = (char*)cpl_frame_get_tag(cur_frame);
00943 plist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
00944
00945 if (cpl_propertylist_has(plist, "ESO INS GRIS NAME") == 1)
00946 {
00947 strcpy(gris_name,cpl_propertylist_get_string(plist, "ESO INS GRIS NAME"));
00948
00949 }
00950
00951
00952
00953 if ((strcmp(tag_firstframe, MIDI_HIGH_SENS_CALIB)==0 ||
00954 strcmp(tag_firstframe, MIDI_HIGH_SENS_SCIENCE)==0) && strcmp(gris_name,"GRISM")==0) {
00955 tag_mask = cpl_sprintf("%s", "KAPPA_HS_MASK_GRISM");
00956 }
00957
00958 else if ((strcmp(tag_firstframe, MIDI_HIGH_SENS_CALIB)==0 ||
00959 strcmp(tag_firstframe, MIDI_HIGH_SENS_SCIENCE)==0) && strcmp(gris_name,"PRISM")==0) {
00960 tag_mask = cpl_sprintf("%s", "KAPPA_HS_MASK_PRISM");
00961 }
00962
00963 else if ((strcmp(tag_firstframe, MIDI_SCI_PHOT_CALIB)==0 ||
00964 strcmp(tag_firstframe, MIDI_SCI_PHOT_SCIENCE)==0) && strcmp(gris_name,"GRISM")==0) {
00965 tag_mask = cpl_sprintf("%s", "KAPPA_SP_MASK_GRISM");
00966 }
00967
00968 else if ((strcmp(tag_firstframe, MIDI_SCI_PHOT_CALIB)==0 ||
00969 strcmp(tag_firstframe, MIDI_SCI_PHOT_SCIENCE)==0) && strcmp(gris_name,"PRISM")==0) {
00970 tag_mask = cpl_sprintf("%s", "KAPPA_SP_MASK_PRISM");
00971 }
00972
00973 else {
00974 tag_mask = cpl_sprintf("%s", "NO MASK");
00975 }
00976
00977
00978 cur_frame = cpl_frameset_get_first(frameset);
00979
00980 while(cur_frame)
00981 {
00982
00983 tag = (char*)cpl_frame_get_tag(cur_frame);
00984
00985 if (strcmp(tag, tag_mask)==0) {
00986
00987 sprintf(fileNames->maskFileName,"%s",cpl_frame_get_filename(cur_frame));
00988 }
00989
00990 cur_frame = cpl_frameset_get_next( frameset );
00991 }
00992
00993
00994
00995
00996
00997 cpl_propertylist_delete(plist);
00998 cpl_free(tag_mask);
00999 return ;
01000 }