diagnostics.c

00001 /******************************************************************************
00002 *******************************************************************************
00003 *               European Southern Observatory
00004 *               VLTI Data Reduction Software
00005 *
00006 * File name:    diagnostics.c
00007 * Description:  Contains the routines for diagnostic purposes
00008 *
00009 *
00010 * History:
00011 * 08-Jan-04     (csabet) Created
00012 *******************************************************************************
00013 ******************************************************************************/
00014 
00015 /******************************************************************************
00016 *   Compiler directives
00017 ******************************************************************************/
00018 
00019 /******************************************************************************
00020 *   Include files
00021 ******************************************************************************/
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <unistd.h>
00025 #include <stdio.h>
00026 #include <cpl.h>
00027 #include <math.h>
00028 #include <time.h>
00029 #include <stdlib.h>
00030 #include "midiGlobal.h"
00031 #include "midiLib.h"
00032 #include "errorHandling.h"
00033 #include "diagnostics.h"
00034 #include "qfits.h"
00035 
00036 /******************************************************************************
00037 *   Global Variables
00038 ******************************************************************************/
00039 
00040 /******************************************************************************
00041 *   Prototypes
00042 ******************************************************************************/
00043 
00044 /*============================ C O D E    A R E A ===========================*/
00045 
00046 
00047 /******************************************************************************
00048 *               European Southern Observatory
00049 *             VLTI MIDI Data Reduction Software
00050 *
00051 * Module name:  midiCreatePlotFileDouble3D
00052 * Input/Output: See function arguments to avoid duplication
00053 * Description:  Creates a 3D plot file
00054 *
00055 * History:
00056 * 08-Apr-05     (csabet)
00057 ******************************************************************************/
00058 void midiCreatePlotFileDouble3D (
00059     const char    *plotFileName,
00060     const char    *title,
00061     const char    *xLabel,
00062     const char    *yLabel,
00063     const char    *zLabel,
00064     int        deletePlot,
00065     double    *image,
00066     int        sizeX,
00067     int        sizeY,
00068     const char    *style,
00069     const char    *lineType)
00070 {
00071 
00072     //    Local Declarations
00073     //    ------------------
00074     const char  routine[] = "midiCreatePlotFileDouble3D";
00075     int         i, j, frame, zero = 0;
00076     FILE        *dataFilePtr=NULL, *cmdFilePtr=NULL;
00077     char        *dataFilePath, *cmdFileName, *argument;
00078 
00079     //    Algorithm
00080     //    ---------
00081     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00082     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00083 
00084     //    Allocate memory
00085     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00086     cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00087     argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00088 
00089     //    Create the plot file
00090     sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
00091     dataFilePtr = fopen (dataFilePath, "w");
00092 
00093     for (i = 0; i < sizeY; i++)
00094     {
00095         frame = i * sizeX;
00096         for (j = 0; j < sizeX; j++)
00097         {
00098             if (isnan (image[frame + j])) fprintf (dataFilePtr, "%d \n", zero);
00099             else fprintf (dataFilePtr, "%8.4f ", image[frame + j]);
00100         }
00101 
00102         fprintf (dataFilePtr, "\n");
00103     }
00104     fclose (dataFilePtr);
00105 
00106     //    Create the command file
00107     if (plotFile > 1)
00108     {
00109         sprintf (cmdFileName, "plotCmdFile.log");
00110         cmdFilePtr = fopen (cmdFileName, "w");
00111         fprintf (cmdFilePtr, "set title \'%s\' \n", title);
00112         fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
00113         fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
00114         fprintf (cmdFilePtr, "set zlabel \'%s\' \n", zLabel);
00115         fprintf (cmdFilePtr, "set xrange [0:%d] \n", sizeX);
00116         fprintf (cmdFilePtr, "set yrange [0:%d] \n", sizeY);
00117         fprintf (cmdFilePtr, "set ticslevel 0 \n");
00118         fprintf (cmdFilePtr, "splot \'%s\' matrix with %s %s \n", dataFilePath, style, lineType);
00119             
00120         if (plotDuration == -1)
00121         {
00122            cpl_msg_info(cpl_func,"\n");
00123             fprintf (cmdFilePtr, "pause %d \"          ***** Hit Return to continue *****\" \n", plotDuration);
00124         }
00125         else
00126             fprintf (cmdFilePtr, "pause %d \n", plotDuration);
00127         
00128         fclose (cmdFilePtr);
00129 
00130         //    Run the command file
00131         sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 900x900+0+0 %s", cmdFileName);
00132         system (argument);
00133 
00134         //    Remove temporary files
00135         remove (cmdFileName);
00136     }
00137 
00138     //    Delete plot file if display only
00139     if (deletePlot || plotFile == 3) remove (dataFilePath);
00140 
00141     //    Release memory
00142     free (dataFilePath);
00143     free (cmdFileName);
00144     free (argument);
00145 
00146     return;
00147 }
00148 /*****************************************************************************/
00149 
00150 
00151 
00152 
00153 /******************************************************************************
00154 *               European Southern Observatory
00155 *             VLTI MIDI Data Reduction Software
00156 *
00157 * Module name:  midiCreatePlotFile3D
00158 * Input/Output: See function arguments to avoid duplication
00159 * Description:  Creates a 3D plot file
00160 *
00161 * History:
00162 * 08-Apr-05     (csabet)
00163 ******************************************************************************/
00164 void midiCreatePlotFile3D (
00165     const char    *plotFileName,
00166     const char    *title,
00167     const char    *xLabel,
00168     const char    *yLabel,
00169     const char    *zLabel,
00170     int        deletePlot,
00171     float    *image,
00172     int        sizeX,
00173     int        sizeY,
00174     const char    *style,
00175     const char    *lineType)
00176 {
00177 
00178     //    Local Declarations
00179     //    ------------------
00180     const char  routine[] = "midiCreatePlotFile3D";
00181     int         i, j, frame, zero = 0;
00182     FILE        *dataFilePtr=NULL, *cmdFilePtr=NULL;
00183     char        *dataFilePath, *cmdFileName, *argument;
00184 
00185     //    Algorithm
00186     //    ---------
00187     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00188     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00189 
00190     //    Allocate memory
00191     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00192     cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00193     argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00194 
00195     //    Create the plot file
00196     sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
00197     dataFilePtr = fopen (dataFilePath, "w");
00198 
00199     for (i = 0; i < sizeY; i++)
00200     {
00201         frame = i * sizeX;
00202         for (j = 0; j < sizeX; j++)
00203         {
00204             if (isnan (image[frame + j])) fprintf (dataFilePtr, "%d \n", zero);
00205             else fprintf (dataFilePtr, "%8.4f ", image[frame + j]);
00206         }
00207 
00208         fprintf (dataFilePtr, "\n");
00209     }
00210     fclose (dataFilePtr);
00211 
00212     //    Create the command file
00213     if (plotFile > 1)
00214     {
00215         sprintf (cmdFileName, "plotCmdFile.log");
00216         cmdFilePtr = fopen (cmdFileName, "w");
00217         fprintf (cmdFilePtr, "set title \'%s\' \n", title);
00218         fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
00219         fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
00220         fprintf (cmdFilePtr, "set zlabel \'%s\' \n", zLabel);
00221         fprintf (cmdFilePtr, "set xrange [0:%d] \n", sizeX);
00222         fprintf (cmdFilePtr, "set yrange [0:%d] \n", sizeY);
00223         fprintf (cmdFilePtr, "set ticslevel 0 \n");
00224         fprintf (cmdFilePtr, "splot \'%s\' matrix with %s %s \n", dataFilePath, style, lineType);
00225             
00226         if (plotDuration == -1)
00227         {
00228            cpl_msg_info(cpl_func,"\n");
00229             fprintf (cmdFilePtr, "pause %d \"          ***** Hit Return to continue *****\" \n", plotDuration);
00230         }
00231         else
00232             fprintf (cmdFilePtr, "pause %d \n", plotDuration);
00233         
00234         fclose (cmdFilePtr);
00235 
00236         //    Run the command file
00237         sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 900x900+0+0 %s", cmdFileName);
00238         system (argument);
00239 
00240         //    Remove temporary files
00241         remove (cmdFileName);
00242     }
00243 
00244     //    Delete plot file if display only
00245     if (deletePlot || plotFile == 3) remove (dataFilePath);
00246 
00247     //    Release memory
00248     free (dataFilePath);
00249     free (cmdFileName);
00250     free (argument);
00251 
00252     return;
00253 }
00254 /*****************************************************************************/
00255 
00256 
00257 
00258 /******************************************************************************
00259 *               European Southern Observatory
00260 *             VLTI MIDI Data Reduction Software
00261 *
00262 * Module name:  midiCreatePlotFileDouble2D
00263 * Input/Output: See function arguments to avoid duplication
00264 * Description:  Creates a plot file
00265 *
00266 * History:
00267 * 14-Feb-05     (csabet)
00268 ******************************************************************************/
00269 void midiCreatePlotFileDouble2D (
00270     const char    *plotFileName,
00271     const char    *title,
00272     const char    *xLabel,
00273     const char    *yLabel,
00274     int        deletePlot,
00275     double    *array,
00276     int        begin,
00277     int        end,
00278     int        interval)
00279 {
00280 
00281     //    Local Declarations
00282     //    ------------------
00283     const char  routine[] = "midiCreatePlotFileDouble2D";
00284     int         i, zero = 0;
00285     FILE        *dataFilePtr=NULL, *cmdFilePtr=NULL;
00286     char        *dataFilePath, *cmdFileName, *argument;
00287     
00288     //    Algorithm
00289     //    ---------
00290     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00291     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00292 
00293     //    Allocate memory
00294     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00295     cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00296     argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00297 
00298     //    Create the plot file
00299     sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
00300     dataFilePtr = fopen (dataFilePath, "w");
00301     for (i = begin; i < end; i += interval)
00302     {
00303         if (isnan (array[i])) fprintf (dataFilePtr, "%d \n", zero);
00304         else fprintf (dataFilePtr, "%f \n", array[i]);
00305     }
00306     fclose (dataFilePtr);
00307 
00308     //    Display plot file
00309     if (plotFile > 1)
00310     {
00311         sprintf (cmdFileName, "plotCmdFile.grb");
00312         cmdFilePtr = fopen (cmdFileName, "w");
00313         fprintf (cmdFilePtr, "set title \'%s\' \n", title);
00314         fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
00315         fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
00316         fprintf (cmdFilePtr, "plot \'%s\' with lines 1\n", dataFilePath);
00317         if (plotDuration == -1)
00318         {
00319            cpl_msg_info(cpl_func,"\n");
00320             fprintf (cmdFilePtr, "pause %d \"          ***** Hit Return to continue *****\" \n", plotDuration);
00321         }
00322         else
00323             fprintf (cmdFilePtr, "pause %d \n", plotDuration);
00324         
00325         fclose (cmdFilePtr);
00326 
00327 
00328         //    Run the command file
00329         sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
00330         system (argument);
00331 
00332         //    Remove temporary files
00333         remove (cmdFileName);
00334     }
00335 
00336     //    Delete plot file if display only
00337     if (deletePlot || plotFile == 3) remove (dataFilePath);
00338 
00339     //    Release memory
00340     free (dataFilePath);
00341     free (cmdFileName);
00342     free (argument);
00343 
00344     return;
00345 }
00346 /*****************************************************************************/
00347 
00348 
00349 /******************************************************************************
00350 *               European Southern Observatory
00351 *             VLTI MIDI Data Reduction Software
00352 *
00353 * Module name:  midiCreateReplotFileDouble2D2P
00354 * Input/Output: See function arguments to avoid duplication
00355 * Description:  Creates a plot file for a 2 column table
00356 *
00357 * History:
00358 * 14-Feb-05     (csabet)
00359 ******************************************************************************/
00360 void midiCreateReplotFileDouble2D2P (
00361     char    *plotFileName,
00362     char    *title,
00363     char    *xLabel,
00364     char    *yLabel,
00365     int        deletePlot,
00366     double    *arrayX,    // In: Array X
00367     double    *arrayY,
00368     int        begin,        // In: Start of the arrayX
00369     int        end,        // In: End of arrayX
00370     int        interval,    // In: Interval for the arrayX
00371     char    *lineType)
00372 {
00373 
00374     //    Local Declarations
00375     //    ------------------
00376     const char  routine[] = "midiCreateReplotFileDouble2D2P";
00377     int         i, zero = 0;
00378     FILE        *dataFilePtr=NULL, *cmdFilePtr=NULL;
00379     char        *dataFilePath, *cmdFileName, *argument;
00380     
00381     //    Algorithm
00382     //    ---------
00383     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00384     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00385 
00386     //    Allocate memory
00387     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00388     cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00389     argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00390 
00391     //    Create the plot file
00392     sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
00393     dataFilePtr = fopen (dataFilePath, "w");
00394     for (i = begin; i < end; i += interval)
00395     {
00396         if (isnan (arrayX[i]) || isnan (arrayY[i])) fprintf (dataFilePtr, "%d %d \n", zero, zero);
00397         else fprintf (dataFilePtr, "%f %f \n", arrayX[i], arrayY[i]);
00398     }
00399     fclose (dataFilePtr);
00400 
00401     //    Display plot file
00402     if (plotFile > 1)
00403     {
00404         sprintf (cmdFileName, "plotCmdFile.grb");
00405         cmdFilePtr = fopen (cmdFileName, "w");
00406         fprintf (cmdFilePtr, "set title \'%s\' \n", title);
00407         fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
00408         fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
00409         fprintf (cmdFilePtr, "replot \'%s\' with %s\n", dataFilePath, lineType);
00410         if (plotDuration == -1)
00411         {
00412            cpl_msg_info(cpl_func,"\n");
00413             fprintf (cmdFilePtr, "pause %d \"          ***** Hit Return to continue *****\" \n", plotDuration);
00414         }
00415         else
00416             fprintf (cmdFilePtr, "pause %d \n", plotDuration);
00417         
00418         fclose (cmdFilePtr);
00419 
00420 
00421         //    Run the command file
00422         sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
00423         system (argument);
00424 
00425         //    Remove temporary files
00426         remove (cmdFileName);
00427     }
00428 
00429     //    Delete plot file if display only
00430     if (deletePlot || plotFile == 3) remove (dataFilePath);
00431 
00432     //    Release memory
00433     free (dataFilePath);
00434     free (cmdFileName);
00435     free (argument);
00436 
00437     return;
00438 }
00439 /*****************************************************************************/
00440 
00441 
00442 /******************************************************************************
00443 *               European Southern Observatory
00444 *             VLTI MIDI Data Reduction Software
00445 *
00446 * Module name:  midiCreatePlotFileDouble2D2P
00447 * Input/Output: See function arguments to avoid duplication
00448 * Description:  Creates a plot file for a 2 column table
00449 *
00450 * History:
00451 * 14-Feb-05     (csabet)
00452 ******************************************************************************/
00453 void midiCreatePlotFileDouble2D2P (
00454     const char    *plotFileName,
00455     const char    *title,
00456     const char    *xLabel,
00457     const char    *yLabel,
00458     int        deletePlot,
00459     double    *arrayX,    // In: Array X
00460     double    *arrayY,
00461     int        begin,        // In: Start of the arrayX
00462     int        end,        // In: End of arrayX
00463     int        interval,    // In: Interval for the arrayX
00464     const char    *lineType)
00465 {
00466 
00467     //    Local Declarations
00468     //    ------------------
00469     const char  routine[] = "midiCreatePlotFileDouble2D2P";
00470     int         i, zero = 0;
00471     FILE        *dataFilePtr=NULL, *cmdFilePtr=NULL;
00472     char        *dataFilePath, *cmdFileName, *argument;
00473     
00474     //    Algorithm
00475     //    ---------
00476     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00477     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00478 
00479     //    Allocate memory
00480     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00481     cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00482     argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00483 
00484     //    Create the plot file
00485     sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
00486     dataFilePtr = fopen (dataFilePath, "w");
00487     for (i = begin; i < end; i += interval)
00488     {
00489         if (isnan (arrayX[i]) || isnan (arrayY[i])) fprintf (dataFilePtr, "%d %d \n", zero, zero);
00490         else fprintf (dataFilePtr, "%f %f \n", arrayX[i], arrayY[i]);
00491     }
00492     fclose (dataFilePtr);
00493 
00494     //    Display plot file
00495     if (plotFile > 1)
00496     {
00497         sprintf (cmdFileName, "plotCmdFile.grb");
00498         cmdFilePtr = fopen (cmdFileName, "w");
00499         fprintf (cmdFilePtr, "set title \'%s\' \n", title);
00500         fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
00501         fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
00502         fprintf (cmdFilePtr, "plot \'%s\' with %s\n", dataFilePath, lineType);
00503         if (plotDuration == -1)
00504         {
00505            cpl_msg_info(cpl_func,"\n");
00506             fprintf (cmdFilePtr, "pause %d \"          ***** Hit Return to continue *****\" \n", plotDuration);
00507         }
00508         else
00509             fprintf (cmdFilePtr, "pause %d \n", plotDuration);
00510         
00511         fclose (cmdFilePtr);
00512 
00513 
00514         //    Run the command file
00515         sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
00516         system (argument);
00517 
00518         //    Remove temporary files
00519         remove (cmdFileName);
00520     }
00521 
00522     //    Delete plot file if display only
00523     if (deletePlot || plotFile == 3) remove (dataFilePath);
00524 
00525     //    Release memory
00526     free (dataFilePath);
00527     free (cmdFileName);
00528     free (argument);
00529 
00530     return;
00531 }
00532 /*****************************************************************************/
00533 
00534 
00535 /******************************************************************************
00536 *               European Southern Observatory
00537 *             VLTI MIDI Data Reduction Software
00538 *
00539 * Module name:  midiCreatePlotFile2D2P
00540 * Input/Output: See function arguments to avoid duplication
00541 * Description:  Creates a plot file for a 2 column table
00542 *
00543 * History:
00544 * 14-Feb-05     (csabet)
00545 ******************************************************************************/
00546 void midiCreatePlotFile2D2P (
00547     const char    *plotFileName,
00548     const char    *title,
00549     const char    *xLabel,
00550     const char    *yLabel,
00551     int        deletePlot,
00552     float    *arrayX,    // In: Array X
00553     float    *arrayY,
00554     int        begin,        // In: Start of the arrayX
00555     int        end,        // In: End of arrayX
00556     int        interval)    // In: Interval for the arrayX
00557 {
00558 
00559     //    Local Declarations
00560     //    ------------------
00561     const char  routine[] = "midiCreatePlotFile2D2P";
00562     int         i, zero = 0;
00563     FILE        *dataFilePtr=NULL, *cmdFilePtr=NULL;
00564     char        *dataFilePath, *cmdFileName, *argument;
00565     
00566     //    Algorithm
00567     //    ---------
00568     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00569     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00570 
00571     //    Allocate memory
00572     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00573     cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00574     argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00575 
00576     //    Create the plot file
00577     sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
00578     dataFilePtr = fopen (dataFilePath, "w");
00579     for (i = begin; i < end; i += interval)
00580     {
00581         if (isnan (arrayX[i]) || isnan (arrayY[i])) fprintf (dataFilePtr, "%d %d \n", zero, zero);
00582         else fprintf (dataFilePtr, "%f %f \n", arrayX[i], arrayY[i]);
00583     }
00584     fclose (dataFilePtr);
00585 
00586     //    Display plot file
00587     if (plotFile > 1)
00588     {
00589         sprintf (cmdFileName, "plotCmdFile.grb");
00590         cmdFilePtr = fopen (cmdFileName, "w");
00591         fprintf (cmdFilePtr, "set title \'%s\' \n", title);
00592         fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
00593         fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
00594         fprintf (cmdFilePtr, "plot \'%s\' with lines 1\n", dataFilePath);
00595         if (plotDuration == -1)
00596         {
00597            cpl_msg_info(cpl_func,"\n");
00598             fprintf (cmdFilePtr, "pause %d \"          ***** Hit Return to continue *****\" \n", plotDuration);
00599         }
00600         else
00601             fprintf (cmdFilePtr, "pause %d \n", plotDuration);
00602         
00603         fclose (cmdFilePtr);
00604 
00605 
00606         //    Run the command file
00607         sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
00608         system (argument);
00609 
00610         //    Remove temporary files
00611         remove (cmdFileName);
00612     }
00613 
00614     //    Delete plot file if display only
00615     if (deletePlot || plotFile == 3) remove (dataFilePath);
00616 
00617     //    Release memory
00618     free (dataFilePath);
00619     free (cmdFileName);
00620     free (argument);
00621 
00622     return;
00623 }
00624 /*****************************************************************************/
00625 
00626 
00627 /******************************************************************************
00628 *               European Southern Observatory
00629 *             VLTI MIDI Data Reduction Software
00630 *
00631 * Module name:  midiCreatePlotFile2D
00632 * Input/Output: See function arguments to avoid duplication
00633 * Description:  Creates a plot file
00634 *
00635 * History:
00636 * 14-Feb-05     (csabet)
00637 ******************************************************************************/
00638 void midiCreatePlotFile2D (
00639     const char    *plotFileName,
00640     const char    *title,
00641     const char    *xLabel,
00642     const char    *yLabel,
00643     int        deletePlot,
00644     float    *array,
00645     int        begin,
00646     int        end,
00647     int        interval,
00648     int        override)
00649 {
00650 
00651     //    Local Declarations
00652     //    ------------------
00653     const char  routine[] = "midiCreatePlotFile2D";
00654     int         i, zero = 0, duration;
00655     FILE        *dataFilePtr=NULL, *cmdFilePtr=NULL;
00656     char        *dataFilePath, *cmdFileName, *argument;
00657     
00658     //    Algorithm
00659     //    ---------
00660     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00661     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
00662 
00663     //    Allocate memory
00664     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00665     cmdFileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00666     argument = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00667 
00668     //    Reset
00669     if (override) 
00670         duration = override;
00671     else 
00672         duration = plotDuration;
00673     
00674     //    Create the plot file
00675     sprintf (dataFilePath, "%s%s.%s.plt", outFileDir, outRootName, plotFileName);
00676     dataFilePtr = fopen (dataFilePath, "w");
00677     for (i = begin; i < end; i += interval)
00678     {
00679         if (isnan (array[i])) fprintf (dataFilePtr, "%d \n", zero);
00680         else fprintf (dataFilePtr, "%f \n", array[i]);
00681     }
00682     fclose (dataFilePtr);
00683 
00684     //    Display plot file
00685     if (plotFile > 1)
00686     {
00687         sprintf (cmdFileName, "plotCmdFile.grb");
00688         cmdFilePtr = fopen (cmdFileName, "w");
00689         fprintf (cmdFilePtr, "set title \'%s\' \n", title);
00690         fprintf (cmdFilePtr, "set xlabel \'%s\' \n", xLabel);
00691         fprintf (cmdFilePtr, "set ylabel \'%s\' \n", yLabel);
00692         fprintf (cmdFilePtr, "plot \'%s\' with lines 1\n", dataFilePath);
00693         if (duration == -1)
00694         {
00695            cpl_msg_info(cpl_func,"\n");
00696             fprintf (cmdFilePtr, "pause %d \"          ***** Hit Return to continue *****\" \n", duration);
00697         }
00698         else
00699             fprintf (cmdFilePtr, "pause %d \n", duration);
00700         
00701         fclose (cmdFilePtr);
00702 
00703 
00704         //    Run the command file
00705         sprintf (argument, "gnuplot -title \"MIDI DRS\" -geometry 600x600+0+0 %s", cmdFileName);
00706         system (argument);
00707 
00708         //    Remove temporary files
00709         remove (cmdFileName);
00710     }
00711 
00712     //    Delete plot file if display only
00713     if (deletePlot || plotFile == 3) remove (dataFilePath);
00714 
00715     //    Release memory
00716     free (dataFilePath);
00717     free (cmdFileName);
00718     free (argument);
00719 
00720     return;
00721 }
00722 /*****************************************************************************/
00723 
00724 
00725 
00726 /******************************************************************************
00727 *               European Southern Observatory
00728 *             VLTI MIDI Data Reduction Software
00729 *
00730 * Module name:  getVersions
00731 * Input/Output: See function arguments to avoid duplication
00732 * Description:  Displays versions of integrated software
00733 *
00734 * History:
00735 * 14-Feb-05     (csabet)
00736 ******************************************************************************/
00737 void getVersions (void)
00738 {
00739 
00740     //    Local Declarations
00741     //    ------------------
00742 
00743     //    Algorithm
00744     //    ---------
00745    cpl_msg_info(cpl_func,"\nIntegrated Versions \n");
00746    cpl_msg_info(cpl_func,"------------------- \n");
00747    cpl_msg_info(cpl_func,"MIDI DRS Pipeline   = %s \n", MIDI_PIPE_VERSION);
00748    cpl_msg_info(cpl_func,"Iau Exchange        = %s \n", IAUEXCHANGE_VERSION);
00749    cpl_msg_info(cpl_func,"QC Dictionary       = %s \n", MIDI_QC_DIC_VERSION);
00750    cpl_msg_info(cpl_func,"\n");
00751 
00752     return;
00753 }
00754 /*****************************************************************************/
00755 
00756 
00757 /******************************************************************************
00758 *               European Southern Observatory
00759 *            VLTI MIDI Data Reduction Software
00760 *
00761 * Module name:  prepareWaterfallDisplay
00762 * Input/Output: See function arguments to avoid duplication
00763 * Description:  This routine creates the waterfall display.
00764 *
00765 * History:
00766 * 14-Aug-03     (csabet) Created. Derived from pballest July 2003
00767 ******************************************************************************/
00768 void prepareWaterfallDisplay (
00769     MidiFiles        *fileNames,        // In: Pointer to the file structure
00770     ImageFormat        *imageSize,        // In: Image format
00771     CompressedData    *compressed)    // In: Compressed data
00772 {
00773 
00774     //    Local Declarations
00775     //    ------------------
00776     const char      routine[] = "prepareWaterfallDisplay";
00777     qfits_header    *pHeaderOut;
00778     FILE            *waterfallPtr;
00779     qfitsdumper     qdFringe;
00780     char            *sFramesPerScan, *sNumOfScans, *classification, *stringTemp, 
00781             *currentTime, *sNumOfChannels, *sNumOfFreqBins;
00782     FILE            *inFitsBatchPtr = NULL;
00783     struct stat     buf;
00784     char            *fileName, *title;
00785     int                f, fs, s, numOfScans, framesPerScan, numOfFrames, scanMax, frameStart, 
00786                     numOfFreqBins, frameEnd;
00787     double            *cleanArray, dcLevel, accum, fluxMax;
00788     time_t          now;
00789     struct tm       *newTime;
00790 
00791     //    Algorithm
00792     //    ---------
00793     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
00794     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
00795 
00796    cpl_msg_info(cpl_func,"\nCreating Waterfall Display Data for batch  %d \n", batchNumber);
00797    cpl_msg_info(cpl_func,"----------------------------------------- \n");
00798     fprintf (midiReportPtr, "\nCreating Waterfall Display Data for batch  %d \n", batchNumber);
00799     fprintf (midiReportPtr, "----------------------------------------- \n");
00800 
00801     //    Allocate memory
00802     stringTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00803     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00804     sNumOfScans = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00805     sFramesPerScan = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00806     sNumOfFreqBins = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00807     sNumOfChannels = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00808     cleanArray = (double *) calloc (imageSize->numOfFrames, sizeof (double));
00809     currentTime = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
00810 
00811     //    Get current time/date
00812     now = time(NULL);
00813     newTime = gmtime (&now);
00814     strftime (currentTime, MIN_STRING_LENGTH, "%a %d %b %Y at %H:%M:%S", newTime);
00815 
00816     //    Create a clean iFringe
00817     numOfFrames = 0;
00818     for (f = 0; f < imageSize->numOfFrames; f++)
00819     {
00820         if (compressed->tarType[f] == 'T')
00821         {
00822             cleanArray[numOfFrames] = compressed->iFringe[f];
00823             numOfFrames++;
00824         }
00825     }
00826 
00827     if (strcmp (imageSize->beamCombiner, "SCI_PHOT") == 0)
00828     {
00829         numOfScans = countTransitions ('T', imageSize->numOfFrames, compressed->tarType) + 1;
00830         framesPerScan = numOfFrames / numOfScans;
00831     }
00832     else
00833     {
00834         numOfScans = imageSize->numOfScans;
00835         framesPerScan = imageSize->framesPerScan;
00836     }
00837 
00838     //    Remove DC level
00839     for (s = 0; s < numOfScans; s++)
00840     {
00841         accum = 0;
00842         for (fs = 0; fs < framesPerScan; fs++)
00843         {
00844             f = fs + s * framesPerScan;
00845             accum += cleanArray[f];
00846         }
00847         dcLevel = accum/framesPerScan;
00848         for (fs = 0; fs < framesPerScan; fs++)
00849         {
00850             f = fs + s * framesPerScan;
00851             cleanArray[f] -= dcLevel;
00852         }
00853     }
00854 
00855     //    Find the scan at which the fringe is maximum
00856     fluxMax = 0.0;
00857     scanMax = 0;
00858     for (f = 0; f < numOfFrames; f++)
00859     {
00860         if (fabs(cleanArray[f]) > fluxMax)
00861         {
00862             fluxMax = fabs(cleanArray[f]);
00863             scanMax = f;
00864         }
00865     }
00866     scanMax = scanMax / framesPerScan + 1;
00867     
00868     //    Write all NAXIS values as character strings
00869     numOfFreqBins = POST_FFT_SIZE/2;
00870     sprintf (sNumOfScans, "%d", numOfScans);
00871     sprintf (sFramesPerScan, "%d", framesPerScan);
00872     sprintf (sNumOfFreqBins, "%d", numOfFreqBins);
00873     sprintf (sNumOfChannels, "%d", imageSize->iXWidth);
00874 
00875     //    Open the list of files
00876     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
00877     {
00878         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
00879        cpl_msg_info(cpl_func,"\nCannot Create Waterfall Display Data for batch  %d \n", batchNumber);
00880         fprintf (midiReportPtr, "\nCannot Create Waterfall Display Data for batch  %d \n", batchNumber);
00881         free (sNumOfScans);
00882         free (sFramesPerScan);
00883         free (classification);
00884         free (stringTemp);
00885         free (cleanArray);
00886         free (sNumOfFreqBins);
00887         free (sNumOfChannels);
00888         return;
00889     }
00890         
00891 
00892     //    Read the name of the first file in the list and get it's full path name
00893     fgets (stringTemp, MAX_STRING_LENGTH, inFitsBatchPtr);
00894     sprintf (classification, "%s", "");
00895     sscanf (stringTemp, "%s%s", fileNames->inFitsName, classification);
00896 
00897     //    Add primary Header
00898     if (diagnostic)cpl_msg_info(cpl_func,"Extracting primary header from input FITS file   %s \n", fileNames->inFitsName);
00899     if (diagnostic) fprintf(midiReportPtr, "Extracting primary header from input FITS file   %s \n", fileNames->inFitsName);
00900     pHeaderOut = qfits_header_read (fileNames->inFitsName);
00901     if (pHeaderOut == NULL)
00902     {
00903         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot extract primary header from input FITS file");
00904        cpl_msg_info(cpl_func,"\nCannot Create Waterfall Display Data for batch  %d \n", batchNumber);
00905         fprintf (midiReportPtr, "\nCannot Create Waterfall Display Data for batch  %d \n", batchNumber);
00906         free (sNumOfScans);
00907         free (sFramesPerScan);
00908         free (classification);
00909         free (stringTemp);
00910         free (cleanArray);
00911         free (sNumOfFreqBins);
00912         free (sNumOfChannels);
00913         return;
00914     }
00915 
00916     //    Updates header for the Waterfall output file
00917     qfits_header_mod (pHeaderOut, "BITPIX","-64", "number of bits per pixel");
00918     qfits_header_mod (pHeaderOut, "NAXIS", "2", "number of data axes");
00919     qfits_header_add (pHeaderOut, "NAXIS1", sFramesPerScan, "", "");
00920     qfits_header_add (pHeaderOut, "NAXIS2", sNumOfScans, "", "");
00921     qfits_header_add (pHeaderOut, "FREQBIN", sNumOfFreqBins, "", "");
00922     qfits_header_add (pHeaderOut, "NUMCHAN", sNumOfChannels, "", "");
00923     qfits_header_mod (pHeaderOut, "INSTRUME", "MIDI", "MIDI Raw Data Display FITS created by DRS pipeline" );
00924     qfits_header_add (pHeaderOut, "HIERARCH ESO PRO CATG", "WATERFALL", "Pipeline product category", NULL);
00925     qfits_header_add (pHeaderOut, "HIERARCH ESO PRO ARCFILE", fileNames->archFileName, "Arcfile name of first raw file", "");
00926     qfits_header_add (pHeaderOut, "HIERARCH ESO PRO PIPEDATE", currentTime, "Pipeline run date", "");
00927     qfits_header_add (pHeaderOut, "HIERARCH ESO PRO VERSION", MIDI_PIPE_VERSION, "Pipeline version", "");
00928     qfits_header_add (pHeaderOut, "PIPEFILE", fileNames->pipeFileName, "Pipeline product file name", "");
00929 
00930     //    Create file and dump FITS Header for Waterfall output file. If the file exist delete it
00931     if (stat (fileNames->outWaterfallName, &buf) == 0) remove (fileNames->outWaterfallName);
00932     if ((waterfallPtr = fopen (fileNames->outWaterfallName, "w")) == NULL)
00933     {
00934         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create Waterfall FITS file");
00935         free (sNumOfScans);
00936         free (sFramesPerScan);
00937         free (classification);
00938         free (stringTemp);
00939         qfits_header_destroy (pHeaderOut);
00940         free (cleanArray);
00941         free (sNumOfFreqBins);
00942         free (sNumOfChannels);
00943         return;
00944     }
00945 
00946     if (diagnostic)cpl_msg_info(cpl_func,"Created Waterfall FITS file: %s \n", fileNames->outWaterfallName);
00947     fprintf (midiReportPtr, "Created Waterfall FITS file: %s \n", fileNames->outWaterfallName);
00948 
00949     qfits_header_dump (pHeaderOut, waterfallPtr);
00950     fclose (waterfallPtr);
00951 
00952     //    Done writing header, close structure
00953     qfits_header_destroy (pHeaderOut);
00954 
00955     //    Dumps Fringe into the Waterfall file
00956     qdFringe.filename  = fileNames->outWaterfallName;
00957     qdFringe.npix      = framesPerScan * numOfScans;
00958     qdFringe.ptype     = PTYPE_DOUBLE;
00959     qdFringe.dbuf      = cleanArray;
00960     qdFringe.out_ptype = BPP_IEEE_DOUBLE;
00961 
00962     qfits_pixdump (&qdFringe);
00963     qfits_zeropad (fileNames->outWaterfallName);
00964 
00965     //    Close files and release memory
00966     fclose (inFitsBatchPtr);
00967     free (sNumOfScans);
00968     free (sFramesPerScan);
00969     free (sNumOfFreqBins);
00970     free (sNumOfChannels);
00971     free (classification);
00972     free (stringTemp);
00973     free (currentTime);
00974 
00975     //    Create plot file
00976     if (plotFile)
00977     {
00978         //    Allocate memory
00979         fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00980         title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
00981 
00982         //    Plot a few fringes around the maximum
00983         sprintf (fileName, "FringeAtScan%d", scanMax-1);
00984         sprintf (title, "Fringe at scan %d", scanMax-1);
00985 
00986         if(scanMax<2){
00987            frameStart = 0;
00988            frameEnd = framesPerScan;
00989         }
00990         else {
00991            frameStart = (scanMax - 2) * framesPerScan;
00992            frameEnd = (scanMax - 1) * framesPerScan;
00993         }
00994         midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux (dc removed)", 0, cleanArray, frameStart, frameEnd, 1);
00995  
00996         sprintf (fileName, "FringeStrongest");
00997         sprintf (title, "Strongest fringe found at scan %d", scanMax);
00998         frameStart = (scanMax - 1) * framesPerScan;
00999         frameEnd = scanMax * framesPerScan;
01000         midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux (dc removed)", 0, cleanArray, frameStart, frameEnd, 1);
01001  
01002         sprintf (fileName, "FringeAtScan%d", scanMax+1);
01003         sprintf (title, "Fringe at scan %d", scanMax+1);
01004         frameStart = scanMax * framesPerScan;
01005         frameEnd = (scanMax + 1) * framesPerScan;
01006         midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux (dc removed)", 0, cleanArray, frameStart, frameEnd, 1);
01007  
01008         free (fileName);
01009         free (title);
01010     }
01011     free (cleanArray);
01012 
01013     return;
01014 }
01015 /*****************************************************************************/
01016 
01017 
01018 /******************************************************************************
01019 *               European Southern Observatory
01020 *            VLTI MIDI Data Reduction Software
01021 *
01022 * Module name:  prepareWaterpowerDisplay
01023 * Input/Output: See function arguments to avoid duplication
01024 * Description:  This routine creates the waterpower display
01025 *
01026 * History:
01027 * 21-Jul-03     (csabet) Created
01028 ******************************************************************************/
01029 void prepareWaterpowerDisplay (
01030     MidiFiles    *fileNames,        // In: Pointer to file structure including target file name
01031     ImageFormat    *imageSize,        // In: Pointer to image structure
01032     float        *allSpectrum)    // In: Compressed spectrum for all regions
01033 {
01034     /*  Local Declarations
01035     ---------------------- */
01036     const char      routine[] = "prepareWaterpowerDisplay";
01037     qfits_header    *pHeaderOut;
01038     FILE            *waterpowerPtr;
01039     qfitsdumper     qdEachSpectrum;
01040     char            *sFramesPerScan, *sNumOfScans, *classification, *stringTemp;
01041     FILE            *inFitsBatchPtr = NULL;
01042     struct stat     buf;
01043 
01044     /*  Algorithm
01045     -----------*/
01046     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01047     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
01048 
01049    cpl_msg_info(cpl_func,"\nCreating Waterpower Display Data for batch  %d \n", batchNumber);
01050    cpl_msg_info(cpl_func,"------------------------------------------ \n");
01051     fprintf (midiReportPtr, "\nCreating Waterpower Display Data for batch  %d \n", batchNumber);
01052     fprintf (midiReportPtr, "------------------------------------------ \n");
01053 
01054     /*  Allocate memory */
01055     stringTemp = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01056     classification = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01057     sNumOfScans = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01058     sFramesPerScan = (char *) calloc (MIN_STRING_LENGTH, sizeof (char));
01059 
01060     /*  Write all NAXIS values as character strings */
01061     sprintf (sNumOfScans, "%d", imageSize->numOfScans); // imageSize->numOfScans);
01062     sprintf (sFramesPerScan, "%d", imageSize->fftsize/2);
01063 
01064     /*  Open the list of files */
01065     if ((inFitsBatchPtr = fopen (fileNames->inFitsBatch, "r")) == NULL)
01066     {
01067         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot open input FITS file list");
01068        cpl_msg_info(cpl_func,"\nCannot Create Waterpower Display Data for batch  %d \n", batchNumber);
01069         fprintf (midiReportPtr, "\nCannot Create Waterpower Display Data for batch  %d \n", batchNumber);
01070         free (sNumOfScans);
01071         free (sFramesPerScan);
01072         free (classification);
01073         free (stringTemp);
01074         return;
01075     }
01076     /*  Read the name of the first file in the list and get it's full path name */
01077     fgets (stringTemp, MAX_STRING_LENGTH, inFitsBatchPtr);
01078     sprintf (classification, "%s", "");
01079     sscanf (stringTemp, "%s%s", fileNames->inFitsName, classification);
01080 
01081     /*  Add primary Header */
01082     if (diagnostic)cpl_msg_info(cpl_func,"Extracting primary header from input FITS file   %s \n", fileNames->inFitsName);
01083     if (diagnostic) fprintf(midiReportPtr, "Extracting primary header from input FITS file   %s \n", fileNames->inFitsName);
01084     pHeaderOut = qfits_header_read (fileNames->inFitsName);
01085     if (pHeaderOut == NULL)
01086     {
01087         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot extract header from input FITS file");
01088        cpl_msg_info(cpl_func,"\nCannot Create Waterpower Display Data for batch  %d \n", batchNumber);
01089         fprintf (midiReportPtr, "\nCannot Create Waterpower Display Data for batch  %d \n", batchNumber);
01090         free (sNumOfScans);
01091         free (sFramesPerScan);
01092         free (classification);
01093         free (stringTemp);
01094         return;
01095     }
01096 
01097     /*  Updates header for the Waterpower output file */
01098     qfits_header_mod (pHeaderOut, "BITPIX","-64", "number of bits per pixel");
01099     qfits_header_mod (pHeaderOut, "NAXIS", "2", "number of data axes");
01100     qfits_header_add (pHeaderOut, "NAXIS1", sFramesPerScan, "", "");
01101     qfits_header_add (pHeaderOut, "NAXIS2", sNumOfScans, "", "");
01102     qfits_header_mod (pHeaderOut, "INSTRUME", "MIDI", "MIDI Raw Data Display FITS created by DRS pipeline" );
01103 
01104     //    Create file and dump FITS Header for Waterpower output file. If the file exist delete it
01105     if (stat (fileNames->outWaterpowerName, &buf) == 0) remove (fileNames->outWaterpowerName);
01106     if ((waterpowerPtr = fopen (fileNames->outWaterpowerName, "w")) == NULL)
01107     {
01108         midiReportWarning (midiReportPtr, routine, __FILE__, __LINE__, "Cannot create Waterpower FITS file");
01109         free (sNumOfScans);
01110         free (sFramesPerScan);
01111         free (classification);
01112         free (stringTemp);
01113         qfits_header_destroy (pHeaderOut);
01114         return;
01115     }
01116 
01117     if (diagnostic)cpl_msg_info(cpl_func,"Created Waterpower FITS file: %s \n", fileNames->outWaterpowerName);
01118     fprintf (midiReportPtr, "Created Waterpower FITS file: %s \n", fileNames->outWaterpowerName);
01119 
01120     qfits_header_dump (pHeaderOut, waterpowerPtr);
01121     fclose (waterpowerPtr);
01122 
01123     /*  Done writing header, close structure */
01124     qfits_header_destroy (pHeaderOut);
01125 
01126     /*  Dumps allSpectrum into the Waterpower file */
01127     qdEachSpectrum.filename  = fileNames->outWaterpowerName;
01128     qdEachSpectrum.npix      = imageSize->allSpectrumLength;
01129     qdEachSpectrum.ptype     = PTYPE_FLOAT;
01130     qdEachSpectrum.fbuf      = allSpectrum;
01131     qdEachSpectrum.out_ptype = BPP_IEEE_FLOAT;
01132 
01133     qfits_pixdump (&qdEachSpectrum);
01134     qfits_zeropad (fileNames->outWaterpowerName);
01135 
01136     /*  Close files */
01137     fclose (inFitsBatchPtr);
01138 
01139     /*  Release memory */
01140     free (sNumOfScans);
01141     free (sFramesPerScan);
01142     free (classification);
01143     free (stringTemp);
01144 
01145     return;
01146 }
01147 /*****************************************************************************/
01148 
01149 
01150 
01151 /******************************************************************************
01152 *               European Southern Observatory
01153 *             VLTI MIDI Data Reduction Software
01154 *
01155 * Module name:  reportInterfChopping
01156 * Input/Output: See function arguments to avoid duplication
01157 * Description:  Checks chopping cycles
01158 *
01159 * History:
01160 * 06-Dec-05     (csabet)
01161 ******************************************************************************/
01162 void reportInterfChopping (
01163     const char            *dataKey,        // In: Whether Interferometry or Photometry etc.
01164     ImageFormat        *format,        // In: Image format
01165     CompressedData    *compressed)    // In: Compressed data
01166 {
01167 
01168     //    Local Declarations
01169     //    ------------------
01170     const char  routine[] = "reportInterfChopping";
01171     int            f, s, u, n, fps;
01172     char        *fileName, *title, *dataFilePath;
01173     FILE        *dataFilePtr=NULL;
01174     double        *array;
01175     
01176     //    Algorithm
01177     //    ---------
01178     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01179     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
01180 
01181     //    Reset
01182     fps = format->framesPerScan;
01183 
01184     //    Allocate memory
01185     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01186 
01187     //    Create a QC log file for Interferometry
01188     sprintf (dataFilePath, "%s%s.Compressed%s.qc.dummy", outFileDir, outRootName, dataKey);
01189     dataFilePtr = fopen (dataFilePath, "w");
01190 
01191     if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
01192         (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
01193     {
01194         fprintf (dataFilePtr, "Frame  TarType  DATA1              DATA2              DATA1-DATA2 \n");
01195         fprintf (dataFilePtr, "================================================================= \n");
01196     }
01197     else
01198     {
01199         fprintf (dataFilePtr, "Frame  TarType  DATA2              DATA3              DATA2-DATA3 \n");
01200         fprintf (dataFilePtr, "================================================================= \n");
01201     }
01202     for (f = 0; f < format->numOfFrames; f++)
01203     {
01204         fprintf (dataFilePtr, "%5d  %c        %f    %f    %f\n", f, compressed->tarType[f], 
01205             compressed->iFringe1[f], compressed->iFringe2[f], compressed->iFringe[f]);
01206     }
01207     fclose (dataFilePtr);
01208 
01209     //    Create statistics and plot    
01210     s = u = compressed->numOfTargetChops = 0;
01211     for (f = 0; f < format->numOfFrames; f++)
01212     {
01213         if (compressed->tarType[f] == 'S') s++;
01214         else if (compressed->tarType[f] == 'T') (compressed->numOfTargetChops)++;
01215         else u++;
01216     }
01217 
01218    cpl_msg_info(cpl_func,"\n%s Chopping Statistics QCLOG \n", dataKey);
01219    cpl_msg_info(cpl_func,"---------------------------------    QCLOG \n");
01220    cpl_msg_info(cpl_func,"Number of Target chops    = %d       QCLOG \n", compressed->numOfTargetChops);
01221    cpl_msg_info(cpl_func,"Number of Sky chops       = %d       QCLOG \n", s);
01222    cpl_msg_info(cpl_func,"Number of Undefined chops = %d       QCLOG \n", u);
01223     fprintf (midiReportPtr, "\n%s Chopping Statistics QCLOG \n", dataKey);
01224     fprintf (midiReportPtr, "---------------------------------    QCLOG \n");
01225     fprintf (midiReportPtr, "Number of Target chops    = %d       QCLOG \n", compressed->numOfTargetChops);
01226     fprintf (midiReportPtr, "Number of Sky chops       = %d       QCLOG \n", s);
01227     fprintf (midiReportPtr, "Number of Undefined chops = %d       QCLOG \n", u);
01228     
01229     if (plotFile && diagnostic > 1)
01230     {
01231         array = (double *) calloc (format->numOfFrames, sizeof (double));
01232         fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01233         title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01234         
01235         if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
01236             (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
01237         {
01238             n = 0;
01239             for (f = 0; f < format->numOfFrames; f++)
01240             {
01241                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
01242                 {
01243                     array[n] = compressed->iFringe1[f];
01244                     n++;
01245                 }
01246             }
01247             sprintf (fileName, "%sCompressedDATA1", dataKey);
01248             sprintf (title, "Compressed %s DATA1", dataKey);
01249             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01250 
01251             n = 0;
01252             for (f = 0; f < format->numOfFrames; f++)
01253             {
01254                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe2[f]))))
01255                 {
01256                     array[n] = compressed->iFringe2[f];
01257                     n++;
01258                 }
01259             }
01260             sprintf (fileName, "%sCompressedDATA2", dataKey);
01261             sprintf (title, "Compressed %s DATA2", dataKey);
01262             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01263 
01264             n = 0;
01265             for (f = 0; f < format->numOfFrames; f++)
01266             {
01267                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe[f]))))
01268                 {
01269                     array[n] = compressed->iFringe[f];
01270                     n++;
01271                 }
01272             }
01273             sprintf (fileName, "%sCompressedDATA1_DATA2", dataKey);
01274             sprintf (title, "Compressed %s DATA1-DATA2", dataKey);
01275             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01276         }
01277         else
01278         {
01279             n = 0;
01280             for (f = 0; f < format->numOfFrames; f++)
01281             {
01282                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
01283                 {
01284                     array[n] = compressed->iFringe1[f];
01285                     n++;
01286                 }
01287             }
01288             sprintf (fileName, "%sCompressedDATA2", dataKey);
01289             sprintf (title, "Compressed %s DATA2", dataKey);
01290             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01291 
01292             n = 0;
01293             for (f = 0; f < format->numOfFrames; f++)
01294             {
01295                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe2[f]))))
01296                 {
01297                     array[n] = compressed->iFringe2[f];
01298                     n++;
01299                 }
01300             }
01301             sprintf (fileName, "%sCompressedDATA3", dataKey);
01302             sprintf (title, "Compressed %s DATA3", dataKey);
01303             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01304 
01305             n = 0;
01306             for (f = 0; f < format->numOfFrames; f++)
01307             {
01308                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe[f]))))
01309                 {
01310                     array[n] = compressed->iFringe[f];
01311                     n++;
01312                 }
01313             }
01314             sprintf (fileName, "%sCompressedDATA2_DATA3", dataKey);
01315             sprintf (title, "Compressed %s DATA2-DATA3", dataKey);
01316             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01317         }
01318         free (fileName);
01319         free (title);
01320         free (array);
01321     }
01322 
01323     //    Release memory
01324     free (dataFilePath);
01325 
01326     return;
01327 }
01328 /*****************************************************************************/
01329 
01330 
01331 
01332 /******************************************************************************
01333 *               European Southern Observatory
01334 *             VLTI MIDI Data Reduction Software
01335 *
01336 * Module name:  displayInterfChoppingDisp
01337 * Input/Output: See function arguments to avoid duplication
01338 * Description:  Checks chopping cycles
01339 *
01340 * History:
01341 * 06-Dec-05     (csabet)
01342 ******************************************************************************/
01343 void displayInterfChoppingDisp (
01344     const char            *dataKey,        // In: Whether Interferometry or Photometry etc.
01345     ImageFormat        *format,        // In: Image format
01346     CompressedData    *compressed)    // In: Compressed data
01347 {
01348 
01349     //    Local Declarations
01350     //    ------------------
01351     const char  routine[] = "displayInterfChoppingDisp";
01352     int            f, n, X, R;
01353     char        *fileName, *title;
01354     float        *arrayF;
01355     
01356     //    Algorithm
01357     //    ---------
01358     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01359     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
01360 
01361     //    Display for each channel
01362     if (plotFile && diagnostic > 4)
01363     {
01364         arrayF = (float *) calloc (format->numOfFrames, sizeof (float));
01365         fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01366         title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01367         
01368         for (R = 0; R < format->numOfRegionsToProcess; R++)
01369         {
01370             for (X = 0; X < format->iXWidth; X++)
01371             {
01372                 if (badChannelList[X])
01373                     continue;
01374                     
01375                 n = 0;
01376                 for (f = 0; f < format->numOfFrames; f++)
01377                 {
01378                     if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iDispFringe[R][X][f]))))
01379                     {
01380                         arrayF[n] = compressed->iDispFringe[R][X][f];
01381                         n++;
01382                     }
01383                 }
01384                 if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
01385                     (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
01386                 {
01387                     sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+1, X+1);
01388                     sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+1, X+1);
01389                 }
01390                 else
01391                 {
01392                     sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+2, X+1);
01393                     sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+2, X+1);
01394                 }
01395                 midiCreatePlotFile2D (fileName, title, "Frame", "Flux", 0, arrayF, 0, n, 1, 0);
01396             }
01397         }
01398         free (fileName);
01399         free (title);
01400         free (arrayF);
01401     }
01402     
01403     return;
01404 }
01405 /*****************************************************************************/
01406 
01407 
01408 /******************************************************************************
01409 *               European Southern Observatory
01410 *             VLTI MIDI Data Reduction Software
01411 *
01412 * Module name:  reportPhotomChopping
01413 * Input/Output: See function arguments to avoid duplication
01414 * Description:  Determines chopping coherency
01415 *
01416 * History:
01417 * 06-Dec-05     (csabet)
01418 ******************************************************************************/
01419 void reportPhotomChopping (
01420     const char            *dataKey,        // In: Whether Interferometry or Photometry etc.
01421     ImageFormat        *format,        // In: Image format
01422     CompressedData    *compressed)    // In: Compressed data
01423 {
01424 
01425     //    Local Declarations
01426     //    ------------------
01427     const char  routine[] = "reportPhotomChopping";
01428     int            f, s, t, u, n, fps;
01429     char        *fileName, *title, *dataFilePath;
01430     FILE        *dataFilePtr=NULL;
01431     double        *array;
01432     
01433     //    Algorithm
01434     //    ---------
01435     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01436     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
01437 
01438     //    Reset
01439     fps = format->framesPerScan;
01440 
01441     //    Allocate memory
01442     dataFilePath = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01443 
01444     //    Create a QC log file for Interferometry
01445     sprintf (dataFilePath, "%s%s.Compressed%s.qc.dummy", outFileDir, outRootName, dataKey);
01446     dataFilePtr = fopen (dataFilePath, "w");
01447 
01448     if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
01449         (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
01450     {
01451         fprintf (dataFilePtr, "Frame  TarType  DATA1              DATA2 \n");
01452         fprintf (dataFilePtr, "======================================== \n");
01453         for (f = 0; f < format->numOfFrames; f++)
01454         {
01455             fprintf (dataFilePtr, "%5d  %c        %f    %f \n", f, compressed->tarType[f], 
01456                 compressed->iFringe1[f], compressed->iFringe2[f]);
01457         }
01458     }
01459     else
01460     {
01461         if (strcmp (format->shutterId, "AOPEN") == 0)
01462         {
01463             fprintf (dataFilePtr, "Frame  TarType  DATA1 \n");
01464             fprintf (dataFilePtr, "===================== \n");
01465             for (f = 0; f < format->numOfFrames; f++)
01466             {
01467                 fprintf (dataFilePtr, "%5d  %c        %f \n", f, compressed->tarType[f], 
01468                     compressed->iFringe1[f]);
01469             }
01470         }
01471         else if (strcmp (format->shutterId, "BOPEN") == 0)
01472         {
01473             fprintf (dataFilePtr, "Frame  TarType  DATA4 \n");
01474             fprintf (dataFilePtr, "===================== \n");
01475             for (f = 0; f < format->numOfFrames; f++)
01476             {
01477                 fprintf (dataFilePtr, "%5d  %c        %f \n", f, compressed->tarType[f], 
01478                     compressed->iFringe1[f]);
01479             }
01480         }
01481         else if (strcmp (format->shutterId, "ABOPEN") == 0)
01482         {
01483             fprintf (dataFilePtr, "Frame  TarType  DATA1 or DATA4 \n");
01484             fprintf (dataFilePtr, "============================== \n");
01485             for (f = 0; f < format->numOfFrames; f++)
01486             {
01487                 fprintf (dataFilePtr, "%5d  %c        %f \n", f, compressed->tarType[f], 
01488                     compressed->iFringe1[f]);
01489             }
01490         }
01491     }
01492     fclose (dataFilePtr);
01493 
01494     //    Create statistics and plot    
01495     s = t = u = 0;
01496     for (f = 0; f < format->numOfFrames; f++)
01497     {
01498         if (compressed->tarType[f] == 'S') s++;
01499         else if (compressed->tarType[f] == 'T') t++;
01500         else u++;
01501     }
01502 
01503    cpl_msg_info(cpl_func,"\n%s Chopping Statistics QCLOG \n", dataKey);
01504    cpl_msg_info(cpl_func,"---------------------------------    QCLOG \n");
01505    cpl_msg_info(cpl_func,"Number of Target chops    = %d       QCLOG \n", t);
01506    cpl_msg_info(cpl_func,"Number of Sky chops       = %d       QCLOG \n", s);
01507    cpl_msg_info(cpl_func,"Number of Undefined chops = %d       QCLOG \n", u);
01508     fprintf (midiReportPtr, "\n%s Chopping Statistics QCLOG \n", dataKey);
01509     fprintf (midiReportPtr, "---------------------------------    QCLOG \n");
01510     fprintf (midiReportPtr, "Number of Target chops    = %d       QCLOG \n", t);
01511     fprintf (midiReportPtr, "Number of Sky chops       = %d       QCLOG \n", s);
01512     fprintf (midiReportPtr, "Number of Undefined chops = %d       QCLOG \n", u);
01513     
01514     if (plotFile && diagnostic > 1)
01515     {
01516         array = (double *) calloc (format->numOfFrames, sizeof (double));
01517         fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01518         title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01519         
01520         if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
01521             (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
01522         {
01523             n = 0;
01524             for (f = 0; f < format->numOfFrames; f++)
01525             {
01526                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
01527                 {
01528                     array[n] = compressed->iFringe1[f];
01529                     n++;
01530                 }
01531             }
01532             sprintf (fileName, "%sCompressedDATA1", dataKey);
01533             sprintf (title, "Compressed %s DATA1", dataKey);
01534             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01535 
01536             n = 0;
01537             for (f = 0; f < format->numOfFrames; f++)
01538             {
01539                 if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe2[f]))))
01540                 {
01541                     array[n] = compressed->iFringe2[f];
01542                     n++;
01543                 }
01544             }
01545             sprintf (fileName, "%sCompressedDATA2", dataKey);
01546             sprintf (title, "Compressed %s DATA2", dataKey);
01547             midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01548         }
01549         else
01550         {
01551             if (strcmp (format->shutterId, "AOPEN") == 0)
01552             {
01553                 n = 0;
01554                 for (f = 0; f < format->numOfFrames; f++)
01555                 {
01556                     if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
01557                     {
01558                         array[n] = compressed->iFringe1[f];
01559                         n++;
01560                     }
01561                 }
01562                 sprintf (fileName, "%sCompressedDATA1", dataKey);
01563                 sprintf (title, "Compressed %s DATA1", dataKey);
01564                 midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01565             }
01566             else if (strcmp (format->shutterId, "BOPEN") == 0)
01567             {
01568                 n = 0;
01569                 for (f = 0; f < format->numOfFrames; f++)
01570                 {
01571                     if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
01572                     {
01573                         array[n] = compressed->iFringe1[f];
01574                         n++;
01575                     }
01576                 }
01577                 sprintf (fileName, "%sCompressedDATA4", dataKey);
01578                 sprintf (title, "Compressed %s DATA4", dataKey);
01579                 midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01580             }
01581             else
01582             {
01583                 if (strcmp (dataKey, "PHOTOMA") == 0)
01584                 {
01585                     n = 0;
01586                     for (f = 0; f < format->numOfFrames; f++)
01587                     {
01588                         if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
01589                         {
01590                             array[n] = compressed->iFringe1[f];
01591                             n++;
01592                         }
01593                     }
01594                     sprintf (fileName, "%sCompressedDATA1", dataKey);
01595                     sprintf (title, "Compressed %s DATA1", dataKey);
01596                     midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01597                 }
01598                 else
01599                 {
01600                     n = 0;
01601                     for (f = 0; f < format->numOfFrames; f++)
01602                     {
01603                         if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iFringe1[f]))))
01604                         {
01605                             array[n] = compressed->iFringe1[f];
01606                             n++;
01607                         }
01608                     }
01609                     sprintf (fileName, "%sCompressedDATA4", dataKey);
01610                     sprintf (title, "Compressed %s DATA4", dataKey);
01611                     midiCreatePlotFileDouble2D (fileName, title, "Frame", "Flux", 0, array, 0, n, 1);
01612                 }
01613             }
01614         }
01615         free (fileName);
01616         free (title);
01617         free (array);
01618     }
01619     
01620     //    Release memory
01621     free (dataFilePath);
01622 
01623     return;
01624 }
01625 /*****************************************************************************/
01626 
01627 
01628 /******************************************************************************
01629 *               European Southern Observatory
01630 *             VLTI MIDI Data Reduction Software
01631 *
01632 * Module name:  displayPhotomChoppingDisp
01633 * Input/Output: See function arguments to avoid duplication
01634 * Description:  Determines chopping coherency
01635 *
01636 * History:
01637 * 06-Dec-05     (csabet)
01638 ******************************************************************************/
01639 void displayPhotomChoppingDisp (
01640     const char            *dataKey,        // In: Whether Interferometry or Photometry etc.
01641     ImageFormat        *format,        // In: Image format
01642     CompressedData    *compressed)    // In: Compressed data
01643 {
01644 
01645     //    Local Declarations
01646     //    ------------------
01647     const char  routine[] = "displayPhotomChoppingDisp";
01648     int            f, n, X, R;
01649     char        *fileName, *title;
01650     float        *arrayF;
01651     
01652     //    Algorithm
01653     //    ---------
01654     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01655     if (diagnostic > 4) fprintf (midiReportPtr, "Invoking      routine   '%s' \n", routine);
01656 
01657 
01658     //    Display for each channel
01659     if (plotFile && diagnostic > 4)
01660     {
01661         arrayF = (float *) calloc (format->numOfFrames, sizeof (float));
01662         fileName = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01663         title = (char *) calloc (MAX_STRING_LENGTH, sizeof (char));
01664         
01665         for (R = 0; R < format->numOfRegionsToProcess; R++)
01666         {
01667             for (X = 0; X < format->iXWidth; X++)
01668             {
01669                 n = 0;
01670                 for (f = 0; f < format->numOfFrames; f++)
01671                 {
01672                     if ((compressed->tarType[f] != 'U') && (!(isnan (compressed->iDispFringe[R][X][f]))))
01673                     {
01674                         arrayF[n] = compressed->iDispFringe[R][X][f];
01675                         n++;
01676                     }
01677                 }
01678                 if ((strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0) ||
01679                     (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0))
01680                 {
01681                     sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+1, X+1);
01682                     sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+1, X+1);
01683                 }
01684                 else
01685                 {
01686                     if (strcmp (dataKey, "PHOTOMA") == 0)
01687                     {
01688                         sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+1, X+1);
01689                         sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+1, X+1);
01690                     }
01691                     else
01692                     {
01693                         sprintf (fileName, "%sCompressedDATA%d_X%d", dataKey, R+4, X+1);
01694                         sprintf (title, "Compressed %s DATA%d for Channel %d", dataKey, R+4, X+1);
01695                     }
01696                 }
01697                 midiCreatePlotFile2D (fileName, title, "Frame", "Flux", 0, arrayF, 0, n, 1, 0);
01698             }
01699         }
01700         free (fileName);
01701         free (title);
01702         free (arrayF);
01703     }
01704     
01705     return;
01706 }
01707 /*****************************************************************************/
01708 
01709 
01710 /******************************************************************************
01711 *               European Southern Observatory
01712 *            VLTI MIDI Data Reduction Software
01713 *
01714 * Module name:  countTransitions
01715 * Input/Output: See function arguments to avoid duplication
01716 * Description:  Checks chopping transitions
01717 *
01718 * History:
01719 * 08-Feb-06     (csabet) Created
01720 ******************************************************************************/
01721 int countTransitions (    // Ou: Chopping transitions
01722     char    key,        // In: Given TarTyp
01723     int        length,        // In: Length of array
01724     char    *tarType)    // In: Array of tarType
01725 
01726 {
01727     //    Local Declarations
01728     //    ------------------
01729     const char        routine[] = "countTransitions";
01730     int                i, transitions, sighting;
01731     char            lastTarTyp;
01732 
01733     //    Algorithm
01734     //    ---------
01735     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01736     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
01737 
01738     //    Initialise
01739     transitions = 0;
01740     sighting = 0;
01741     lastTarTyp = tarType[0];
01742 
01743     //    Count transitions
01744     if (lastTarTyp == key) sighting++;
01745     for (i = 1; i < length; i++)
01746     {
01747         if (tarType[i] == key)
01748         {
01749             if (sighting && tarType[i] != lastTarTyp) 
01750                 transitions++;
01751 
01752             sighting++;
01753         }
01754         
01755         lastTarTyp = tarType[i];
01756     }
01757     if (!sighting) transitions = - 1;
01758 
01759     return (transitions);
01760 }
01761 /*****************************************************************************/
01762 
01763 
01764 /******************************************************************************
01765 *               European Southern Observatory
01766 *            VLTI MIDI Data Reduction Software
01767 *
01768 * Module name:  midiReportResultsFringe
01769 * Input/Output: See function arguments to avoid duplication
01770 * Description:  Reports all the results
01771 *
01772 * History:
01773 * 23-Feb-05     (csabet) Created
01774 ******************************************************************************/
01775 void midiReportResultsFringe (
01776     float           *freqCal,        // IO: Calibrated frequency in THz
01777     ImageFormat        *format,        // In: Image size of interferometry data
01778     DispersedResult    *dispResult)    // In: Result data structure
01779 {
01780 
01781     //  Local Declarations
01782     //    ------------------
01783     const char    routine[] = "midiReportResultsFringe";
01784     int            X;
01785 
01786     //    Algorithm
01787     //    ---------
01788     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01789     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine   '%s' \n", routine);
01790 
01791 
01792    cpl_msg_info(cpl_func,"\nReporting the results for batch %d \n", batchNumber);
01793    cpl_msg_info(cpl_func,"------------------------------- \n");
01794     fprintf (midiReportPtr, "\nReporting the results for batch %d \n", batchNumber);
01795     fprintf (midiReportPtr, "------------------------------- \n");
01796 
01797     //    Recalculate number of channels rejected
01798     format->numOfChannelsProcessed = 0;
01799     for (X = 0; X < format->iXWidth; X++)
01800     {
01801         if (!(badChannelList[X]))
01802             (format->numOfChannelsProcessed)++;
01803     }
01804     format->numOfChannelsRejected = format->iXWidth - format->numOfChannelsProcessed;
01805     
01806    cpl_msg_info(cpl_func,"Observation Category         = %s \n", format->obsCatg);
01807    cpl_msg_info(cpl_func,"\nResult Abbreviation \n");
01808    cpl_msg_info(cpl_func,"------------------- \n");
01809    cpl_msg_info(cpl_func,"X      = Channel Number \n");
01810    cpl_msg_info(cpl_func,"F      = Channel Frequency in THz \n");
01811    cpl_msg_info(cpl_func,"W      = Channel Wavelength in microns \n");
01812    cpl_msg_info(cpl_func,"RVis   = Raw Visibility \n");
01813    cpl_msg_info(cpl_func,"RVisEr = Raw Visibility Error (Standard deviation) \n");
01814    cpl_msg_info(cpl_func,"NVis   = Normalised Visibility \n");
01815    cpl_msg_info(cpl_func,"NVisEr = Normalised Visibility Error (Standard deviation) \n");
01816    cpl_msg_info(cpl_func,"PhNe   = \'Net\' Photometry \n");
01817    cpl_msg_info(cpl_func,"PhNeEr = \'Net\' Photometry Error (Standard deviation) \n");
01818    cpl_msg_info(cpl_func,"TF     = Transfer Function \n");
01819    cpl_msg_info(cpl_func,"TFEr   = Transfer Function Error (Standard deviation) \n");
01820    cpl_msg_info(cpl_func,"CVis   = Calibrated Visibility \n");
01821    cpl_msg_info(cpl_func,"CVisEr = Calibrated Visibility Error (Standard deviation) \n");
01822 
01823     fprintf (midiReportPtr, "Observation Category      = %s                               QCLOG \n", format->obsCatg);
01824     fprintf (midiReportPtr, "\nResult Abbreviation                                        QCLOG \n");
01825     fprintf (midiReportPtr, "-------------------                                          QCLOG \n");
01826     fprintf (midiReportPtr, "X      = Channel Number                                      QCLOG \n");
01827     fprintf (midiReportPtr, "F      = Channel Frequency in THz                            QCLOG \n");
01828     fprintf (midiReportPtr, "W      = Channel Wavelength in microns                       QCLOG \n");
01829     fprintf (midiReportPtr, "RVis   = Raw Visibility                                      QCLOG \n");
01830     fprintf (midiReportPtr, "RVisEr = Raw Visibility Error (Standard deviation)           QCLOG \n");
01831     fprintf (midiReportPtr, "NVis   = Normalised Visibility                               QCLOG \n");
01832     fprintf (midiReportPtr, "NVisEr = Normalised Visibility Error (Standard deviation)    QCLOG \n");
01833     fprintf (midiReportPtr, "PhNe   = \'Net\' Photometry                                  QCLOG \n");
01834     fprintf (midiReportPtr, "PhNeEr = \'Net\' Photometry Error (Standard deviation)       QCLOG \n");
01835     fprintf (midiReportPtr, "TF     = Transfer Function                                   QCLOG \n");
01836     fprintf (midiReportPtr, "TFEr   = Transfer Function Error (Standard deviation)        QCLOG \n");
01837     fprintf (midiReportPtr, "CVis   = Calibrated Visibility                               QCLOG \n");
01838     fprintf (midiReportPtr, "CVisEr = Calibrated Visibility Error (Standard deviation)    QCLOG \n");
01839 
01840    cpl_msg_info(cpl_func,"\nX    W      F        RVis          RVisEr  NVis    NVisEr      ");
01841    cpl_msg_info(cpl_func,"PhNe      PhNeEr   TF      TFEr     CVis    CVisEr \n");
01842     fprintf (midiReportPtr, "\nX    W      F        RVis          RVisEr  NVis    NVisEr      ");
01843     fprintf (midiReportPtr, "PhNe      PhNeEr   TF      TFEr     CVis    CVisEr    QCLOG \n");
01844 
01845     for (X = 0; X < format->iXWidth; X++)
01846     {
01847         if (badChannelList[X])
01848         {
01849            cpl_msg_info(cpl_func,"%3d  %5.2f  %5.2f          <-- %s --> \n", 
01850                 X, freqCal[X], SPEED_OF_LIGHT/freqCal[X], UNAV); 
01851              fprintf (midiReportPtr, "%3d  %5.2f  %5.2f          <-- %s -->  QCLOG \n", 
01852                 X, freqCal[X], SPEED_OF_LIGHT/freqCal[X], UNAV); 
01853             continue;
01854         }
01855     
01856        cpl_msg_info(cpl_func,"%3d  %5.2f  %5.2f  %11.5f  %9.4f  %6.4f  %8.4f  %9.1f %7.2f   %6.4f   %6.4f   %5.3f    %5.3f \n", 
01857             X, freqCal[X], SPEED_OF_LIGHT/freqCal[X], 
01858             dispResult->rawVis2[X], dispResult->rawVis2Err[X], 
01859             dispResult->normVis2[X], dispResult->normVis2Err[X], 
01860             dispResult->photomNet2[X], dispResult->photomNet2Err[X], 
01861             dispResult->trf[X], dispResult->trfErr[X], 
01862             dispResult->calibVis2[X], dispResult->calibVis2Err[X]);
01863  
01864         fprintf (midiReportPtr, "%3d  %5.2f  %5.2f  %11.4f  %9.4f  %6.4f  %8.4f  %9.1f %7.2f   %6.4f   %6.4f   %5.3f    %5.3f     QCLOG\n", 
01865             X, freqCal[X], SPEED_OF_LIGHT/freqCal[X], 
01866             dispResult->rawVis2[X], dispResult->rawVis2Err[X], 
01867             dispResult->normVis2[X], dispResult->normVis2Err[X], 
01868             dispResult->photomNet2[X], dispResult->photomNet2Err[X], 
01869             dispResult->trf[X], dispResult->trfErr[X], 
01870             dispResult->calibVis2[X], dispResult->calibVis2Err[X]);
01871     }
01872 
01873     return;
01874 }
01875 /*****************************************************************************/
01876 
01877 /******************************************************************************
01878 *               European Southern Observatory
01879 *            VLTI MIDI Data Reduction Software
01880 *
01881 * Module name:  reportRejectList
01882 * Input/Output: See function arguments to avoid duplication
01883 * Description:    Final result of the rejection list for dispersed processing
01884 *
01885 * History:
01886 * 14-Mar-06     (csabet) Created
01887 ******************************************************************************/
01888 void reportRejectList (
01889     ImageFormat        *format,        // In: Points to the image format
01890     CompressedData    *compressed)    // In: Compressed data
01891 {
01892     //    Local Declarations
01893     //--------------------
01894     const char  routine[] = "reportRejectList";
01895     int            f, x, numOfFramesProcessed, numOfFramesRejected, frameFailureId;
01896 
01897     //    Algorithm
01898     //    ---------
01899     if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking      routine   '%s' \n", routine);
01900     if (diagnostic > 4) fprintf(midiReportPtr, "Invoking      routine '%s'  \n", routine);
01901 
01902    cpl_msg_info(cpl_func,"\nFinalising Scan, Frame and Channel rejection \n");
01903    cpl_msg_info(cpl_func,"-------------------------------------------- \n");
01904     fprintf (midiReportPtr, "\nFinalising Scan, Frame and Channel rejection \n");
01905     fprintf (midiReportPtr, "-------------------------------------------- \n");
01906 
01907     if (diagnostic)cpl_msg_info(cpl_func,"\nChannel   Number of Frames   Number of Frames   Frame Failure ID   Channel Failure ID \n");
01908     if (diagnostic)cpl_msg_info(cpl_func,"              Processed          Rejected \n");
01909     if (diagnostic)cpl_msg_info(cpl_func,"------------------------------------------------------------------------------------- \n");
01910     fprintf (midiReportPtr, "\nChannel   Number of Frames   Number of Frames   Frame Failure ID   Channel Failure ID \n");
01911     fprintf (midiReportPtr, "              Processed          Rejected \n");
01912     fprintf (midiReportPtr, "------------------------------------------------------------------------------------- \n");
01913 
01914     format->numOfChannelsRejected = 0;
01915     for (x = 0; x < format->iXWidth; x++)
01916     {
01917         frameFailureId = 0;
01918         numOfFramesProcessed = 0;
01919         
01920         //    If channel was masked no frames were processed
01921         for (f = 0; f < format->numOfFrames; f++)
01922         {
01923             if (!(compressed->rejectList[x][f]))
01924                 numOfFramesProcessed++;
01925 
01926             frameFailureId |= compressed->rejectList[x][f];
01927         }
01928 
01929         //    Count rejected channels
01930         if (!numOfFramesProcessed || (badChannelList[x]))
01931             (format->numOfChannelsRejected)++;
01932         
01933         //    Count rejected frames
01934         numOfFramesRejected = format->numOfFrames - numOfFramesProcessed;
01935         
01936         if (badChannelList[x])
01937         {
01938             if (diagnostic)cpl_msg_info(cpl_func,
01939                 "%3d       %4d                %4d                %4d                %4d                REJECTED\n", 
01940                 x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
01941             fprintf (midiReportPtr, 
01942                 "%3d       %4d                %4d                %4d                %4d                REJECTED  QCLOG \n", 
01943                 x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
01944         }
01945         else
01946         {
01947             if (diagnostic)cpl_msg_info(cpl_func,
01948                 "%3d       %4d                %4d                %4d                %4d \n", 
01949                 x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
01950             fprintf (midiReportPtr, 
01951                 "%3d       %4d                %4d                %4d                %4d                          QCLOG \n", 
01952                 x, numOfFramesProcessed, numOfFramesRejected, frameFailureId, badChannelList[x]);
01953         }
01954     }
01955 
01956     //    Count number of channels to process
01957     format->numOfChannelsProcessed = format->iXWidth - format->numOfChannelsRejected;
01958 
01959    cpl_msg_info(cpl_func,"Number of channels processed  = %3d \n", format->numOfChannelsProcessed);
01960    cpl_msg_info(cpl_func,"Number of channels rejected   = %3d \n", format->numOfChannelsRejected);
01961     fprintf (midiReportPtr, "Number of channels processed  = %3d QCLOG \n", format->numOfChannelsProcessed);
01962     fprintf (midiReportPtr, "Number of channels rejected   = %3d QCLOG \n", format->numOfChannelsRejected);
01963 
01964     if (diagnostic)
01965     {
01966        cpl_msg_info(cpl_func,"Failure ID \n");
01967        cpl_msg_info(cpl_func,"---------- \n");
01968        cpl_msg_info(cpl_func,"   1 = Bit  1, indicates a TIME error \n");
01969        cpl_msg_info(cpl_func,"   2 = Bit  2, indicates an LOCALOPD error \n");
01970        cpl_msg_info(cpl_func,"   4 = Bit  3, indicates an OPD error \n");
01971        cpl_msg_info(cpl_func,"   8 = Bit  4, indicates a Bad DATA \n");
01972        cpl_msg_info(cpl_func,"  16 = Bit  5, indicates a chopping problem (TARTYPE2) \n");
01973        cpl_msg_info(cpl_func,"  32 = Bit  6, indicates a Delay Line Jump \n");
01974        cpl_msg_info(cpl_func,"  64 = Bit  7, indicates an Unwanted Region \n");
01975        cpl_msg_info(cpl_func," 128 = Bit  8, indicates a Weak Signal/Noise \n");
01976        cpl_msg_info(cpl_func," 256 = Bit  9, indicates a SKY or Undefined \n");
01977        cpl_msg_info(cpl_func," 512 = Bit 10, indicates a TARTYPE Cross error. e.g. region 0 different to region 1 \n");
01978        cpl_msg_info(cpl_func,"1024 = Bit 11, indicates a Masked Channel \n");
01979        cpl_msg_info(cpl_func,"\nHence a number such as 168 indicates bits 4, 6 and 8 were set \n\n");
01980     }    
01981 
01982     fprintf (midiReportPtr, "Failure ID QCLOG \n");
01983     fprintf (midiReportPtr, "---------- QCLOG \n");
01984     fprintf (midiReportPtr, "   1 = Bit  1, indicates a TIME error QCLOG \n");
01985     fprintf (midiReportPtr, "   2 = Bit  2, indicates an LOCALOPD error QCLOG \n");
01986     fprintf (midiReportPtr, "   4 = Bit  3, indicates an OPD error QCLOG \n");
01987     fprintf (midiReportPtr, "   8 = Bit  4, indicates a Bad DATA QCLOG \n");
01988     fprintf (midiReportPtr, "  16 = Bit  5, indicates a chopping problem (TARTYPE2) QCLOG \n");
01989     fprintf (midiReportPtr, "  32 = Bit  6, indicates a Delay Line Jump QCLOG \n");
01990     fprintf (midiReportPtr, "  64 = Bit  7, indicates an Unwanted Region QCLOG \n");
01991     fprintf (midiReportPtr, " 128 = Bit  8, indicates a Weak Signal/Noise QCLOG \n");
01992     fprintf (midiReportPtr, " 256 = Bit  9, indicates a SKY or Undefined QCLOG \n");
01993     fprintf (midiReportPtr, " 512 = Bit 10, indicates a TARTYPE Cross error. e.g. region 0 different to region 1 QCLOG \n");
01994     fprintf (midiReportPtr, "1024 = Bit 11, indicates a Masked Channel QCLOG \n");
01995     fprintf (midiReportPtr, "\nHence a number such as 168 indicates bits 4, 6 and 8 were set QCLOG \n\n");
01996 
01997     return;
01998 }
01999 /*****************************************************************************/

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