visibility.c

00001 /******************************************************************************
00002 *******************************************************************************
00003 *               European Southern Observatory
00004 *             VLTI MIDI Data Reduction Software
00005 *
00006 * Module name:  visibility.c
00007 * Description:  Contains routines for all visibility computation routines
00008 *
00009 * History:
00010 * 21-Jul-03     (csabet) Created
00011 *******************************************************************************
00012 ******************************************************************************/
00013 
00014 /******************************************************************************
00015 *   Compiler directives
00016 ******************************************************************************/
00017 
00018 /******************************************************************************
00019 *   Include files
00020 ******************************************************************************/
00021 #include <stdio.h>
00022 #include <cpl.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <math.h>
00026 #include "midiGlobal.h"
00027 #include "midiLib.h"
00028 #include "visibility.h"
00029 #include "errorHandling.h"
00030 #include "diagnostics.h"
00031 #include "midi_dfs.h"
00032 
00033 /*============================ C O D E    A R E A ===========================*/
00034 
00035 
00036 
00037 
00038 /******************************************************************************
00039 *               European Southern Observatory
00040 *            VLTI MIDI Data Reduction Software
00041 *
00042 * Module name:  computeCalibVis
00043 * Input/Output: See function arguments to avoid duplication
00044 * Description:  This routine computes the final visibility on SCIENCE targets. It
00045 *               requires the transfer function as well as the uncalibrated
00046 *               visibilities.
00047 *
00048 * History:
00049 * 08-Feb-05     (csabet) Created
00050 ******************************************************************************/
00051 void computeCalibVis (
00052     MidiFiles        *fileNames,                // In: Pointer to MIDI file structure
00053     ImageFormat        *format,                // In: Image structure
00054     DispersedResult    *dispResult,            // In: Dispersed result structure
00055     int                *error,                    // Ou: Status
00056     cpl_parameterlist  *parlist,
00057     cpl_frameset       *frameset)
00058 {
00059 
00060     //    Local Declarations
00061     //    ------------------
00062     const char  routine[] = "computeCalibVis";
00063     int         X;
00064 /*
00065     FILE        *trfPtr=NULL;
00066     int         numOfRecords;
00067     char        *givenGrismId;
00068     char             * tag=NULL;
00069 */
00070     char             * softag=NULL;
00071     cpl_frame        * cur_frame=NULL;
00072     cpl_table        * table=NULL;
00073     cpl_errorstate     prestate = cpl_errorstate_get();   
00074     int                ext_trf=0;
00075     int                dimentrf=0;
00076     cpl_frame        * local_trf_frame=NULL;
00077     cpl_propertylist * dummy_propertylist = NULL;    
00078     cpl_propertylist * qclist=NULL;    
00079     char             * dataname=NULL;
00080     //    Algorithm
00081     //    ---------
00082     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00083     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
00084 
00085    cpl_msg_info(cpl_func,"\nComputing Calibrated Visibility for batch  %d \n", batchNumber);
00086    cpl_msg_info(cpl_func,"----------------------------------------- \n");
00087     fprintf (midiReportPtr, "\nComputing Calibrated Visibility for batch  %d \n", batchNumber);
00088     fprintf (midiReportPtr, "----------------------------------------- \n");
00089 
00090     //    Reset parameters
00091     *error = 0;
00092     dispResult->trfExists = 0;
00093     dispResult->calibVisExists = 0;
00094 
00095 /* -------------------------------------------------------------------------- */
00096     prestate = cpl_errorstate_get();   
00097 
00098 /*       Grism or Prism? */
00099     if (strcmp(format->grismId,"GRISM")==0){
00100        softag = cpl_sprintf("%s", MIDI_TRF_GRISM);
00101     }
00102     else if (strcmp(format->grismId,"PRISM")==0){
00103        softag = cpl_sprintf("%s", MIDI_TRF_PRISM);
00104     }
00105     else {
00106        cpl_msg_warning(cpl_func, "No GRISM or PRISM found");   
00107        cpl_msg_warning(cpl_func, "No transfer function applied");
00108        cpl_errorstate_set(prestate); 
00109        *error = 1;
00110        return;
00111     }
00112     
00113     cur_frame = cpl_frameset_find( frameset, softag );    
00114 
00115     /* 
00116        In case no transfer function file was sent (i.e. during online pipeline run) then
00117        check the tmp dir
00118     */   
00119     if( !cur_frame )      
00120     {
00121        /* PIPELINE will not send the trf. Try to load it from tmp */
00122        dummy_propertylist=cpl_propertylist_load("/tmp/MIDI_trf.fits", 0);    
00123        if (dummy_propertylist != NULL)
00124        {
00125           local_trf_frame=cpl_frame_new();
00126           cpl_frame_set_filename (local_trf_frame,"/tmp/MIDI_trf.fits");
00127           cpl_frame_set_group (local_trf_frame, CPL_FRAME_GROUP_CALIB);
00128           cpl_frame_set_level (local_trf_frame, CPL_FRAME_LEVEL_FINAL);
00129           cpl_frame_set_tag (local_trf_frame, cpl_propertylist_get_string(dummy_propertylist, "ESO PRO CATG"));
00130           cpl_frame_set_type (local_trf_frame, CPL_FRAME_TYPE_TABLE);
00131           cpl_frameset_insert(frameset, local_trf_frame);
00132           cpl_propertylist_delete(dummy_propertylist);          
00133         }
00134     }
00135 
00136     cur_frame = cpl_frameset_find( frameset, softag );    
00137     
00138     if (cur_frame)
00139     {
00140        cpl_msg_info(cpl_func, "Transfer function found in the SOF: %s\n",cpl_frame_get_filename(cur_frame));   
00141     }
00142 
00143     
00144     if (!cur_frame) {
00145        cpl_msg_warning(cpl_func, "No siutable transfer function found!");   
00146        cpl_msg_warning(cpl_func, "No transfer function applied to the data");
00147        cpl_free(softag);
00148        cpl_errorstate_set(prestate); 
00149        *error = 1;
00150        return;
00151     }
00152 
00153     cpl_free(softag);
00154     
00155     /* Load extension  TRANSFER_FUNCTION */ 
00156     
00157     prestate = cpl_errorstate_get();   
00158 
00159     ext_trf=cpl_fits_find_extension(cpl_frame_get_filename(cur_frame),"TRANSFER_FUNCTION");
00160 
00161     if((table = cpl_table_load(cpl_frame_get_filename(cur_frame), ext_trf, 1))==NULL)
00162     {
00163        cpl_msg_info(cpl_func, "No siutable table found in the file %s\n",cpl_frame_get_filename(cur_frame));   
00164        cpl_msg_warning(cpl_func, "No transfer function applied");
00165        cpl_errorstate_set(prestate);  
00166        *error = 1;
00167        return;
00168     }
00169 
00170         //    Check if number of records is consistent
00171     dimentrf=cpl_table_get_nrow(table);
00172     if ( dimentrf != format->iXWidth)
00173     {
00174        cpl_msg_warning(cpl_func, "Inconsistent Number of Records found");   
00175        cpl_msg_warning(cpl_func, "No transfer function applied");
00176        cpl_errorstate_set(prestate);  
00177        cpl_table_delete(table);
00178        *error = 1;
00179        return;
00180     }
00181     
00182     /* If all is Ok read the values */
00183     
00184     if (cpl_table_has_column(table, "TRF") && cpl_table_has_column(table, "TRF_ERROR") )
00185     {
00186 
00187        for (X=0; X<dimentrf;X++){
00188           dispResult->trf[X]=cpl_table_get_float(table, "TRF", X, NULL);
00189           dispResult->trfErr[X]=cpl_table_get_float(table, "TRF_ERROR", X, NULL);
00190        }
00191     }
00192     else{
00193        cpl_msg_info(cpl_func, "No siutable table column found in the file %s\n",cpl_frame_get_filename(cur_frame));   
00194        cpl_msg_warning(cpl_func,"No transfer function applied");
00195        cpl_table_delete(table);
00196        *error = 1;
00197        return;
00198     }
00199 
00200 
00201 /* Save the fits table  into a fits file */
00202     qclist=cpl_propertylist_new();    
00203 
00204     /* Save QC parameters from the original file to the new product */ 
00205     dummy_propertylist = cpl_propertylist_load(cpl_frame_get_filename(cur_frame), 0);
00206     cpl_propertylist_copy_property_regexp(qclist, dummy_propertylist, "^ESO QC",0);    
00207     cpl_propertylist_delete(dummy_propertylist);
00208     
00209     if (strcmp(format->grismId,"GRISM")==0) {
00210        cpl_propertylist_update_string(qclist, CPL_DFS_PRO_CATG, "TRF_GRISM");
00211        dataname=cpl_sprintf("MIDI_trf_grism.fits");
00212     }
00213     if (strcmp(format->grismId,"PRISM")==0) {
00214        cpl_propertylist_update_string(qclist, CPL_DFS_PRO_CATG, "TRF_PRISM");
00215        dataname=cpl_sprintf("MIDI_trf_prism.fits");
00216     }
00217     cpl_propertylist_append_string(qclist, "EXTNAME", "TRANSFER_FUNCTION");
00218     
00219     
00220     cpl_dfs_save_table(frameset, NULL, parlist, frameset, NULL, table, 
00221                        qclist, "midi_fringe_all",
00222                        qclist, NULL, 
00223                        PACKAGE "/" PACKAGE_VERSION,
00224                        dataname);
00225 
00226     cpl_propertylist_delete(qclist);        
00227     cpl_free(dataname); 
00228     cpl_table_delete(table);
00229 
00230 
00231 
00232 /* -------------------------------------------------------------------------- */
00233     //    Allicate memory
00234 /*     givenGrismId = (char *) calloc (MIN_STRING_LENGTH, sizeof (char)); */
00235 
00236 /*     //    Check if Transfer Function is available. Try to open the file for reading */
00237 /*     if (diagnostic)cpl_msg_info(cpl_func,"Trying to extract Transfer Functions from %s \n", fileNames->trfNameRead); */
00238 /*     fprintf (midiReportPtr, "Trying to extract Transfer Functions from %s \n", fileNames->trfNameRead); */
00239 /*     if ((trfPtr = fopen (fileNames->trfNameRead, "r")) == NULL) */
00240 /*     { */
00241 /*         *error = 1; */
00242 /*         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open Transfer Function file"); */
00243 /*         free (givenGrismId); */
00244 /*         return; */
00245 /*     } */
00246     
00247 /*     //    Read Grism ID */
00248 /*     if (fscanf (trfPtr, "%s \n", givenGrismId) == EOF) */
00249 /*     { */
00250 /*         *error = 1; */
00251 /*         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Grism ID"); */
00252 /*         if (trfPtr) fclose (trfPtr); */
00253 /*         free (givenGrismId); */
00254 /*         if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
00255 /*         return; */
00256 /*     } */
00257 /*     else */
00258 /*     { */
00259 /*         //    Check if the given Grism ID is the same as that of the current batch */
00260 /*         if (strcmp (format->grismId, givenGrismId) != 0) */
00261 /*         { */
00262 /*             midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Inconsistent Grism ID"); */
00263 /*             if (diagnostic)cpl_msg_info(cpl_func,"Given grism ID          = %s. Expected %s \n", givenGrismId, format->grismId); */
00264 /*             fprintf (midiReportPtr, "Given grism ID          = %s. Expected %s \n", givenGrismId, format->grismId); */
00265 /*             if (trfPtr) fclose (trfPtr); */
00266 /*             free (givenGrismId); */
00267 /*             if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
00268 /*             return; */
00269 /*         } */
00270 /*         if (diagnostic)cpl_msg_info(cpl_func,"Given grism ID          = %s. Expected %s \n", givenGrismId, format->grismId); */
00271 /*         fprintf (midiReportPtr, "Given grism ID          = %s. Expected %s \n", givenGrismId, format->grismId); */
00272 /*     } */
00273     
00274 /*     //    Get number of records */
00275 /*     if (fscanf (trfPtr, "%d \n", &numOfRecords) == EOF) */
00276 /*     { */
00277 /*         *error = 1; */
00278 /*         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Number of Records"); */
00279 /*         if (trfPtr) fclose (trfPtr); */
00280 /*         free (givenGrismId); */
00281 /*         if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
00282 /*         return; */
00283 /*     } */
00284 /*     else  */
00285 /*     { */
00286 /*         //    Check if number of records is consistent */
00287 /*         if (numOfRecords != format->iXWidth) */
00288 /*         { */
00289 /*             *error = 1; */
00290 /*             sprintf (midiMessage, "Inconsistent Number of Records from %s. Expected %d",  */
00291 /*                 fileNames->trfNameRead, format->iXWidth);  */
00292 /*             midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage); */
00293 /*             if (diagnostic)cpl_msg_info(cpl_func,"Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
00294 /*             fprintf (midiReportPtr, "Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
00295 /*             if (trfPtr) fclose (trfPtr); */
00296 /*             free (givenGrismId); */
00297 /*             if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
00298 /*             return; */
00299 /*         } */
00300 /*         if (diagnostic)cpl_msg_info(cpl_func,"Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
00301 /*         fprintf (midiReportPtr, "Given Number of Records = %d. Expected %d \n", numOfRecords, format->iXWidth); */
00302 /*     } */
00303 
00304 /*     //    If all is well then try to load the data into the array */
00305 /*     for (X = 0; X < format->iXWidth; X++) */
00306 /*     { */
00307 /*         if (fscanf (trfPtr, "%f %f", &(dispResult->trf[X]), &(dispResult->trfErr[X])) == EOF) */
00308 /*         { */
00309 /*             *error = 1; */
00310 /*             midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Transfer Functions"); */
00311 /*             if (trfPtr) fclose (trfPtr); */
00312 /*             free (givenGrismId); */
00313 /*             if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
00314 /*             return; */
00315 /*         } */
00316 /*         fscanf (trfPtr, "\n"); */
00317 /*         if (diagnostic)cpl_msg_info(cpl_func,"Channel %3d = %f %f \n", X, (dispResult->trf)[X], (dispResult->trfErr)[X]); */
00318 /*         fprintf (midiReportPtr, "Channel %3d = %f %f \n", X, (dispResult->trf)[X], (dispResult->trfErr)[X]); */
00319 /*     } */
00320 /*     if (diagnostic)cpl_msg_info(cpl_func,"\nRead %d sets of transfer function values from %s \n", format->iXWidth, fileNames->trfNameRead); */
00321 /*     fprintf (midiReportPtr, "\nRead %d sets of transfer function values from %s \n", format->iXWidth, fileNames->trfNameRead); */
00322 /*     if (trfPtr) fclose (trfPtr); */
00323 /*     free (givenGrismId); */
00324 /*     if (strcmp (format->obsCatg, "SCIENCE") == 0) remove (fileNames->trfNameRead); */
00325 
00326 
00327     //    Compute calibrated visibilities
00328     if (diagnostic)cpl_msg_info(cpl_func,"\nChannel   Calibrated Visibility   Calibrated Visibility Error \n");
00329     if (diagnostic)cpl_msg_info(cpl_func,"------------------------------------------------------------- \n");
00330     fprintf (midiReportPtr, "\nChannel   Calibrated Visibility   Calibrated Visibility Error QCLOG \n");
00331     fprintf (midiReportPtr, "-------------------------------------------------------------   QCLOG\n");
00332     for (X = 0; X < format->iXWidth; X++)
00333     {
00334         if (badChannelList[X] || (dispResult->trf[X] <= 0.0))
00335         {
00336             badChannelList[X] |= BSL_DATA_ERROR;
00337             if (diagnostic)cpl_msg_info(cpl_func,"%3d                  <-- %s --> \n", X, UNAV);
00338             fprintf (midiReportPtr, "%3d                  <-- %s --> \n", X, UNAV);
00339             continue;
00340         }
00341 
00342         (dispResult->calibVis2)[X] = (dispResult->normVis2)[X] / (dispResult->trf)[X];
00343         (dispResult->calibVis2Err)[X] = (dispResult->normVis2Err)[X] / (fabs ((dispResult->trf)[X])) +
00344             (dispResult->trfErr)[X] * (fabs ((dispResult->normVis2)[X]) / ((dispResult->trf)[X] * (dispResult->trf)[X]));
00345 
00346         if (diagnostic)cpl_msg_info(cpl_func,"%3d         %5.4f                   %5.4f \n", 
00347             X, (dispResult->calibVis2)[X], (dispResult->calibVis2Err)[X]);
00348         fprintf (midiReportPtr, "%3d         %5.4f                   %5.4f QCLOG \n", 
00349             X, (dispResult->calibVis2)[X], (dispResult->calibVis2Err)[X]);
00350     }
00351 
00352     if (plotFile)
00353     {
00354         midiCreatePlotFile2D ("CalibVisCombined", "Combined Calibrated Visibility", 
00355             "Channale", "Visibility", 0, dispResult->calibVis2, 0, format->iXWidth, 1, 0);
00356             
00357         midiCreatePlotFile2D ("CalibVisErrCombined", "Combined Calibrated Visibility Error", 
00358             "Channel", "Visibility Error", 0, dispResult->calibVis2Err, 0, format->iXWidth, 1, 0);
00359 
00360         midiCreatePlotFile2D ("NormalizedUncalibVisCombined", "Combined Calibrated Visibility", 
00361             "Channale", "Visibility", 0, dispResult->calibVis2, 0, format->iXWidth, 1, 0);
00362             
00363         midiCreatePlotFile2D ("NormalizedUncalibVisErrCombined", "Combined Calibrated Visibility Error", 
00364             "Channel", "Visibility Error", 0, dispResult->calibVis2Err, 0, format->iXWidth, 1, 0);
00365     }
00366     
00367     //    Close files
00368     dispResult->trfExists = 1;
00369     dispResult->calibVisExists = 1;
00370 
00371     return;
00372 }
00373 /*****************************************************************************/
00374  
00375 /******************************************************************************
00376 *               European Southern Observatory
00377 *            VLTI MIDI Data Reduction Software
00378 *
00379 * Module name:  computeUncalibVisHSUndisp
00380 * Input/Output: See function arguments to avoid duplication
00381 * Description:  Uses the results of the estimateFringe() together with
00382 *               any other parameters (TBD) and errors and computes
00383 *               an estimate of the visibility. This routine applies to both
00384 *               CALIB and SCIENCE targets.
00385 *
00386 * History:
00387 * 02-Dec-03     (csabet) Created
00388 ******************************************************************************/
00389 void computeUncalibVisHSUndisp (
00390     RawVisibility    *rawVis,
00391     PhotometryResult *photom)
00392 {
00393 
00394     /*  Local Declarations
00395     --------------------*/
00396     const char  routine[] = "computeUncalibVisHSUndisp";
00397     
00398     /*  Algorithm
00399     -----------*/
00400     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00401     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
00402 
00403    cpl_msg_info(cpl_func,"\nComputing Uncalibrated Visibilities for batch  %d \n", batchNumber);
00404    cpl_msg_info(cpl_func,"--------------------------------------------- \n");
00405     fprintf (midiReportPtr, "\nComputing Uncalibrated Visibilities for batch  %d \n", batchNumber);
00406     fprintf (midiReportPtr, "--------------------------------------------- \n");
00407 
00408     rawVis->visErr = fabs (rawVis->vis * (photom->chop2ChopAErr[0] + photom->chop2ChopAErr[1] +
00409                     photom->chop2ChopBErr[0] + photom->chop2ChopBErr[1]) / (8.0 * sqrt(2.0)));
00410     rawVis->vis1Err = fabs (rawVis->vis1 * (photom->chop2ChopAErr[0] + photom->chop2ChopAErr[1] +
00411                     photom->chop2ChopBErr[0] + photom->chop2ChopBErr[1]) / 8.0);
00412     rawVis->vis2Err = fabs (rawVis->vis2 * (photom->chop2ChopAErr[0] + photom->chop2ChopAErr[1] +
00413                     photom->chop2ChopBErr[0] + photom->chop2ChopBErr[1]) / 8.0);
00414     rawVis->visSqrdErr = 2.0 * (rawVis->visErr * fabs (rawVis->vis));
00415     rawVis->visSqrd1Err = 2.0 * (rawVis->vis1Err * fabs (rawVis->vis1));
00416     rawVis->visSqrd2Err = 2.0 * (rawVis->vis2Err * fabs (rawVis->vis2));
00417 
00418    cpl_msg_info(cpl_func,"Uncalibrated Visibility         region 0       = %f \n", rawVis->vis);
00419    cpl_msg_info(cpl_func,"Uncalibrated Visibility         region 0 Error = %f \n", rawVis->visErr);
00420    cpl_msg_info(cpl_func,"Uncalibrated Visibility         region 1       = %f \n", rawVis->vis1);
00421    cpl_msg_info(cpl_func,"Uncalibrated Visibility         region 1 Error = %f \n", rawVis->vis1Err);
00422    cpl_msg_info(cpl_func,"Uncalibrated Visibility         region 2       = %f \n", rawVis->vis2);
00423    cpl_msg_info(cpl_func,"Uncalibrated Visibility         region 2 Error = %f \n", rawVis->vis2Err);
00424    cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 0       = %f \n", rawVis->visSqrd);
00425    cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 0 Error = %f \n", rawVis->visSqrdErr);
00426    cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 1       = %f \n", rawVis->visSqrd1);
00427    cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 1 Error = %f \n", rawVis->visSqrd1Err);
00428    cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 2       = %f \n", rawVis->visSqrd2);
00429    cpl_msg_info(cpl_func,"Uncalibrated Squared Visibility region 2 Error = %f \n", rawVis->visSqrd2Err);
00430 
00431     fprintf (midiReportPtr, "Uncalibrated Visibility         region 0       = %f \n", rawVis->vis);
00432     fprintf (midiReportPtr, "Uncalibrated Visibility         region 0 Error = %f \n", rawVis->visErr);
00433     fprintf (midiReportPtr, "Uncalibrated Visibility         region 1       = %f \n", rawVis->vis1);
00434     fprintf (midiReportPtr, "Uncalibrated Visibility         region 1 Error = %f \n", rawVis->vis1Err);
00435     fprintf (midiReportPtr, "Uncalibrated Visibility         region 2       = %f \n", rawVis->vis2);
00436     fprintf (midiReportPtr, "Uncalibrated Visibility         region 2 Error = %f \n", rawVis->vis2Err);
00437     fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 0       = %f \n", rawVis->visSqrd);
00438     fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 0 Error = %f \n", rawVis->visSqrdErr);
00439     fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 1       = %f \n", rawVis->visSqrd1);
00440     fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 1 Error = %f \n", rawVis->visSqrd1Err);
00441     fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 2       = %f \n", rawVis->visSqrd2);
00442     fprintf (midiReportPtr, "Uncalibrated Squared Visibility region 2 Error = %f \n", rawVis->visSqrd2Err);
00443 
00444     return;
00445 }
00446 /*****************************************************************************/
00447 
00448 
00449 /******************************************************************************
00450 *               European Southern Observatory
00451 *            VLTI MIDI Data Reduction Software
00452 *
00453 * Module name:  computeCalibVisHSUndisp
00454 * Input/Output: See function arguments to avoid duplication
00455 * Description:  This routine computes the final visibility on SCIENCE targets. It
00456 *               requires the transfer function as well as the uncalibrated
00457 *               visibilities.
00458 *
00459 * History:
00460 * 21-Jul-03     (csabet) Created
00461 ******************************************************************************/
00462 void computeCalibVisHSUndisp (
00463     MidiFiles                *fileNames,    // In: Pointer to MIDI file structure
00464     RawVisibility            *rawVis,    // In: Raw visibilities
00465     TransferFunction        *trf,        // In: Transfer Functions
00466     CalibratedVisibility    *calibVis,    // Ou: Calibrated visibilities
00467     int                        *error)        // Ou: Status
00468 {
00469 
00470     /*  Local Declarations
00471     --------------------*/
00472     const char  routine[] = "computeCalibVisHSUndisp";
00473     FILE        *trfPtr;
00474     int         i;
00475 
00476     /*  Algorithm
00477     -----------*/
00478     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00479     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
00480 
00481    cpl_msg_info(cpl_func,"\nComputing Calibrated Visibility for batch  %d \n", batchNumber);
00482    cpl_msg_info(cpl_func,"----------------------------------------- \n");
00483     fprintf (midiReportPtr, "\nComputing Calibrated Visibility for batch  %d \n", batchNumber);
00484     fprintf (midiReportPtr, "----------------------------------------- \n");
00485 
00486     /* Reset parameters */
00487     *error = 0;
00488     trf->exists = 0;
00489     calibVis->exists = 0;
00490 
00491     /* Open the transfer function file for reading */
00492     if ((trfPtr = fopen (fileNames->trfNameRead, "r")) == NULL)
00493     {
00494         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open Transfer Functions file");
00495         *error = 1;
00496         return;
00497     }
00498 
00499     /* Read the transfer fuctions from the file */
00500     for (i = 0; i < 6; i++)
00501     {
00502         if (fscanf (trfPtr, "%f\n", &(trf->trf[i])) == EOF)
00503         {
00504             midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Transfer Functions");
00505             *error = 1;
00506             return;
00507         }
00508         if (fscanf (trfPtr, "%f\n", &(trf->trfErr[i])) == EOF)
00509         {
00510             midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot read Transfer Functions");
00511             *error = 1;
00512             return;
00513         }
00514     }
00515 
00516     /* Compute calibrated visibilities */
00517     if (trf->trf[0] == 0 || trf->trfErr[0] == 0 ||
00518         trf->trf[1] == 0 || trf->trfErr[1] == 0 ||
00519         trf->trf[2] == 0 || trf->trfErr[2] == 0 ||
00520         trf->trf[3] == 0 || trf->trfErr[3] == 0 ||
00521         trf->trf[4] == 0 || trf->trfErr[4] == 0 ||
00522         trf->trf[5] == 0 || trf->trfErr[5] == 0)
00523     {
00524         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, 
00525             "A singularity encountered. Cannot compute Calibrated Visibilities");
00526         *error = 1;
00527         return;
00528     }
00529     else
00530     {
00531         calibVis->vis[0] = rawVis->vis / trf->trf[0];
00532         calibVis->visErr[0] = rawVis->visErr / (fabs (trf->trf[0])) +
00533             trf->trfErr[0] * (fabs (rawVis->vis) / (trf->trf[0] * trf->trf[0]));
00534 
00535         calibVis->vis[1] = rawVis->vis1 / trf->trf[1];
00536         calibVis->visErr[1] = rawVis->vis1Err / (fabs (trf->trf[1])) +
00537             trf->trfErr[1] * (fabs (rawVis->vis1) / (trf->trf[1] * trf->trf[1]));
00538 
00539         calibVis->vis[2] = rawVis->vis2 / trf->trf[2];
00540         calibVis->visErr[2] = rawVis->vis2Err / (fabs (trf->trf[2])) +
00541             trf->trfErr[2] * (fabs (rawVis->vis2) / (trf->trf[2] * trf->trf[2]));
00542 
00543         calibVis->visSqrd[0] = rawVis->visSqrd / trf->trf[3];
00544         calibVis->visSqrdErr[0] = rawVis->visSqrdErr / (fabs (trf->trf[3])) +
00545             trf->trfErr[3] * (fabs (rawVis->visSqrd) / (trf->trf[3] * trf->trf[3]));
00546 
00547         calibVis->visSqrd[1] = rawVis->visSqrd1 / trf->trf[4];
00548         calibVis->visSqrdErr[1] = rawVis->visSqrd1Err / (fabs (trf->trf[4])) +
00549             trf->trfErr[4] * (fabs (rawVis->visSqrd1) / (trf->trf[4] * trf->trf[4]));
00550 
00551         calibVis->visSqrd[2] = rawVis->visSqrd2 / trf->trf[5];
00552         calibVis->visSqrdErr[2] = rawVis->visSqrd2Err / (fabs (trf->trf[5])) +
00553             trf->trfErr[5] * (fabs (rawVis->visSqrd2) / (trf->trf[5] * trf->trf[5]));
00554     }
00555 
00556     /* Report results and close file */
00557    cpl_msg_info(cpl_func,"Calibrated Visibility         region 0       = %f \n", calibVis->vis[0]);
00558    cpl_msg_info(cpl_func,"Calibrated Visibility         region 0 Error = %f \n", calibVis->visErr[0]);
00559    cpl_msg_info(cpl_func,"Calibrated Visibility         region 1       = %f \n", calibVis->vis[1]);
00560    cpl_msg_info(cpl_func,"Calibrated Visibility         region 1 Error = %f \n", calibVis->visErr[1]);
00561    cpl_msg_info(cpl_func,"Calibrated Visibility         region 2       = %f \n", calibVis->vis[2]);
00562    cpl_msg_info(cpl_func,"Calibrated Visibility         region 2 Error = %f \n", calibVis->visErr[2]);
00563    cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 0       = %f \n", calibVis->visSqrd[0]);
00564    cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 0 Error = %f \n", calibVis->visSqrdErr[0]);
00565    cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 1       = %f \n", calibVis->visSqrd[1]);
00566    cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 1 Error = %f \n", calibVis->visSqrdErr[1]);
00567    cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 2       = %f \n", calibVis->visSqrd[2]);
00568    cpl_msg_info(cpl_func,"Calibrated Squared Visibility region 2 Error = %f \n", calibVis->visSqrdErr[2]);
00569 
00570     fprintf (midiReportPtr, "Calibrated Visibility         region 0       = %f (QCLOG)\n", calibVis->vis[0]);
00571     fprintf (midiReportPtr, "Calibrated Visibility         region 0 Error = %f (QCLOG)\n", calibVis->visErr[0]);
00572     fprintf (midiReportPtr, "Calibrated Visibility         region 1       = %f (QCLOG)\n", calibVis->vis[1]);
00573     fprintf (midiReportPtr, "Calibrated Visibility         region 1 Error = %f (QCLOG)\n", calibVis->visErr[1]);
00574     fprintf (midiReportPtr, "Calibrated Visibility         region 2       = %f (QCLOG)\n", calibVis->vis[2]);
00575     fprintf (midiReportPtr, "Calibrated Visibility         region 2 Error = %f (QCLOG)\n", calibVis->visErr[2]);
00576     fprintf (midiReportPtr, "Calibrated Squared Visibility region 0       = %f (QCLOG)\n", calibVis->visSqrd[0]);
00577     fprintf (midiReportPtr, "Calibrated Squared Visibility region 0 Error = %f (QCLOG)\n", calibVis->visSqrdErr[0]);
00578     fprintf (midiReportPtr, "Calibrated Squared Visibility region 1       = %f (QCLOG)\n", calibVis->visSqrd[1]);
00579     fprintf (midiReportPtr, "Calibrated Squared Visibility region 1 Error = %f (QCLOG)\n", calibVis->visSqrdErr[1]);
00580     fprintf (midiReportPtr, "Calibrated Squared Visibility region 2       = %f (QCLOG)\n", calibVis->visSqrd[2]);
00581     fprintf (midiReportPtr, "Calibrated Squared Visibility region 2 Error = %f (QCLOG)\n", calibVis->visSqrdErr[2]);
00582 
00583     fclose (trfPtr);
00584     remove (fileNames->trfNameRead);
00585     trf->exists = 1;
00586     calibVis->exists = 1;
00587 
00588     return;
00589 }
00590 /*****************************************************************************/
00591 
00592  
00593 /******************************************************************************
00594 *               European Southern Observatory
00595 *            VLTI MIDI Data Reduction Software
00596 *
00597 * Module name:  computeUncalibVis
00598 * Input/Output: See function arguments to avoid duplication
00599 * Description:  Computes DISPERSED Uncalibrated Normalized Visibility
00600 *
00601 * History:
00602 * 21-Oct-04     (JM) 
00603 * 21-Jan-05     (csabet) Cleaned up and Integrated
00604 ******************************************************************************/
00605 void computeUncalibVis (
00606     ImageFormat        *format,    // In: General data format
00607     float            *freqFound,    // IO: Wavelength calibration
00608     DispersedResult    *dispResult,// In: Dispersed result structure
00609     int                *error)        // Ou: Error status
00610 {
00611  
00612     /*  Local Declarations
00613     --------------------*/
00614     const char  routine[] = "computeUncalibVis";
00615     int         X, n;      
00616     float         errfromvis, neterr;
00617     double         phot, photA, photB;
00618     
00619     /*  Algorithm
00620     -----------*/
00621     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00622     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
00623    cpl_msg_info(cpl_func,"\nComputing Normalized Uncalibrated Visibility for batch  %d \n", batchNumber);
00624    cpl_msg_info(cpl_func,"------------------------------------------------------ \n");
00625     fprintf (midiReportPtr, "\nComputing Normalized Uncalibrated Visibility for batch  %d \n", batchNumber);
00626     fprintf (midiReportPtr, "------------------------------------------------------ \n");
00627 
00628     //    Reset
00629     *error = 0;
00630         
00631     //    First for photometry. For SCI_PHOT each photometry has one region to process
00632     for (X = 0; X < format->iXWidth; X++)
00633     {
00634         if (badChannelList[X])
00635             continue;
00636             
00637         if (strcmp (format->beamCombiner, "SCI_PHOT") == 0)
00638         {
00639             phot = 4.F * (dispResult->photomA)[0][X] * (dispResult->photomB)[0][X];
00640             (dispResult->photomNet2Err)[X] = sqrt(sqr((dispResult->photomAErr)[0][X] /
00641                 (dispResult->photomA)[0][X]) + sqr((dispResult->photomBErr)[0][X] /
00642                 (dispResult->photomB)[0][X]));
00643         }
00644         else
00645         {
00646             photA = (dispResult->photomA)[0][X] + (dispResult->photomA)[1][X];
00647             photB = (dispResult->photomB)[0][X] + (dispResult->photomB)[1][X];
00648             phot = 4.F*photA*photB;
00649             (dispResult->photomNet2Err)[X] = sqrt((sqr((dispResult->photomAErr)[0][X]) +
00650                 sqr((dispResult->photomAErr)[1][X])) / sqr(photA) +
00651                 (sqr((dispResult->photomBErr)[0][X]) +
00652                 sqr((dispResult->photomBErr)[1][X])) / sqr(photB));
00653         }
00654 
00655         if (phot > 0.F) 
00656             dispResult->photomNet2[X] = phot;    // do not ever insert a negative value here!!
00657         else
00658             dispResult->photomNet2Err[X] = 0.F;// set the err to zero when the photom itself is invalid.        
00659     }
00660 
00661     //    Now compute the visibility^2
00662     n = 0;
00663     for (X = 0; X < format->iXWidth; X++)
00664     {
00665         if (badChannelList[X])
00666             continue;
00667             
00668         if ((dispResult->photomNet2)[X] > 0.F)
00669             (dispResult->normVis2)[X] = (dispResult->rawVis2)[X] / (dispResult->photomNet2)[X];
00670         else
00671             (dispResult->normVis2)[X] = 0.F;
00672             
00673         if ((dispResult->normVis2)[X] <= 0.0)
00674         {
00675             (dispResult->normVis2)[X] = 0.F;
00676             badChannelList[X] |= BSL_DATA_ERROR;
00677         }
00678         else
00679             n++;
00680     }
00681 
00682     if (!n)
00683     {
00684         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot find any good visibility range");
00685         *error = 1;
00686         return;
00687     }
00688 
00689     if (diagnostic)cpl_msg_info(cpl_func,"\nChannel   Freq / Wave    Net photometry   Visibility^2    RMS Photometry     Errors percent \n");
00690     fprintf (midiReportPtr, "\nChannel   Freq / Wave    Net photometry   Visibility^2    RMS Photometry     Errors percent       QCLOG \n");
00691     if (diagnostic)cpl_msg_info(cpl_func,"         THz  micron       ADU/frame       normalized      Error percent     from Vis     Net \n");
00692     fprintf (midiReportPtr, "         THz  micron       ADU/frame       normalized      Error percent     from Vis     Net     QCLOG \n");
00693 
00694     for (X = 0; X < format->iXWidth; X++)
00695     {
00696         if (badChannelList[X])
00697         {
00698             if (diagnostic) cpl_msg_info(cpl_func,"%3d    %6.3f   %6.3f               <-- %s --> \n", 
00699                 X, 299.8F/freqFound[X], freqFound[X], UNAV);
00700             fprintf (midiReportPtr, "%3d    %6.3f   %6.3f               <-- %s -->                       QCLOG \n", 
00701                 X, 299.8F/freqFound[X], freqFound[X], UNAV);
00702             continue;
00703         }
00704 
00705         if (diagnostic) cpl_msg_info(cpl_func,"%3d ", X);    // Tell the column and region....
00706         fprintf (midiReportPtr, "%3d ", X);        // Tell the column and region....
00707  
00708                 
00709         if (diagnostic)cpl_msg_info(cpl_func,"   %6.3f   %6.3f", 299.8F/freqFound[X], freqFound[X]);
00710         if (diagnostic)cpl_msg_info(cpl_func,"   %9.3f", sqrt((dispResult->photomNet2)[X]));
00711         if (diagnostic)cpl_msg_info(cpl_func,"           %7.4f", (dispResult->normVis2)[X]);
00712         if (diagnostic)cpl_msg_info(cpl_func,"           %7.2f", 100.F*(dispResult->photomNet2Err)[X]);
00713         fprintf (midiReportPtr, "   %6.3f   %6.3f", 299.8F/freqFound[X], freqFound[X]);
00714         fprintf (midiReportPtr, "   %9.3f", sqrt((dispResult->photomNet2)[X]));
00715         fprintf (midiReportPtr, "           %7.4f", (dispResult->normVis2)[X]);
00716         fprintf (midiReportPtr, "           %7.2f", 100.F*(dispResult->photomNet2Err)[X]);
00717         errfromvis = (dispResult->rawVis2Err)[X] / (dispResult->rawVis2)[X]; // This must be improved. csabet 02-02-05
00718         neterr = sqrt(sqr(errfromvis) + sqr((dispResult->photomNet2Err)[X]));
00719         (dispResult->normVis2Err)[X] = neterr;     // This must be improved. csabet 07-02-05
00720         if (diagnostic)cpl_msg_info(cpl_func,"       %8.2f", 100.F*errfromvis);
00721         if (diagnostic)cpl_msg_info(cpl_func,"       %8.2f", 100.F*neterr);
00722         fprintf (midiReportPtr, "       %8.2f", 100.F*errfromvis);
00723         fprintf (midiReportPtr, "       %8.2f", 100.F*neterr);
00724 
00725         if (diagnostic)cpl_msg_info(cpl_func,"\n");
00726         fprintf (midiReportPtr, "     QCLOG \n");
00727     }
00728 
00729     if (plotFile)
00730     {
00731         midiCreatePlotFile2D ("PhotomNetCombined", "Combined Net Photometry", 
00732             "Channel", "Photometry", 0, dispResult->photomNet2, 0, format->iXWidth, 1, 0);
00733         midiCreatePlotFile2D ("PhotomNetErrCombined", "Combined Net Photometry Error", 
00734             "Channel", "Photometry Error", 0, dispResult->photomNet2Err, 0, format->iXWidth, 1, 0);
00735         midiCreatePlotFile2D ("NormalizedUncalibVisCombined", "Combined Normalized Uncalibrated Visibility", 
00736             "Channel", "Visibility", 0, dispResult->normVis2, 0, format->iXWidth, 1, 0);
00737         midiCreatePlotFile2D ("NormalizedUncalibVisErrCombined", "Combined Normalized Uncalibrated Visibility Error", 
00738             "Channel", "Visibility Error", 0, dispResult->normVis2Err, 0, format->iXWidth, 1, 0);
00739     }
00740 
00741     //    Compute Binned Uncalibrated Visibilities
00742     computeBinnedUncalibVis (format, dispResult, error);
00743     if (*error)
00744     {
00745         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot compute Binned Uncalibrated visibilities");
00746         return;
00747     }
00748     
00749     return;
00750 }
00751 /*****************************************************************************/
00752 
00753 
00754 /******************************************************************************
00755 *               European Southern Observatory
00756 *            VLTI MIDI Data Reduction Software
00757 *
00758 * Module name:  normalizeVis
00759 * Input/Output: See function arguments to avoid duplication
00760 * Description:
00761 *
00762 *
00763 * History:
00764 * 21-Jul-03     (csabet) Created routine template
00765 ******************************************************************************/
00766 void normalizeVis (
00767     RawVisibility    *rawVis,    // UNnormalized visibilities, get changed to normalized thru pointer
00768     float           photomA[],    // Photometry of A telescope, each region
00769     float           photomB[])    // Photometry of B telescope, each region
00770     
00771 {    /*  Local Declarations
00772     --------------------*/
00773     const char  routine[] = "normalizeVis";
00774 
00775     /*  Algorithm
00776     -----------*/
00777     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s'  \n", routine);
00778     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s'  \n", routine);
00779     
00780 // Assumes scanmix is equal between regions
00781     if (((photomA[0] + photomA[1]) * (photomB[0] + photomB[1])) != 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
00782         rawVis->visSqrd /= (photomA[0] + photomA[1])*(photomB[0] + photomB[1]) ;
00783     else
00784         rawVis->visSqrd = NOT_A_NUMBER;
00785 
00786     if ((photomA[0] * photomB[0]) != 0) /* Singularity check */ /* Added csabet 09-Jan-04 */
00787         rawVis->visSqrd1 /= (photomA[0]*photomB[0]) ;
00788     else
00789         rawVis->visSqrd1 = NOT_A_NUMBER;
00790 
00791     if ((photomA[1] * photomB[1]) != 0)  /* Singularity check */ /* Added csabet 09-Jan-04 */
00792         rawVis->visSqrd2 /= (photomA[1]*photomB[1]) ;
00793     else
00794         rawVis->visSqrd2 = NOT_A_NUMBER;
00795 
00796     if (((photomA[0] + photomA[1]) * (photomB[0] + photomB[1])) > 0)  /* Singularity check */ /* Added csabet 09-Jan-04 */
00797         rawVis->vis /= (float) sqrt((photomA[0] + photomA[1])*(photomB[0] + photomB[1])) ;
00798     else
00799         rawVis->vis = NOT_A_NUMBER;
00800 
00801     if ((photomA[0] * photomB[0]) > 0)  /* Singularity check */ /* Added csabet 09-Jan-04 */
00802         rawVis->vis1 /= (float) sqrt(photomA[0]*photomB[0])  ;
00803     else
00804         rawVis->vis1 = NOT_A_NUMBER;
00805 
00806     if ((photomA[1] * photomB[1]) > 0)  /* Singularity check */ /* Added csabet 09-Jan-04 */
00807         rawVis->vis2 /= (float) sqrt(photomA[1]*photomB[1]) ;
00808     else
00809         rawVis->vis2 = NOT_A_NUMBER;
00810 
00811     /* Added csabet 09-Jan-04 */
00812    cpl_msg_info(cpl_func,
00813         "Visibilities       combined    I1          I2 \n"
00814         "--------------------------------------------- \n"
00815         "Vis amplitude:     %5.4f      %5.4f     %5.4f \n"
00816         "Vis^2:             %5.4f      %5.4f     %5.4f \n"
00817         "sqrt(Vis^2):       %5.4f      %5.4f     %5.4f \n",
00818         rawVis->vis, rawVis->vis1, rawVis->vis2,
00819         rawVis->visSqrd, rawVis->visSqrd1, rawVis->visSqrd2,
00820         sqrtp(rawVis->visSqrd), sqrtp(rawVis->visSqrd1), sqrtp(rawVis->visSqrd2));
00821 
00822     fprintf (midiReportPtr,
00823         "Visibilities       combined    I1          I2 QCLOG \n"
00824         "--------------------------------------------- \n"
00825         "Vis amplitude:     %5.4f      %5.4f     %5.4f QCLOG \n"
00826         "Vis^2:             %5.4f      %5.4f     %5.4f QCLOG \n"
00827         "sqrt(Vis^2):       %5.4f      %5.4f     %5.4f QCLOG \n",
00828         rawVis->vis, rawVis->vis1, rawVis->vis2,
00829         rawVis->visSqrd, rawVis->visSqrd1, rawVis->visSqrd2,
00830         sqrtp(rawVis->visSqrd), sqrtp(rawVis->visSqrd1), sqrtp(rawVis->visSqrd2));
00831 
00832     if ((rawVis->vis == NOT_A_NUMBER) || (rawVis->vis1 == NOT_A_NUMBER) || (rawVis->vis2 == NOT_A_NUMBER) ||
00833         (rawVis->visSqrd == NOT_A_NUMBER) || (rawVis->visSqrd1 == NOT_A_NUMBER) || (rawVis->visSqrd2 == NOT_A_NUMBER) )
00834     {
00835         sprintf (midiMessage, "A value of  %.4f  is a reject result. QCLOG", (float)NOT_A_NUMBER);
00836         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
00837     }
00838     
00839     return;
00840 }
00841 /*****************************************************************************/
00842 
00843 
00844 /******************************************************************************
00845 *                European Southern Observatory
00846 *              VLTI MIDI Data Reduction Software 
00847 *
00848 * Module name:  computeBinnedUncalibVis
00849 * Input/Output: See function arguments to avoid duplication
00850 * Description:  This routine computes the uncalibrated visibilities at 5 spectral
00851 *                bands as follows:
00852 *
00853 *                1)  8.64 microns (Channels 120 -> 126) PRISM
00854 *                                 (Channels  38 ->  50) GRISM
00855 *                2)  9.00 microns (Channels 113 -> 121) PRISM
00856 *                                 (Channels  52 ->  68) GRISM
00857 *                3) 10.46 microns (Channels  88 ->  99) PRISM
00858 *                                 (Channels 116 -> 136) GRISM
00859 *                4) 11.79 microns (Channels  60 ->  72) PRISM
00860 *                                 (Channels 176 -> 200) GRISM
00861 *                5) 12.80 microns (Channels  36 ->  50) PRISM
00862 *                                 (Channels 217 -> 245) GRISM
00863 *
00864 * History:        
00865 * 21-Sep-06        (csabet) Created
00866 ******************************************************************************/
00867 void computeBinnedUncalibVis (
00868     ImageFormat        *format,        // In: General data format
00869     DispersedResult    *dispResult,    // In: Dispersed result structure
00870     int                *error)            // Ou: Error status
00871 {
00872 
00873     //    Local Declarations
00874     //    ------------------
00875     const char    routine[] = "computeBinnedUncalibVis";
00876     int            i, n;
00877 
00878     //    Algorithm
00879     //    ---------
00880    cpl_msg_info(cpl_func,"\nBinned Uncalibrated Visibilities for batch  %d \n", batchNumber);
00881    cpl_msg_info(cpl_func,"------------------------------------------ \n");
00882     fprintf (midiReportPtr, "\nBinned Uncalibrated Visibilities for batch  %d QCLOG \n", batchNumber);
00883     fprintf (midiReportPtr, "------------------------------------------ QCLOG \n");
00884 
00885     //    Reset parameters
00886     *error = 0;
00887     n = 0;
00888 
00889     dispResult->uncalVisBinned1 = 0.0;
00890     dispResult->uncalVisBinned2 = 0.0;
00891     dispResult->uncalVisBinned3 = 0.0;
00892     dispResult->uncalVisBinned4 = 0.0;
00893     dispResult->uncalVisBinned5 = 0.0;
00894 
00895     if (strcmp(format->grismId, "PRISM") == 0)
00896     {
00897         n = 0;
00898         for (i = 36; i < 51; i++)
00899         {
00900             if (badChannelList[i])
00901                 continue;
00902                 
00903             dispResult->uncalVisBinned5 += (dispResult->normVis2)[i];
00904             n++;
00905         }
00906         dispResult->uncalVisBinned5 /= n;
00907         n = 0;
00908         for (i = 60; i < 73; i++)
00909         {
00910             if (badChannelList[i])
00911                 continue;
00912                 
00913             dispResult->uncalVisBinned4 += (dispResult->normVis2)[i];
00914             n++;
00915         }
00916         dispResult->uncalVisBinned4 /= n;
00917         n = 0;
00918         for (i = 88; i < 99; i++)
00919         {
00920             if (badChannelList[i])
00921                 continue;
00922                 
00923             dispResult->uncalVisBinned3 += (dispResult->normVis2)[i];
00924             n++;
00925         }
00926         dispResult->uncalVisBinned3 /= n;
00927         n = 0;
00928         for (i = 113; i < 122; i++)
00929         {
00930             if (badChannelList[i])
00931                 continue;
00932                 
00933             dispResult->uncalVisBinned2 += (dispResult->normVis2)[i];
00934             n++;
00935         }
00936         dispResult->uncalVisBinned2 /= n;
00937         n = 0;
00938         for (i = 120; i < 127; i++)
00939         {
00940             if (badChannelList[i])
00941                 continue;
00942                 
00943             dispResult->uncalVisBinned1 += (dispResult->normVis2)[i];
00944             n++;
00945         }
00946         dispResult->uncalVisBinned1 /= n;
00947     }
00948     else if (strcmp(format->grismId, "GRISM") == 0)
00949     {
00950         n = 0;
00951         for (i = 38; i < 51; i++)
00952         {
00953             if (badChannelList[i])
00954                 continue;
00955                 
00956             dispResult->uncalVisBinned1 += (dispResult->normVis2)[i];
00957             n++;
00958         }
00959         dispResult->uncalVisBinned1 /= n;
00960         n = 0;
00961         for (i = 52; i < 69; i++)
00962         {
00963             if (badChannelList[i])
00964                 continue;
00965                 
00966             dispResult->uncalVisBinned2 += (dispResult->normVis2)[i];
00967             n++;
00968         }
00969         dispResult->uncalVisBinned2 /= n;
00970         n = 0;
00971         for (i = 116; i < 137; i++)
00972         {
00973             if (badChannelList[i])
00974                 continue;
00975                 
00976             dispResult->uncalVisBinned3 += (dispResult->normVis2)[i];
00977             n++;
00978         }
00979         dispResult->uncalVisBinned3 /= n;
00980         n = 0;
00981         for (i = 176; i < 201; i++)
00982         {
00983             if (badChannelList[i])
00984                 continue;
00985                 
00986             dispResult->uncalVisBinned4 += (dispResult->normVis2)[i];
00987             n++;
00988         }
00989         dispResult->uncalVisBinned4 /= n;
00990         n = 0;
00991         for (i = 217; i < 246; i++)
00992         {
00993             if (badChannelList[i])
00994                 continue;
00995                 
00996             dispResult->uncalVisBinned5 += (dispResult->normVis2)[i];
00997             n++;
00998         }
00999         dispResult->uncalVisBinned5 /= n;
01000     }
01001     else
01002     {
01003         sprintf (midiMessage, "Unknown GRISM ID ... %s", format->grismId);
01004         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, midiMessage);
01005         *error = 1;
01006         return;
01007     }
01008 
01009     //    Report
01010    cpl_msg_info(cpl_func,"Grism ID: %s \n", format->grismId);
01011     fprintf (midiReportPtr, "Grism ID: %s QCLOG \n", format->grismId);
01012     if (strcmp(format->grismId, "PRISM") == 0)
01013     {
01014        cpl_msg_info(cpl_func," 8.64 micron (Channel 120 -> 126) = %0.4f \n", dispResult->uncalVisBinned1);
01015        cpl_msg_info(cpl_func," 9.00 micron (Channel 113 -> 121) = %0.4f \n", dispResult->uncalVisBinned2);
01016        cpl_msg_info(cpl_func,"10.46 micron (Channel  88 ->  98) = %0.4f \n", dispResult->uncalVisBinned3);
01017        cpl_msg_info(cpl_func,"11.79 micron (Channel  60 ->  72) = %0.4f \n", dispResult->uncalVisBinned4);
01018        cpl_msg_info(cpl_func,"12.80 micron (Channel  36 ->  50) = %0.4f \n", dispResult->uncalVisBinned5);
01019 
01020         fprintf (midiReportPtr, " 8.64 micron (Channel 120 -> 126) = %0.4f QCLOG \n", dispResult->uncalVisBinned1);
01021         fprintf (midiReportPtr, " 9.00 micron (Channel 113 -> 121) = %0.4f QCLOG \n", dispResult->uncalVisBinned2);
01022         fprintf (midiReportPtr, "10.46 micron (Channel  88 ->  98) = %0.4f QCLOG \n", dispResult->uncalVisBinned3);
01023         fprintf (midiReportPtr, "11.79 micron (Channel  60 ->  72) = %0.4f QCLOG \n", dispResult->uncalVisBinned4);
01024         fprintf (midiReportPtr, "12.80 micron (Channel  36 ->  50) = %0.4f QCLOG \n", dispResult->uncalVisBinned5);
01025     }
01026     else
01027     {
01028        cpl_msg_info(cpl_func," 8.64 micron (Channel  38 ->  50) = %0.4f \n", dispResult->uncalVisBinned1);
01029        cpl_msg_info(cpl_func," 9.00 micron (Channel  52 ->  68) = %0.4f \n", dispResult->uncalVisBinned2);
01030        cpl_msg_info(cpl_func,"10.46 micron (Channel 116 -> 136) = %0.4f \n", dispResult->uncalVisBinned3);
01031        cpl_msg_info(cpl_func,"11.79 micron (Channel 176 -> 200) = %0.4f \n", dispResult->uncalVisBinned4);
01032        cpl_msg_info(cpl_func,"12.80 micron (Channel 217 -> 245) = %0.4f \n", dispResult->uncalVisBinned5);
01033 
01034         fprintf (midiReportPtr, " 8.64 micron (Channel  38 ->  50) = %0.4f QCLOG \n", dispResult->uncalVisBinned1);
01035         fprintf (midiReportPtr, " 9.00 micron (Channel  52 ->  68) = %0.4f QCLOG \n", dispResult->uncalVisBinned2);
01036         fprintf (midiReportPtr, "10.46 micron (Channel 116 -> 136) = %0.4f QCLOG \n", dispResult->uncalVisBinned3);
01037         fprintf (midiReportPtr, "11.79 micron (Channel 176 -> 200) = %0.4f QCLOG \n", dispResult->uncalVisBinned4);
01038         fprintf (midiReportPtr, "12.80 micron (Channel 217 -> 245) = %0.4f QCLOG \n", dispResult->uncalVisBinned5);
01039     }
01040     
01041     return;
01042 }
01043 /*****************************************************************************/
01044 

Generated on 15 Mar 2012 for MIDI Pipeline Reference Manual by  doxygen 1.6.1