Debian Codegraph @

gui/XEchelle/libsrc/commands.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26
27 .VERSION
28 090825 last modif
29
30 ===========================================================================*/
31
32 #include <Xm/Xm.h>
33 #include <Xm/Text.h>
34 #include <Xm/ToggleB.h>
35 #include <UxLib.h>
36
37 #include <proto_xech.h>
38
39
40 extern int AppendDialogText(), StringToIndex(), CallbackList();
41 extern int AppendDialogTextNoWait();
42
43 extern void InitField(), ImageOpen(), ImageClose();
44
45
46 /* Extended Help Initialisations */
47
48 struct exthelp {
49
50 char comm[20];
51 char swid[30];
52 char text[5000];
53
54 } ehelp[] = {
55
56 {"ROTATE", "pb_search_plot2", "Spectra must be at standard orientation\n\
57 The wavelength must increase from left to right\n\
58 and from bottom to top."},
59
60 {"SEARCH", "pb_search_plot6",
61 "search for calibration lines in a wavelength calibration echelle \n\
62 frame in the space pixel-order. The positions the detected lines \n\
63 are stored in the auxiliary table line.tbl"},
64
65 {"CALIBR", "pb_calib_disper",
66
67 " 1. Presentation of the methods. \n\
68 \n\
69 The methods PAIR, ANGLE and TWO-D are interactive and \n\
70 use the command CENTER/MOMENT with option CURSOR to point the \n\
71 lines. It is recommended to beginners to read the \n\
72 related help and use this command before identify/echelle. \n\
73 The three methods can be used if the disperser is a grating. \n\
74 Only the method TWO-D can apply if the disperser is a grism. \n\
75 In case of initial misidentifications, methods PAIR and \n\
76 ANGLE invoke a wavelength calibration diagnosis (see Note 3). \n\
77 \n\
78 In interactive modes, one must first point all the positions \n\
79 to identify, then provide order number and wavelengths. \n\
80 \n\
81 In method PAIR, one must recognize two pairs of \n\
82 lines in overlapped regions of the spectrum and \n\
83 provide the absolute order number of the first \n\
84 pointed line and wavelengths for each of the two \n\
85 pairs. The geometry of the pairs provide the angle of \n\
86 orientation of the spectrum. \n\
87 \n\
88 In method ANGLE, one identify at least four \n\
89 lines anywhere and provide absolute order number of the \n\
90 first pointed line and the wavelengths of all lines. The \n\
91 angle of orientation of the spectrum is computed analytically. \n\
92 \n\
93 At the difference of PAIR and ANGLE which involve \n\
94 the echelle relation (product order by wavelength as \n\
95 a function of the x position), the method TWO-D \n\
96 fits from the beginning a bivariate polynomial to \n\
97 the identifications. Therefore, it requires more initial \n\
98 identifications than the above methods. The minimum number \n\
99 is given by (dc + 1)**2 + 1, where dc is the degree of \n\
100 the polynomial used to fit the dispersion relation. \n\
101 \n\
102 Method RESTART must be used only IMMEDIATELY AFTER the \n\
103 methods PAIR, ANGLE or TWO-D. It avoids the interactive \n\
104 pointing of the lines and enters the program at the step \n\
105 of the identifications. \n\
106 \n\
107 Method GUESS is not interactive and can be used after \n\
108 any calibration by an interactive method. The method GUESS \n\
109 requires the name of a previously saved echelle session, which \n\
110 process tables will be used to start automatically the \n\
111 lines identification. The shift between the two sets of \n\
112 calibration lines is estimated by cross-correlation, unless \n\
113 its value is provided (see parameter guess). \n\
114 \n\
115 Method ORDER allows to restart only the single-order \n\
116 solutions with a different parameter wlctol. "},
117
118 {"REBINS", "pb_search_plot17",
119 "Rebin extracted orders into linear wavelength steps. The \n\
120 frame is converted from the space pixel-order into the space \n\
121 wavelength-order"},
122
123 {"ORDERS", "pb_search_plot5",
124 "Search for order positions in a 2-D echelle spectrum. The positions \n\
125 of points located in order and in interorder space are stored \n\
126 in an auxiliary table, named order. The order definition by \n\
127 Hough transform is more automatic and requires for simple cases \n\
128 no parameters"},
129
130 {"BACKGR", "pb_search_plot1",
131 "Compute the background of the echelle raw spectrum in the \n\
132 sampling space pixel-pixel. This command requires the table \n\
133 Background values are estimated at reference positions \n\
134 between the orders and interpolated either by smoothing \n\
135 spline or bivariate polynomial interpolation. Commands \n\
136 SCAN/ECHELLE and SELECT/BACKGROUND can be used before."},
137
138 {"EXTRAS", "pb_search_plot18",
139 "Extract echelle orders. Position of the orders are defined \n\
140 in the auxiliary table order.tbl, generated by the methods \n\
141 STD, COMPLEMENT or HOUGH (panel Order Definition). The extraction \n\
142 can be performed in mode Average or Optimal"},
143
144 {"SKYBKG", "pb_search_plot20",
145 " 1. Definition of sky limits \n\
146 \n\
147 The limits of the sky window(s) are defined directly \n\
148 or interactively. 1 or 2 sky windows can be defined. \n\
149 A cross-order profile is plotted in the graphic window \n\
150 and the program expects two position clicked for 1 window \n\
151 and four position cliked for two windows. The position \n\
152 of the cross-order profile plotted is set automatically \n\
153 (POSSKY=AUTO), indicated numerically (POSSKY=order,column) \n\
154 or defined interactively by a click in the display window \n\
155 (POSSKY=CURSOR). The cross-order profile is plotted over \n\
156 one order width on each side (parameter half-width). \n\
157 \n\
158 2. Extraction of the sky and correction \n\
159 \n\
160 An extracted sky spectrum is provided, similar to extracted echelle spectra. \n\
161 This extracted can be subtracted from the extracted object spectrum for \n\
162 sky background correction. "},
163
164 {"FLAT", "pb_search_plot21",
165 " 1. Preparation of the flat-field \n\
166 \n\
167 a) optionally subtract background from flat-field image \n\
168 If the descriptor BACKGROUND exists in flat-field image, \n\
169 the background step will be skipped. \n\
170 The corrected image, i.e. the flat-field corrected \n\
171 from its background, is stored as [correct] \n\
172 \n\
173 b) compute an approximation to the blaze profile for the \n\
174 flat-field. The order-by-order blaze profiles are stored \n\
175 as [blaze] \n\
176 \n\
177 The output images are used for flat-field correction. \n\
178 \n\
179 The background is approximated by spline polynomials \n\
180 fitted to points located in the interorder space. \n\
181 These points are defined by the command DEFINE/ECHELLE \n\
182 Parameters can be defaulted to the current session values, \n\
183 as displayed by SHOW/ECHELLE. \n\
184 \n\
185 2. Flat-Field Correction \n\
186 \n\
187 The flat-field correction is performed in wavelength space during \n\
188 the reduction. "},
189
190 {"RESPON", "pb_search_plot22",
191 " Compute instrument response by comparing the extracted \n\
192 orders of the standard star to a table of fluxes."},
193
194 {"MERGER", "pb_search_plot29",
195 "Produces a 1-D spectrum, from the order by order file generated \n\
196 by the Resampling command"},
197
198 };
199
200 void GetExtendedHelp(w)
201 Widget w;
202 {
203 int i;
204
205 UxPopupInterface(UxFindSwidget("HelpShell"), no_grab);
206
207 for(i=0; i<10; i++) {
208 if (w == UxGetWidget(UxFindSwidget(ehelp[i].swid)))
209 UxPutText(UxFindSwidget("tx_extended_help"), ehelp[i].text);
210 }
211 }
212
213 void MidasCommand(sw)
214 Widget sw;
215
216 {
217 char command[100];
218
219 /* Scan Limits */
220 if (sw == UxGetWidget(UxFindSwidget("pb_search_search2"))) {
221 strcpy(command, "SCAN/ECHELLE ");
222 strcat(command, UxGetText(UxFindSwidget("tf_alpha7")));
223 strcat(command, " CURSOR");
224 AppendDialogText(command);
225 AppendDialogText("SYNCHRO/ECHELLE");
226 ImageOpen();
227 InitField(StringToIndex("tf_alpha2"));
228 InitField(StringToIndex("tf_alpha4"));
229 InitField(StringToIndex("tf_thres3"));
230 ImageClose();
231 }
232
233 /* Order Definition */
234 if (sw == UxGetWidget(UxFindSwidget("pb_search_search3"))) {
235 strcpy(command, "CALIBRATE/ECHELLE ? ? ORDER");
236 AppendDialogText(command);
237 AppendDialogText("SYNCHRO/ECHELLE");
238 ImageOpen();
239 InitField(StringToIndex("tf_thres1"));
240 InitField(StringToIndex("tf_thres5"));
241 ImageClose();
242 }
243
244 /* Load Echelle */
245 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot3"))) {
246 strcpy(command, "LOAD/ECHELLE");
247 AppendDialogTextNoWait(command);
248 }
249
250 /* Save Echelle */
251 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot4"))) {
252 strcpy(command, "SAVE/ECHELLE sess");
253 AppendDialogTextNoWait(command);
254 }
255
256 /* Arc Line Extraction and Search */
257 if (sw == UxGetWidget(UxFindSwidget("pb_search_search1"))) {
258 strcpy(command, "EXTRACT/ECHELLE {WLC} &e; SEARCH/ECHEL &e");
259 AppendDialogTextNoWait(command);
260 }
261
262 /* Load Search */
263 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot7"))) {
264 sprintf (command, "DISPLAY/ECHE {WLC} ; LOAD/SEARCH");
265 AppendDialogTextNoWait(command);
266 }
267
268 /* Search Save */
269 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot8"))) {
270 strcpy(command, "SAVE/ECHELLE sess");
271 AppendDialogTextNoWait(command);
272 }
273
274
275 /* WLC Calibration */
276 if (sw == UxGetWidget(UxFindSwidget("pb_calib_calibrate"))) {
277 strcpy(command, "IDENT/ECHELLE ");
278 AppendDialogTextNoWait(command);
279 }
280
281 /* Plot Residuals */
282 if (sw == UxGetWidget(UxFindSwidget("pb_calib_resid"))) {
283 sprintf (command, "PLOT/RESIDUALS");
284 AppendDialogTextNoWait(command);
285 }
286
287 /* Rebinned WLC */
288 if (sw == UxGetWidget(UxFindSwidget("pb_calib_spec"))) {
289 strcpy(command, "EXTRACT/ECHELLE {WLC} &w; REBIN/ECHELLE &w &r; DISPLAY/ECHELLE &r");
290 AppendDialogTextNoWait(command);
291 }
292
293 /* Background Panel : Subtract Background */
294 if (sw == UxGetWidget(UxFindSwidget("pb_search_search6"))) {
295 strcpy(command, "SUBTRACT/BACK ");
296 strcat(command, UxGetText(UxFindSwidget("tf_alpha17")));
297 strcat(command, " ");
298 strcat(command, UxGetText(UxFindSwidget("tf_alpha18")));
299 strcat(command, " ");
300 strcat(command, UxGetText(UxFindSwidget("tf_alpha19")));
301 AppendDialogTextNoWait(command);
302 }
303
304 /* Show Positions */
305 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot9"))) {
306 strcpy(command, "DISPLAY/ECHELLE ");
307 strcat(command, UxGetText(UxFindSwidget("tf_alpha17")));
308 strcat(command, " ; SET/ECHE BKGVISU = YES; LOAD/ECHELLE");
309 AppendDialogTextNoWait(command);
310 }
311
312 /* Select Positions */
313 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot10"))) {
314 strcpy(command, "SELECT/BACKGR ");
315 AppendDialogTextNoWait(command);
316 }
317
318 /* Plot Background */
319 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot12"))) {
320 sprintf(command, "GRAPH/SPEC; SET/GRAPH YAXIS=%s,%s;",
321 UxGetText(UxFindSwidget("tf_alpha21")), UxGetText(UxFindSwidget("tf_alpha20")));
322 strcat(command, "PLOT/COLUMN ");
323 strcat(command, UxGetText(UxFindSwidget("tf_alpha17")));
324 strcat(command, " @500 ; OVER/COLUMN ");
325 strcat(command, UxGetText(UxFindSwidget("tf_alpha18")));
326 strcat(command, " @500");
327 AppendDialogTextNoWait(command);
328 }
329
330 /* Extract Orders */
331 if (sw == UxGetWidget(UxFindSwidget("pb_search_search7"))) {
332 strcpy(command, "EXTRACT/ECHELLE ");
333 strcat(command, UxGetText(UxFindSwidget("tf_thres6")));
334 strcat(command, " ");
335 strcat(command, UxGetText(UxFindSwidget("tf_thres7")));
336 AppendDialogTextNoWait(command);
337 }
338
339 /* Plot Orders */
340 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot13"))) {
341 strcpy(command, "PLOT/ECHELLE ");
342 strcat(command, UxGetText(UxFindSwidget("tf_thres7")));
343 strcat(command, " 1,{echord(1)}");
344 AppendDialogTextNoWait(command);
345 }
346
347 /* Defines interactively the limits of the sky window */
348 if (sw == UxGetWidget(UxFindSwidget("pb_search_search8"))) {
349 strcpy(command, "DEFINE/SKY ");
350 strcat(command, UxGetText(UxFindSwidget("tf_thres9")));
351 if (XmToggleButtonGetState(UxGetWidget(UxFindSwidget("toggleButton16"))) == TRUE) strcat(command," 1 ");
352 else strcat(command, " 2 ");
353 strcat(command, " CURSOR");
354 AppendDialogText(command);
355 AppendDialogText("SYNCHRO/ECHELLE");
356 ImageOpen();
357 InitField(StringToIndex("tf_alpha22"));
358 InitField(StringToIndex("tf_alpha23"));
359 InitField(StringToIndex("tf_alpha24"));
360 InitField(StringToIndex("tf_alpha25"));
361 ImageClose();
362 }
363
364
365 /* Extract Sky */
366 if (sw == UxGetWidget(UxFindSwidget("pb_search_search9"))) {
367 strcpy(command, "EXTRACT/SKY ");
368 strcat(command, UxGetText(UxFindSwidget("tf_thres9")));
369 strcat(command, " ");
370 strcat(command, UxGetText(UxFindSwidget("tf_thres10")));
371 if (XmToggleButtonGetState(UxGetWidget(UxFindSwidget("toggleButton19"))) == TRUE) strcat(command," FILTER");
372 else strcat(command," AVERAGE");
373 AppendDialogTextNoWait(command);
374 }
375
376
377 /* Plot Sky Orders */
378 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot13"))) {
379 strcpy(command, "PLOT/ECHELLE ");
380 strcat(command, UxGetText(UxFindSwidget("tf_thres10")));
381 strcat(command, " 1,{echord(1)}");
382 AppendDialogTextNoWait(command);
383 }
384
385 /* Rebin Orders */
386 if (sw == UxGetWidget(UxFindSwidget("pb_rebin_rbr"))) {
387 strcpy(command, "REBIN/ECHELLE ");
388 strcat(command, UxGetText(UxFindSwidget("tf_rebstrt")));
389 strcat(command, " ");
390 strcat(command, UxGetText(UxFindSwidget("tf_rebend")));
391 AppendDialogTextNoWait(command);
392 }
393
394 /* Plot Rebinned Orders */
395 if (sw == UxGetWidget(UxFindSwidget("pb_rebin_plot"))) {
396 strcpy(command, "PLOT/ECHELLE ");
397 strcat(command, UxGetText(UxFindSwidget("tf_rebend")));
398 strcat(command, " 1,{echord(1)}");
399 AppendDialogTextNoWait(command);
400 }
401
402
403 /* Flat-Field Computation */
404 if (sw == UxGetWidget(UxFindSwidget("pb_search_search10"))) {
405 strcpy(command, "FLAT/ECHELLE ");
406 AppendDialogText(command);
407 AppendDialogText("SYNCHRO/ECHELLE");
408 ImageOpen();
409 InitField(StringToIndex("toggleButton2"));
410 ImageClose();
411 }
412
413 /* Plot Blaze Function */
414 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot24"))) {
415 strcpy(command, "PLOT/ECHELLE {BLAZE} 1,{ECHORD(1)}");
416 AppendDialogTextNoWait(command);
417 }
418
419
420 /* Chromatic Response */
421 if (sw == UxGetWidget(UxFindSwidget("pb_search_search12"))) {
422 strcpy(command, "RESPONSE/ECHELLE ");
423 AppendDialogTextNoWait(command);
424 }
425
426 /* Plot Blaze Function */
427 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot23"))) {
428 strcpy(command, "PLOT/ECHELLE {RESPONSE} 1,{ECHORD(1)}");
429 AppendDialogTextNoWait(command);
430 }
431
432
433 /* Merge Orders */
434 if (sw == UxGetWidget(UxFindSwidget("pb_search_search13"))) {
435 strcpy(command, "MERGE/ECHELLE ");
436 strcat(command, UxGetText(UxFindSwidget("tf_thres8")));
437 strcat(command, " ");
438 strcat(command, UxGetText(UxFindSwidget("tf_thres11")));
439 AppendDialogTextNoWait(command);
440 }
441
442 /* Plot Overlaps */
443 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot25"))) {
444 strcpy(command, "MERGE/ECHELLE ");
445 strcat(command, UxGetText(UxFindSwidget("tf_thres8")));
446 strcat(command, " ");
447 strcat(command, UxGetText(UxFindSwidget("tf_thres11")));
448 AppendDialogTextNoWait(command);
449 }
450
451 /* Plot Spectrum */
452 if (sw == UxGetWidget(UxFindSwidget("pb_search_plot28"))) {
453 strcpy(command, "SET/GRAPH; PLOT ");
454 strcat(command, UxGetText(UxFindSwidget("tf_thres11")));
455 AppendDialogTextNoWait(command);
456 }
457
458
459 /* Reduce Main Batch */
460 if (sw == UxGetWidget(UxFindSwidget("pb_main_batch"))) {
461 WGet_selection();
462 WProcess_table("EProcess.tbl");
463 sprintf(command,"EXECUTE/TABLE EProcess.tbl REDUCE/ECHELLE [:INPUT] [:OUTPUT]");
464 AppendDialogTextNoWait(command);
465 }
466
467
468 /* Rotate Main Batch */
469 if (sw == UxGetWidget(UxFindSwidget("pb_main_ident"))) {
470 if (WGet_selection() > 0) {
471 WProcess_table("EProcess.tbl");
472 sprintf(command,"EXECUTE/TABLE EProcess.tbl ROTATE/ECHELLE [:INPUT] [:OUTPUT]");
473 AppendDialogTextNoWait(command);
474 }
475 else
476 UxPutText(UxFindSwidget("shelp_main"), "*** No File Selected: No Action ***");
477 }
478
479 /* Load Orders Main Batch */
480 if (sw == UxGetWidget(UxFindSwidget("pb_main_batch1"))) {
481 if (WGet_selection() > 0) {
482 sprintf(command, "DISPLAY/ECHELLE %s; LOAD/ECHELLE", WGet_First());
483 AppendDialogTextNoWait(command);
484 }
485 else
486 UxPutText(UxFindSwidget("shelp_main"), "*** No File Selected: No Action ***");
487 }
488
489
490 /* Plot Spectrum Main Batch */
491 if (sw == UxGetWidget(UxFindSwidget("pb_main_batch2"))) {
492 strcpy(command, "SAVE/ECHELLE sess");
493 AppendDialogTextNoWait(command);
494 }
495
496 }
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518