00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <cpl.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include "midi_utils.h"
00040 #include "midi_pfits.h"
00041 #include "midi_dfs.h"
00042 #include "midiControl.h"
00043 #include "midiGlobal.h"
00044 #include "midiAppendPropertylist.h"
00045
00046
00047
00048
00049
00050 static int midi_fringe_all_create(cpl_plugin *) ;
00051 static int midi_fringe_all_exec(cpl_plugin *) ;
00052 static int midi_fringe_all_destroy(cpl_plugin *) ;
00053 static int midi_fringe_all(cpl_parameterlist *, cpl_frameset *) ;
00054
00055
00056
00057
00058
00059 static char midi_fringe_all_description[] =
00060 "This recipe is able to compute Uncalibrated Visibilities, Transfer Functions\n"
00061 "and Calibrated Visibilities for HIGH_SENS and SCI_PHOT input data.\n"
00062 "As the input frames and the output products of this recipe are manifold, the\n"
00063 "user should refer to the pipeline manual for a detailed description \n\n";
00064
00065
00066
00067
00068
00069
00078
00079 int cpl_plugin_get_info(cpl_pluginlist * list)
00080 {
00081 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00082 cpl_plugin * plugin = &recipe->interface ;
00083
00084 cpl_plugin_init(plugin,
00085 CPL_PLUGIN_API,
00086 MIDI_BINARY_VERSION,
00087 CPL_PLUGIN_TYPE_RECIPE,
00088 "midi_fringe_all",
00089 "Computes Visibilities and Transfer Functions",
00090 midi_fringe_all_description,
00091 "Armin Gabasch",
00092 PACKAGE_BUGREPORT,
00093 midi_get_license(),
00094 midi_fringe_all_create,
00095 midi_fringe_all_exec,
00096 midi_fringe_all_destroy) ;
00097
00098 cpl_pluginlist_append(list, plugin) ;
00099
00100 return 0;
00101 }
00102
00103
00111
00112 static int midi_fringe_all_create(cpl_plugin * plugin)
00113 {
00114 cpl_recipe * recipe ;
00115 cpl_parameter * p ;
00116
00117
00118 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00119 recipe = (cpl_recipe *)plugin ;
00120 else return -1 ;
00121
00122
00123 recipe->parameters = cpl_parameterlist_new() ;
00124
00125
00126
00127 p = cpl_parameter_new_value("midi.midi_fringe_all.checkSof",
00128 CPL_TYPE_BOOL, "Do homogeneity checks on the SOF ", "midi.midi_fringe_all", TRUE) ;
00129 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "checkSof") ;
00130 cpl_parameterlist_append(recipe->parameters, p) ;
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 return 0;
00142 }
00143
00144
00150
00151 static int midi_fringe_all_exec(cpl_plugin * plugin)
00152 {
00153 cpl_recipe * recipe ;
00154
00155
00156 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00157 recipe = (cpl_recipe *)plugin ;
00158 else return -1 ;
00159
00160 batchNumber=0;
00161 return midi_fringe_all(recipe->parameters, recipe->frames) ;
00162 }
00163
00164
00170
00171 static int midi_fringe_all_destroy(cpl_plugin * plugin)
00172 {
00173 cpl_recipe * recipe ;
00174
00175
00176 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00177 recipe = (cpl_recipe *)plugin ;
00178 else return -1 ;
00179
00180 cpl_parameterlist_delete(recipe->parameters) ;
00181 return 0 ;
00182 }
00183
00184
00191
00192 static int midi_fringe_all(
00193 cpl_parameterlist *parlist,
00194 cpl_frameset *frameset)
00195 {
00196
00197
00198
00199
00200 cpl_frame *current_frame;
00201 int error=0;
00202 FILE *sofPtr=NULL;
00203 int plotDuration;
00204 char * system_call=NULL;
00205
00206
00207
00208 cpl_ensure_code(midi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
00209 cpl_error_get_code());
00210
00211
00212
00213
00214
00215
00216 plotDuration = 0;
00217
00218 current_frame = cpl_frameset_get_first(frameset);
00219 sofPtr = fopen ("MIDI_sof.log", "w");
00220 while ( current_frame && sofPtr )
00221 {
00222 fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
00223 current_frame = cpl_frameset_get_next( frameset );
00224 }
00225 fclose (sofPtr);
00226 system("sort -o MIDI_sof.log MIDI_sof.log");
00227
00228 executeDataReduction (MIDI_CALIBTEMP, MIDI_MASKS, "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
00229
00230 if (error) return -1;
00231 remove ("MIDI_sof.log");
00232
00233
00234 if (strcmp (batchTemplate, "SCI_PHOT_CALIB") == 0){
00235 if (CPL_ERROR_NONE != appendPropertylist_table("MIDI_b1_spc.pro.fits", CPL_FRAME_TYPE_TABLE, "REDUCED_DISPERSED_SCIPHOT",frameset,parlist))
00236 {
00237 cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
00238 }
00239 }
00240
00241 if (strcmp (batchTemplate, "SCI_PHOT_CALIB") == 0){
00242 if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_spc.waf.fits", CPL_FRAME_TYPE_IMAGE, "WATERFALL",frameset,parlist))
00243 {
00244 cpl_msg_error(cpl_func,"Error in appendPropertylist");
00245 }
00246 }
00247
00248
00249 if (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0){
00250 if (CPL_ERROR_NONE != appendPropertylist_table("MIDI_b1_sps.pro.fits", CPL_FRAME_TYPE_TABLE, "REDUCED_DISPERSED_SCIPHOT",frameset,parlist))
00251 {
00252 cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
00253 }
00254 }
00255
00256 if (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0){
00257 if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_sps.waf.fits", CPL_FRAME_TYPE_IMAGE, "WATERFALL",frameset,parlist))
00258 {
00259 cpl_msg_error(cpl_func,"Error in appendPropertylist");
00260 }
00261 }
00262
00263 if (strcmp (batchTemplate, "SCI_PHOT_KAPPA") == 0){
00264 if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_spk.pro.fits", CPL_FRAME_TYPE_IMAGE, "KAPPA_MATRIX",frameset,parlist))
00265 {
00266 cpl_msg_error(cpl_func,"Error in appendPropertylist");
00267 }
00268
00269 }
00270
00271
00272 if (strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0){
00273 if (CPL_ERROR_NONE != appendPropertylist_table("MIDI_b1_hsc.pro.fits", CPL_FRAME_TYPE_TABLE, "REDUCED_DISPERSED",frameset,parlist))
00274 {
00275 cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
00276 }
00277 }
00278
00279 if (strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0){
00280 if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_hsc.waf.fits", CPL_FRAME_TYPE_IMAGE, "WATERFALL",frameset,parlist))
00281 {
00282 cpl_msg_error(cpl_func,"Error in appendPropertylist");
00283 }
00284 }
00285
00286
00287 if (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0){
00288 if (CPL_ERROR_NONE != appendPropertylist_table("MIDI_b1_hss.pro.fits", CPL_FRAME_TYPE_TABLE, "REDUCED_DISPERSED",frameset,parlist))
00289 {
00290 cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
00291 }
00292 }
00293
00294 if (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0){
00295 if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_hss.waf.fits", CPL_FRAME_TYPE_IMAGE, "WATERFALL",frameset,parlist))
00296 {
00297 cpl_msg_error(cpl_func,"Error in appendPropertylist");
00298 }
00299 }
00300
00301
00302
00303
00304 if (strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0){
00305
00306 struct plots plotfiles_lambda[] =
00307 {{"MIDI_b1_hsc.WaveCalibCombined.plt", "Lambda"},
00308 {"MIDI_b1_hsc.NormalizedUncalibVisCombined.plt", "Visibility"},
00309 {"MIDI_b1_hsc.NormalizedUncalibVisErrCombined.plt", "VisibilityErr"},
00310 {"MIDI_b1_hsc.PhotomADATA1.plt", "PhotomADATA1"},
00311 {"MIDI_b1_hsc.PhotomAErrDATA1.plt", "PhotomAErrDATA1"},
00312 {"MIDI_b1_hsc.PhotomADATA2.plt", "PhotomADATA2"},
00313 {"MIDI_b1_hsc.PhotomAErrDATA2.plt", "PhotomAErrDATA2"},
00314 {"MIDI_b1_hsc.PhotomBDATA1.plt", "PhotomBDATA1"},
00315 {"MIDI_b1_hsc.PhotomBErrDATA1.plt", "PhotomBErrDATA1"},
00316 {"MIDI_b1_hsc.PhotomBDATA2.plt", "PhotomBDATA2"},
00317 {"MIDI_b1_hsc.PhotomBErrDATA2.plt", "PhotomBErrDATA2"},
00318 {"MIDI_b1_hsc.MeanInterfCleanDATA1.plt", "MeanInterfDATA1"},
00319 {"MIDI_b1_hsc.MeanInterfCleanDATA2.plt", "MeanInterfDATA2"}};
00320 int dimen_lambda = sizeof(plotfiles_lambda)/sizeof(struct plots);
00321
00322 struct plots plotfiles_frames[] =
00323 {{"MIDI_b1_hsc.PhotomACleanDATA1.plt", "PhotomA_DATA1"},
00324 {"MIDI_b1_hsc.PhotomACleanDATA2.plt", "PhotomA_DATA2"},
00325 {"MIDI_b1_hsc.PhotomBCleanDATA1.plt", "PhotomB_DATA1"},
00326 {"MIDI_b1_hsc.PhotomBCleanDATA2.plt", "PhotomB_DATA2"}};
00327 int dimen_frames = sizeof(plotfiles_frames)/sizeof(struct plots);
00328
00329
00330 struct plots plotfiles_scans[] =
00331 {{"MIDI_b1_hsc.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
00332 int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
00333
00334
00335
00336
00337 if (CPL_ERROR_NONE != appendPropertylist_statistics("MIDI_b1_hsc.pro.fits","MIDI_b1_hsc.stat.fits",CPL_FRAME_TYPE_TABLE,"REDUCED_STAT_HS",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
00338 {
00339 cpl_msg_error(cpl_func,"Error in appending aditional files");
00340 }
00341
00342
00343 }
00344
00345
00346 if (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0){
00347
00348 struct plots plotfiles_lambda[] =
00349 {{"MIDI_b1_hss.WaveCalibCombined.plt", "Lambda"},
00350 {"MIDI_b1_hss.NormalizedUncalibVisCombined.plt", "Visibility"},
00351 {"MIDI_b1_hss.NormalizedUncalibVisErrCombined.plt", "VisibilityErr"},
00352 {"MIDI_b1_hss.PhotomADATA1.plt", "PhotomADATA1"},
00353 {"MIDI_b1_hss.PhotomAErrDATA1.plt", "PhotomAErrDATA1"},
00354 {"MIDI_b1_hss.PhotomADATA2.plt", "PhotomADATA2"},
00355 {"MIDI_b1_hss.PhotomAErrDATA2.plt", "PhotomAErrDATA2"},
00356 {"MIDI_b1_hss.PhotomBDATA1.plt", "PhotomBDATA1"},
00357 {"MIDI_b1_hss.PhotomBErrDATA1.plt", "PhotomBErrDATA1"},
00358 {"MIDI_b1_hss.PhotomBDATA2.plt", "PhotomBDATA2"},
00359 {"MIDI_b1_hss.PhotomBErrDATA2.plt", "PhotomBErrDATA2"},
00360 {"MIDI_b1_hss.MeanInterfCleanDATA1.plt", "MeanInterfDATA1"},
00361 {"MIDI_b1_hss.MeanInterfCleanDATA2.plt", "MeanInterfDATA2"}};
00362 int dimen_lambda = sizeof(plotfiles_lambda)/sizeof(struct plots);
00363
00364 struct plots plotfiles_frames[] =
00365 {{"MIDI_b1_hss.PhotomACleanDATA1.plt", "PhotomA_DATA1"},
00366 {"MIDI_b1_hss.PhotomACleanDATA2.plt", "PhotomA_DATA2"},
00367 {"MIDI_b1_hss.PhotomBCleanDATA1.plt", "PhotomB_DATA1"},
00368 {"MIDI_b1_hss.PhotomBCleanDATA2.plt", "PhotomB_DATA2"}};
00369 int dimen_frames = sizeof(plotfiles_frames)/sizeof(struct plots);
00370
00371 struct plots plotfiles_scans[] =
00372 {{"MIDI_b1_hss.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
00373 int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
00374
00375
00376
00377
00378 if (CPL_ERROR_NONE != appendPropertylist_statistics("MIDI_b1_hss.pro.fits","MIDI_b1_hss.stat.fits",CPL_FRAME_TYPE_TABLE,"REDUCED_STAT_HS",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
00379 {
00380 cpl_msg_error(cpl_func,"Error in appending aditional files");
00381 }
00382
00383
00384 }
00385
00386
00387
00388
00389 if (strcmp (batchTemplate, "SCI_PHOT_CALIB") == 0){
00390
00391 struct plots plotfiles_lambda[] =
00392 {{"MIDI_b1_spc.WaveCalibCombined.plt", "Lambda"},
00393 {"MIDI_b1_spc.NormalizedUncalibVisCombined.plt", "Visibility"},
00394 {"MIDI_b1_spc.NormalizedUncalibVisErrCombined.plt", "VisibilityErr"},
00395 {"MIDI_b1_spc.PhotomADATA1.plt", "PhotomADATA1"},
00396 {"MIDI_b1_spc.PhotomAErrDATA1.plt", "PhotomAErrDATA1"},
00397 {"MIDI_b1_spc.PhotomIDATA2.plt", "PhotomIDATA2"},
00398 {"MIDI_b1_spc.PhotomIErrDATA2.plt", "PhotomIErrDATA2"},
00399 {"MIDI_b1_spc.PhotomIDATA3.plt", "PhotomIDATA3"},
00400 {"MIDI_b1_spc.PhotomIErrDATA3.plt", "PhotomIErrDATA3"},
00401 {"MIDI_b1_spc.PhotomBDATA4.plt", "PhotomBDATA4"},
00402 {"MIDI_b1_spc.PhotomBErrDATA4.plt", "PhotomBErrDATA4"},
00403 {"MIDI_b1_spc.MeanInterfCleanDATA1.plt", "MeanInterfDATA1"},
00404 {"MIDI_b1_spc.MeanInterfCleanDATA2.plt", "MeanInterfDATA2"}};
00405 int dimen_lambda = sizeof(plotfiles_lambda)/sizeof(struct plots);
00406
00407 struct plots plotfiles_frames[] =
00408 {{"MIDI_b1_spc.PhotomACleanDATA1.plt", "PhotomA_DATA1"},
00409 {"MIDI_b1_spc.InterfCleanDATA2.plt", "PhotomI_DATA2"},
00410 {"MIDI_b1_spc.InterfCleanDATA3.plt", "PhotomI_DATA3"},
00411 {"MIDI_b1_spc.PhotomBCleanDATA4.plt", "PhotomB_DATA4"}};
00412 int dimen_frames = sizeof(plotfiles_frames)/sizeof(struct plots);
00413
00414
00415 struct plots plotfiles_scans[] =
00416 {{"MIDI_b1_spc.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
00417 int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
00418
00419
00420
00421
00422 if (CPL_ERROR_NONE != appendPropertylist_statistics("MIDI_b1_spc.pro.fits","MIDI_b1_spc.stat.fits",CPL_FRAME_TYPE_TABLE,"REDUCED_STAT_SP",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
00423 {
00424 cpl_msg_error(cpl_func,"Error in appending aditional files");
00425 }
00426
00427
00428 }
00429
00430 if (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0){
00431
00432 struct plots plotfiles_lambda[] =
00433 {{"MIDI_b1_sps.WaveCalibCombined.plt", "Lambda"},
00434 {"MIDI_b1_sps.NormalizedUncalibVisCombined.plt", "Visibility"},
00435 {"MIDI_b1_sps.NormalizedUncalibVisErrCombined.plt", "VisibilityErr"},
00436 {"MIDI_b1_sps.PhotomADATA1.plt", "PhotomADATA1"},
00437 {"MIDI_b1_sps.PhotomAErrDATA1.plt", "PhotomAErrDATA1"},
00438 {"MIDI_b1_sps.PhotomIDATA2.plt", "PhotomIDATA2"},
00439 {"MIDI_b1_sps.PhotomIErrDATA2.plt", "PhotomIErrDATA2"},
00440 {"MIDI_b1_sps.PhotomIDATA3.plt", "PhotomIDATA3"},
00441 {"MIDI_b1_sps.PhotomIErrDATA3.plt", "PhotomIErrDATA3"},
00442 {"MIDI_b1_sps.PhotomBDATA4.plt", "PhotomBDATA4"},
00443 {"MIDI_b1_sps.PhotomBErrDATA4.plt", "PhotomBErrDATA4"},
00444 {"MIDI_b1_sps.MeanInterfCleanDATA1.plt", "MeanInterfDATA1"},
00445 {"MIDI_b1_sps.MeanInterfCleanDATA2.plt", "MeanInterfDATA2"}};
00446 int dimen_lambda = sizeof(plotfiles_lambda)/sizeof(struct plots);
00447
00448 struct plots plotfiles_frames[] =
00449 {{"MIDI_b1_sps.PhotomACleanDATA1.plt", "PhotomA_DATA1"},
00450 {"MIDI_b1_sps.InterfCleanDATA2.plt", "PhotomI_DATA2"},
00451 {"MIDI_b1_sps.InterfCleanDATA3.plt", "PhotomI_DATA3"},
00452 {"MIDI_b1_sps.PhotomBCleanDATA4.plt", "PhotomB_DATA4"}};
00453 int dimen_frames = sizeof(plotfiles_frames)/sizeof(struct plots);
00454
00455
00456 struct plots plotfiles_scans[] =
00457 {{"MIDI_b1_sps.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
00458 int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
00459
00460
00461
00462
00463 if (CPL_ERROR_NONE != appendPropertylist_statistics("MIDI_b1_sps.pro.fits","MIDI_b1_sps.stat.fits",CPL_FRAME_TYPE_TABLE,"REDUCED_STAT_SP",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
00464 {
00465 cpl_msg_error(cpl_func,"Error in appending aditional files");
00466 }
00467
00468
00469 }
00470
00471
00472
00473 if (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0 || strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0){
00474
00475 system_call=cpl_sprintf("rm -f /tmp/MIDI_trf.fits");
00476 if (system(system_call)==0){
00477 cpl_msg_info(cpl_func, "Removing possible transfer function file /tmp/MIDI_trf.fits");
00478 cpl_msg_info(cpl_func,system_call);
00479 cpl_free(system_call);
00480 }
00481 }
00482
00483
00484
00485 if (cpl_error_get_code())
00486 return -1 ;
00487 else
00488 return 0 ;
00489 }