Blame view

src/idl/dustemwrap_plot.pro 38.3 KB
9ded3be9   Ilyes Choubani   Display update. F...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
PRO dustemwrap_plot, p_dim,                           $
                     st=st,                           $
                     dustem_sed = dustem_sed,         $
                     SED_spec = SED_spec,             $
                     dustem_qsed = dustem_qsed,       $
                     Q_spec = Q_spec,                 $
                     dustem_used = dustem_used,       $
                     U_spec = U_spec,                 $
                     dustem_polsed = dustem_polsed,   $
                     P_spec = P_spec,                 $
                     dustem_polfrac = dustem_polfrac, $
                     SP_spec = SP_spec,               $
                     dustem_psi_em = dustem_psi_em,   $
                     PSI_spec = PSI_spec,             $
                     dustem_ext = dustem_ext,         $
                     EXT_spec = EXT_spec,             $
                     dustem_qext = dustem_qext,       $
                     QEXT_spec = QEXT_spec,           $
                     dustem_uext = dustem_uext,       $
                     UEXT_spec = UEXT_spec,           $
                     dustem_polext = dustem_polext,   $
                     POLEXT_spec = POLEXT_spec,       $
                     dustem_fpolext = dustem_fpolext, $
                     SPEXT_spec = SPEXT_spec,         $
                     dustem_psi_ext = dustem_psi_ext, $
                     PSIEXT_spec = PSIEXT_spec,       $
                     _extra=_extra,                   $
                     help=help
392ede91   Jean-Philippe Bernard   included an help ...
29
30
31

;+
; NAME:
133b7033   Annie Hughes   cosmetic changes ...
32
33
;    dustemwrap_plot
;
392ede91   Jean-Philippe Bernard   included an help ...
34
; PURPOSE:
133b7033   Annie Hughes   cosmetic changes ...
35
36
;    plots dustemwrap observed sed, predicted sed, predicted spectra for total intensity, polarization in emission and extinction
;
392ede91   Jean-Philippe Bernard   included an help ...
37
; CATEGORY:
133b7033   Annie Hughes   cosmetic changes ...
38
39
;    DustEMWrap, Distributed, Plotting, Mid-Level
;  
392ede91   Jean-Philippe Bernard   included an help ...
40
; CALLING SEQUENCE:
9ded3be9   Ilyes Choubani   Display update. F...
41
;    dustemwrap_plot,p_dim,st=st,dustem_sed=dustem_sed,SED_spec=SED_spec,dustem_qsed=dustem_qsed,Q_spec=Q_spec,dustem_used=dustem_used,U_spec=U_spec $
133b7033   Annie Hughes   cosmetic changes ...
42
43
44
45
46
;                  ,dustem_polsed,P_spec,dustem_polfrac,SP_spec,dustem_psi_em,PSI_spec $
;                  ,dustem_ext,EXT_spec,dustem_qext,QEXT_spec,dustem_uext,UEXT_spec $
;                  ,dustem_polext,POLEXT_spec,dustem_fpolext,SPEXT_spec,dustem_psi_ext,PSIEXT_spec $
;                  ,_extra=_extra 
;
392ede91   Jean-Philippe Bernard   included an help ...
47
48
; INPUTS:
;    p_dim
133b7033   Annie Hughes   cosmetic changes ...
49
;
392ede91   Jean-Philippe Bernard   included an help ...
50
; OPTIONAL INPUT PARAMETERS:
9ded3be9   Ilyes Choubani   Display update. F...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;    st             = dustem output structure 
;    dustem_sed     = dustem predicted SED
;    dustem_qsed    = dustem predicted StokesQ SED
;    dustem_used    = dustem predicted StokesU SED
;    dustem_polsed  = dustem predicted LargeP SED
;    dustem_polfrac = dustem predicted smallP SED  
;    dustem_psi_em  = dustem predicted PSI SED  
;    dustem_ext     = dustem predicted EXT
;    dustem_qext    = dustem predicted StokesQ EXT
;    dustem_uext    = dustem predicted StokesU EXT 
;    dustem_polext  = dustem predicted LargeP EXT
;    dustem_fpolext = dustem predicted smallP EXT
;    dustem_psi_ext = dustem prediced PSI EXT 
;    SED_spec       = dustem predicted total emission spectrum (total = all-grain)
;    Q_spec         = dustem precicted total StokesQ emission spectrum
;    U_spec         = dustem predicted total Stokes U emission spectrum
;    P_spec         = dustem predicted total LargeP emission spectrum
;    SP_spec        = dustem predicted total smallP emission spectrum 
;    PSI_spec       = dustem predicted total PSI emission spectrum
;    EXT_spec       = dustem predicted total extinction spectrum
;    QEXT_spec      = dustem predicted total StokesQ extinction spectrum
;    UEXT_spec      = dustem predicted total StokesU extinction spectrum
;    POLEXT_spec    = dustem predicted total LargeP extinction spectrum
;    SPEXT_spec     = dustem predicted total smallP extinction spectrum  
;    PSIEXT_spec    = dustem predicted total PSI extinction spectrum
133b7033   Annie Hughes   cosmetic changes ...
76
;
392ede91   Jean-Philippe Bernard   included an help ...
77
; OUTPUTS:
9ded3be9   Ilyes Choubani   Display update. F...
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;    dustem_sed     = dustem predicted SED
;    dustem_qsed    = dustem predicted StokesQ SED
;    dustem_used    = dustem predicted StokesU SED
;    dustem_polsed  = dustem predicted LargeP SED
;    dustem_polfrac = dustem predicted smallP SED  
;    dustem_psi_em  = dustem predicted PSI SED  
;    dustem_ext     = dustem predicted EXT
;    dustem_qext    = dustem predicted StokesQ EXT
;    dustem_uext    = dustem predicted StokesU EXT 
;    dustem_polext  = dustem predicted LargeP EXT
;    dustem_fpolext = dustem predicted smallP EXT
;    dustem_psi_ext = dustem prediced PSI EXT 
;    SED_spec       = dustem predicted total emission spectrum
;    Q_spec         = dustem precicted total StokesQ emission spectrum
;    U_spec         = dustem predicted total Stokes U emission spectrum
;    P_spec         = dustem predicted total LargeP emission spectrum
;    SP_spec        = dustem predicted total smallP emission spectrum 
;    PSI_spec       = dustem predicted total PSI emission spectrum
;    EXT_spec       = dustem predicted total extinction spectrum
;    QEXT_spec      = dustem predicted total StokesQ extinction spectrum
;    UEXT_spec      = dustem predicted total StokesU extinction spectrum
;    POLEXT_spec    = dustem predicted total LargeP extinction spectrum
;    SPEXT_spec     = dustem predicted total smallP extinction spectrum  
;    PSIEXT_spec    = dustem predicted total PSI extinction spectrum;
133b7033   Annie Hughes   cosmetic changes ...
102
;
392ede91   Jean-Philippe Bernard   included an help ...
103
104
; OPTIONAL OUTPUT PARAMETERS:
;    
392ede91   Jean-Philippe Bernard   included an help ...
105
106
; ACCEPTED KEY-WORDS:
;    help
133b7033   Annie Hughes   cosmetic changes ...
107
;
392ede91   Jean-Philippe Bernard   included an help ...
108
109
; COMMON BLOCKS:
;    None
133b7033   Annie Hughes   cosmetic changes ...
110
;
392ede91   Jean-Philippe Bernard   included an help ...
111
; SIDE EFFECTS:
133b7033   Annie Hughes   cosmetic changes ...
112
113
;    Generates plots!
;
392ede91   Jean-Philippe Bernard   included an help ...
114
115
116
; RESTRICTIONS:
;    The DustEM fortran code must be installed
;    The DustEMWrap IDL code must be installed
133b7033   Annie Hughes   cosmetic changes ...
117
;
392ede91   Jean-Philippe Bernard   included an help ...
118
119
; PROCEDURES AND SUBROUTINES USED:
;
133b7033   Annie Hughes   cosmetic changes ...
120
; EXAMPLES:
392ede91   Jean-Philippe Bernard   included an help ...
121
122
;    
; MODIFICATION HISTORY:
133b7033   Annie Hughes   cosmetic changes ...
123
;    Written by Ilyes Choubani 2022
392ede91   Jean-Philippe Bernard   included an help ...
124
;    Evolution details on the DustEMWrap gitlab.
133b7033   Annie Hughes   cosmetic changes ...
125
;    See http://dustemwrap.irap.omp.eu/ for FAQ and help.  
392ede91   Jean-Philippe Bernard   included an help ...
126
127
128
129
130
131
;-

IF keyword_set(help) THEN BEGIN
  doc_library,'dustemwrap_plot'
  goto,the_end
END
67bd858a   Ilyes Choubani   Replication of th...
132

9ded3be9   Ilyes Choubani   Display update. F...
133
;===========Making sure Plugins are activated 
2910e8ce   Ilyes Choubani   Draft version of ...
134
IF not keyword_set(st) THEN BEGIN
a73f6031   Ilyes Choubani   small corrections...
135
  dustem_activate_plugins,p_dim/(*(*!dustem_fit).param_init_values),st=st  ; 0/0 division case?
d8df0428   Ilyes Choubani   unfortunate merge...
136
ENDIF
d8df0428   Ilyes Choubani   unfortunate merge...
137

9ded3be9   Ilyes Choubani   Display update. F...
138
;===========Making sure the predicted dustem SEDs are set
d8df0428   Ilyes Choubani   unfortunate merge...
139
if not keyword_set(dustem_sed) and isa((*!dustem_data).sed) then begin ;better test?
afde94a3   Ilyes Choubani   general update
140
  
a73f6031   Ilyes Choubani   small corrections...
141
      dustem_sed = dustem_compute_sed(p_dim,st=st,SED_spec=SED_spec)
0496a3ac   Ilyes Choubani   Small corrections...
142
      if !run_pol and tag_exist(*!dustem_show,'qsed') && !run_lin then begin
dc1d037e   Ilyes Choubani   Small fixes to st...
143
          
a73f6031   Ilyes Choubani   small corrections...
144
          dustem_polsed = dustem_compute_polsed(p_dim,st=st,P_spec=P_spec,SP_spec=SP_spec,dustem_polfrac=dustem_polfrac)
54e685fc   Ilyes Choubani   small corrections...
145
146
147
          toto = dustem_compute_stokes(p_dim,st=st,Q_spec=Q_spec,U_spec=U_spec,PSI_spec=PSI_spec,dustem_psi_em=dustem_psi_em) 
          dustem_qsed = toto[0]
          dustem_used = toto[1]
dc1d037e   Ilyes Choubani   Small fixes to st...
148
          
07372e26   Ilyes Choubani   Corrected huge pl...
149
      endif         
d8df0428   Ilyes Choubani   unfortunate merge...
150
endif
dc1d037e   Ilyes Choubani   Small fixes to st...
151
  
9ded3be9   Ilyes Choubani   Display update. F...
152
;===========Making sure the predicted dustem EXTs are set
d8df0428   Ilyes Choubani   unfortunate merge...
153
if not keyword_set(dustem_ext) and isa((*!dustem_data).ext) then begin
a73f6031   Ilyes Choubani   small corrections...
154
      dustem_ext = dustem_compute_ext(p_dim,st=st,EXT_spec=EXT_spec)
fcb6eade   Ilyes Choubani   general update - ...
155
      
0496a3ac   Ilyes Choubani   Small corrections...
156
      if !run_pol and tag_exist(*!dustem_show,'qext') && !run_lin then begin ;any polarization tag (qsed,used,qext,usext,polfrac) can be used for this test
88872c38   Ilyes Choubani   small update. Cha...
157
                              
5ac0dfba   Jean-Philippe Bernard   removed sti= calls
158
          dustem_polext = dustem_compute_polext(p_dim,st=st,POLEXT_spec=POLEXT_spec,SPEXT_spec=SPEXT_spec,dustem_fpolext=dustem_fpolext)
54e685fc   Ilyes Choubani   small corrections...
159
160
161
          toto = dustem_compute_stokext(p_dim,st=st,QEXT_spec=QEXT_spec,UEXT_spec=UEXT_spec,PSIEXT_spec=PSIEXT_spec,dustem_psi_ext=dustem_psi_ext) 
          dustem_qext = toto[0]
          dustem_uext = toto[1]
dc1d037e   Ilyes Choubani   Small fixes to st...
162
      endif
d8df0428   Ilyes Choubani   unfortunate merge...
163
endif
dfc68a85   Ilyes Choubani   Fixed some plotti...
164

9ded3be9   Ilyes Choubani   Display update. F...
165
;===========We should call this something more adequate
a7d7a5d5   Jean-Philippe Bernard   cleaned the code....
166
167
168
169
170
mouchard=*!iteration_mouchard
new_mouchard=mouchard[0]
new_mouchard.iteration=!dustem_iter.act
new_mouchard.chi2=(*!dustem_fit).chi2
new_mouchard.rchi2=(*!dustem_fit).rchi2
a7d7a5d5   Jean-Philippe Bernard   cleaned the code....
171
172
mouchard=[mouchard,new_mouchard]
!iteration_mouchard=ptr_new(mouchard)
2910e8ce   Ilyes Choubani   Draft version of ...
173

2910e8ce   Ilyes Choubani   Draft version of ...
174

9ded3be9   Ilyes Choubani   Display update. F...
175
176
177
;===========Initializing tests
test_sed = isa((*!dustem_data).sed) 
test_ext = isa((*!dustem_data).ext)
0496a3ac   Ilyes Choubani   Small corrections...
178

9ded3be9   Ilyes Choubani   Display update. F...
179
180
;===========Bunch of tests that are not important now but that
;might be in future releases. To adjust the layout of the dashboard for instance
b5314324   Ilyes Choubani   updating the plot...
181
if !run_pol then begin
0496a3ac   Ilyes Choubani   Small corrections...
182
    if tag_exist(*!dustem_show,'qsed') then begin ;testing to account for the fact that the user can activate the !run_pol keyword without knowing
9ded3be9   Ilyes Choubani   Display update. F...
183
    ;ie: using a dust model with polarization w/o polarization data present...
0496a3ac   Ilyes Choubani   Small corrections...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
        test_polsed = isa((*!dustem_show).polsed)
        test_polfrac = isa((*!dustem_show).polfrac)
        test_qsed = isa((*!dustem_show).qsed)
        test_used = isa((*!dustem_show).used)
        test_psi_em = isa((*!dustem_show).psi_em)
    endif
    
    if tag_exist(*!dustem_show,'qext') then begin
        test_polext = isa((*!dustem_show).polext)
        test_psi_ext = isa((*!dustem_show).psi_ext)
        test_fpolext = isa((*!dustem_show).fpolext)
        test_qext = isa((*!dustem_show).qext)
        test_uext = isa((*!dustem_show).uext)
    endif
    
    if tag_exist(*!dustem_show,'qsed') then test_m = test_sed or test_polsed $
                                                  or test_polfrac or test_qsed $
                                                  or test_used or test_psi_em
    if tag_exist(*!dustem_show,'qext') then test_x = test_ext or test_polext $
                                                  or test_fpolext or test_qext $
                                                  or test_uext or test_psi_ext
                                                  
    if ~tag_exist(*!dustem_show,'qsed') then test_m = test_sed
    if ~tag_exist(*!dustem_show,'qext') then test_x = test_ext 
                                        
b5314324   Ilyes Choubani   updating the plot...
209
210
211
212
endif else begin
    test_m = test_sed 
    test_x = test_ext 
endelse
18e4331f   Ilyes Choubani   general update (f...
213

b5314324   Ilyes Choubani   updating the plot...
214
n_plgns = n_tags(*!dustem_plugin)
2910e8ce   Ilyes Choubani   Draft version of ...
215

5f04fa07   Ilyes Choubani   general update
216
217
218
219
frmt0='(A36)'
frmt1='(1E10.2)'
frmt2='(10F10.2)'

9ded3be9   Ilyes Choubani   Display update. F...
220
221
222
223
;===========Loops over the _extra structure and retrieves 
;the keywords pertaining to each data set.
;It places them in a system variable that is 
;always refreshed (@ each call). 
0496a3ac   Ilyes Choubani   Small corrections...
224
dustem_set_plot_range,test_sed, test_ext,_extra= _extra
25140f99   Ilyes Choubani   debugging in plot...
225

9ded3be9   Ilyes Choubani   Display update. F...
226
227
;===========Keeping track of the command indices to adress the different datasets
;Doing this manually because I don't see another way.
2910e8ce   Ilyes Choubani   Draft version of ...
228
229
cmdind_m = 0 ;for emission
cmdind_x = 0 ;for extinction
5f04fa07   Ilyes Choubani   general update
230
231
cmdind_prms = 0 ;for parameters
cmdind_plgns = 0 ;for plugins
2910e8ce   Ilyes Choubani   Draft version of ...
232

9ded3be9   Ilyes Choubani   Display update. F...
233
234
;===========Keeping track of the windows' indices
;-emission and extinction-
2910e8ce   Ilyes Choubani   Draft version of ...
235
236
237
iswinsed = !dustemcgwin_id.sed EQ la_undef()
iswinext = !dustemcgwin_id.ext EQ la_undef()

9ded3be9   Ilyes Choubani   Display update. F...
238
239
;===========Keeping track of the windows' indices
;-parameters and plugins-
5f04fa07   Ilyes Choubani   general update
240
241
242
iswinprms = !dustemcgwin_id.prms EQ la_undef()
iswinplgns = !dustemcgwin_id.plgns EQ la_undef()

9ded3be9   Ilyes Choubani   Display update. F...
243
;===========Retrieving some data relevant to the plotting
5f04fa07   Ilyes Choubani   general update
244
if isa((*!dustem_fit).current_param_errors) then begin
9ded3be9   Ilyes Choubani   Display update. F...
245
    errors = (*(*!dustem_fit).current_param_errors) ;* (*(*!dustem_fit).param_init_values) ;multiplied internally in dustem_mpfit. Should maybe be changed.
5f04fa07   Ilyes Choubani   general update
246
endif else begin
dfc68a85   Ilyes Choubani   Fixed some plotti...
247
    errors = (*(*!dustem_fit).param_init_values)*0.;+la_undef();Initialized to 0 instead of la_undef() 
5f04fa07   Ilyes Choubani   general update
248
249
250
251
252
253
254
255
256
257
258
259
260
261
ENDELSE 

if isa((*!dustem_fit).chi2) then begin
    chi2 = (*!dustem_fit).chi2    
endif else begin
    chi2 = la_undef();maybe not the best initialization 
endelse 

if isa((*!dustem_fit).rchi2) then begin
    rchi2 = (*!dustem_fit).rchi2    
endif else begin
    rchi2 = la_undef();maybe not the best initialization 
endelse 

88872c38   Ilyes Choubani   small update. Cha...
262
263
;changing tag_exist() by isa() because the user can mistakenly activate the !run_pol keyword

52a3c8dc   Jean-Philippe Bernard   mise a jour
264
265
266
267
268
269
;===== commented out by Annie and JP on 17 march 2023
;If !run_pol THEN BEGIN
;    If tag_exist(*!dustem_show,'QSED') THEN BEGIN
;        IF ~isa((*!dustem_data).qsed) THEN !run_pol=0 
;    ENDIF ELSE !run_pol = 0
;ENDIF
88872c38   Ilyes Choubani   small update. Cha...
270

9ded3be9   Ilyes Choubani   Display update. F...
271
;===========Window positionning parameters
0496a3ac   Ilyes Choubani   Small corrections...
272
if !run_pol and tag_exist(*!dustem_show,'qsed') then BEGIN ;qsed tag is sufficient for the test
dba085c0   Jean-Philippe Bernard   fixed windows pos...
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
    wdelta_x=60
    main_wxsize=910
    main_wysize=658

    param_wxpos=main_wxsize+wdelta_x
    param_wypos=15
    param_wxsize=350
    param_wysize=200

    plugin_wxpos=main_wxsize+wdelta_x
    plugin_wypos=300
    plugin_wxsize=350
    plugin_wysize=200
ENDIF ELSE BEGIN
    wdelta_x=60
    main_wxsize=640  ;default of cgwindow
    main_wysize=512  ;default of cgwindow

    param_wxpos=main_wxsize+wdelta_x;700
    param_wypos=15
    param_wxsize=350
    param_wysize=200

    plugin_wxpos=main_wxsize+wdelta_x;700
    plugin_wypos=300
    plugin_wxsize=350
    plugin_wysize=200
ENDELSE

9ded3be9   Ilyes Choubani   Display update. F...
302
;===========EMISSION WINDOW
2910e8ce   Ilyes Choubani   Draft version of ...
303
if test_m then begin
2910e8ce   Ilyes Choubani   Draft version of ...
304
    
9ded3be9   Ilyes Choubani   Display update. F...
305
306
    ;===========If window not set, create it and plot data anew
    if iswinsed then begin    
dfc68a85   Ilyes Choubani   Fixed some plotti...
307
        
18e47096   Ilyes Choubani   corrections for e...
308
309
        cgwindow,wxsize=main_wxsize,wysize=main_wysize,wtitle='DUSTEMWRAP '+!dustem_version.version+' (EMISSION)' 
                                                        
9ded3be9   Ilyes Choubani   Display update. F...
310
        winid_m = cgquery(dimensions=dim_m,/current) ;dimension is not used...
2910e8ce   Ilyes Choubani   Draft version of ...
311
312
        !dustemcgwin_id.sed = winid_m
        
5f04fa07   Ilyes Choubani   general update
313
        cgcontrol, winid_m, execute=0
9ded3be9   Ilyes Choubani   Display update. F...
314
315
       
        ;===========Display Model string
5f04fa07   Ilyes Choubani   general update
316
317
        xxpos = 0.015
        yypos = 0.97
abebbdf3   Ilyes Choubani   General update: A...
318
        cgtext, xxpos, yypos,'Model : '+!dustem_model,color=0,/normal,charsize = 1.2,/addcmd ;& cmdind_m+=1 This is the first command in the window
9ded3be9   Ilyes Choubani   Display update. F...
319
        ;===========Display Hydrogen Column Density
5f04fa07   Ilyes Choubani   general update
320
        yypos = 0.95
abebbdf3   Ilyes Choubani   General update: A...
321
        cgtext, xxpos, yypos,textoidl('N_{H}')+textoidl(' (H/cm^2) : ')+strmid(string(*!dustem_HCD,format='(1E10.2)'),2),color=0,/normal,charsize = 1.2,/addcmd & cmdind_m+=1
40597848   Ilyes Choubani   Plotting of numbe...
322
        
9ded3be9   Ilyes Choubani   Display update. F...
323
        ;===========Displaying current iteration
e08591fe   Ilyes Choubani   To Annie: removal...
324
        xxpos = 0.015 
40597848   Ilyes Choubani   Plotting of numbe...
325
326
        yypos = 0.015
        
9ded3be9   Ilyes Choubani   Display update. F...
327
328
        ;FROZEN part that does not change in-between displays.
        cgtext, xxpos, yypos,'Iteration : ',color=0,/normal,charsize = 1.25,/addcmd & cmdind_m+=1
e08591fe   Ilyes Choubani   To Annie: removal...
329
330
331
        ;generating the equivalent escape string for the frozen part of the string
        esc_txt = strjoin(replicate(' ', strlen('Iteration : ')))
         
9ded3be9   Ilyes Choubani   Display update. F...
332
        ;Refreshed part that changes in-between iterations/displays.
e08591fe   Ilyes Choubani   To Annie: removal...
333
334
        cgtext, xxpos, yypos,esc_txt+strtrim(!dustem_iter.act,2),color=0,/normal,charsize = 1.25,/addcmd & cmdind_m+=1
        
9ded3be9   Ilyes Choubani   Display update. F...
335
        ;
40597848   Ilyes Choubani   Plotting of numbe...
336
337
        !dustemcgwin_ncmds.runs.pl = cmdind_m

e08591fe   Ilyes Choubani   To Annie: removal...
338
339
        ;#plotting of (mostly) fixed data for rchi2
          
5f04fa07   Ilyes Choubani   general update
340
        yypos = 0.97
e08591fe   Ilyes Choubani   To Annie: removal...
341
342
343
344
345
          
        ;#Displaying fixed part
        ;replacing the chi2 value (refreshed part of the string) by spaces
        esc_txt = strjoin(replicate(' ', strlen(strtrim(string(chi2,format=frmt2),2))))
        cgtext, 0.985, yypos,textoidl('\chi^{2} :  ')+esc_txt,color=0,/normal,charsize = 1.0,alignment=1.0,/addcmd & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
346
        
5f04fa07   Ilyes Choubani   general update
347
        
e08591fe   Ilyes Choubani   To Annie: removal...
348
349
350
351
        ;#Displaying refreshed part (first run . This is the command that will be replaced)
        ;generating the equivalent escape string for the frozen part of the string
        esc_txt = strjoin(replicate(' ', strlen(textoidl('\chi^{2} :  '))))
        cgtext, 0.985, yypos,esc_txt+strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0,alignment=1.0,/addcmd & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
352
353
354
       
        ;saving the command id to replace it
        !dustemcgwin_ncmds.chi2.pl = cmdind_m
5f04fa07   Ilyes Choubani   general update
355
356
357
        
        ;plotting of (mostly) fixed data for rchi2
        
5f04fa07   Ilyes Choubani   general update
358
359
        yypos = 0.95
        
e08591fe   Ilyes Choubani   To Annie: removal...
360
361
362
        ;#Displaying fixed part
        ;replacing the rchi2 value (refreshed part of the string) by spaces
        esc_txt = strjoin(replicate(' ', strlen(strtrim(string(rchi2,format=frmt2),2))))
9ded3be9   Ilyes Choubani   Display update. F...
363
364
365
        txt = textoidl('r_{\chi^{2}} : ')
        
        cgtext, 0.985, yypos,txt+esc_txt,color=0,/normal,charsize = 1.35,alignment=1.0,/addcmd & cmdind_m+=1
e08591fe   Ilyes Choubani   To Annie: removal...
366
367
368
369
        
        ;#Displaying refreshed part (first run . This is the command that will be replaced)
        ;generating the equivalent escape string for the frozen part of the string
        esc_txt = strjoin(replicate(' ', strlen(textoidl('r_{\chi^{2}} : '))))
9ded3be9   Ilyes Choubani   Display update. F...
370
371
        txt = strtrim(string(rchi2,format=frmt2),2)
        cgtext, 0.985, yypos,esc_txt+txt,color=0,/normal,charsize = 1.0,alignment=1.0,/addcmd & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
372
373
        ;saving the command id to replace it
        !dustemcgwin_ncmds.rchi2.pl = cmdind_m
e08591fe   Ilyes Choubani   To Annie: removal...
374
375
376

        ;Saving the title for the emission plot
        tit=!dustem_plot_range.title_m
5f04fa07   Ilyes Choubani   general update
377
        
9ded3be9   Ilyes Choubani   Display update. F...
378
        ;See if JP and Annie don't like plotting this on the bottom of the window
0496a3ac   Ilyes Choubani   Small corrections...
379
        cgtext, 0.5, 0.96,tit,color=0,/normal,charsize = 1.6,alignment=0.5,/addcmd & cmdind_m+=1
e08591fe   Ilyes Choubani   To Annie: removal...
380
        cgtext, 0.5, 0.015,'(RUNNING)',color=0,/normal,charsize = 1.6,/addcmd,alignment=0.5 & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
381
382
383
        
        !dustemcgwin_ncmds.pltit.pl = cmdind_m
        
5cb00808   Jean-Philippe Bernard   added some commen...
384
    endif else begin     ;This is when the cgwindow exists already
5f04fa07   Ilyes Choubani   general update
385
386
387
        
        winid_m = !dustemcgwin_id.sed
        cgcontrol, winid_m, execute=0
9ded3be9   Ilyes Choubani   Display update. F...
388
        cgset, winid_m ;apparently specifying the window index in the above command isn't enough. This might be because of the use of cgcontrol
5f04fa07   Ilyes Choubani   general update
389
390
        
        ;Refreshing chi2 data: 
18e47096   Ilyes Choubani   corrections for e...
391
        cmdind_m = !dustemcgwin_ncmds.chi2.pl
e08591fe   Ilyes Choubani   To Annie: removal...
392
        xxpos = 0.985;1 - !dustemcgwin_ncmds.chi2.txtwdth - 0.03  
5f04fa07   Ilyes Choubani   general update
393
        yypos = 0.97
9ded3be9   Ilyes Choubani   Display update. F...
394
395
        ;using cgwindow's weakness to fix the ps output.
        if !dustem_end ne 0 then esc_txt = textoidl('\chi^{2} :  ') else esc_txt = strjoin(replicate(' ', strlen(textoidl('\chi^{2} :  '))))
18e47096   Ilyes Choubani   corrections for e...
396
397
        cgwindow,'cgtext', xxpos , yypos,esc_txt+strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_m, winid=winid_m ;& cmdind_m+=1
        if !dustem_end ne 0 then  cgwindow,'cgtext', xxpos , yypos,'',color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_m-1, winid=winid_m ;& cmdind_m+=1
9ded3be9   Ilyes Choubani   Display update. F...
398
         ;Refreshing number of runs data: 
5f04fa07   Ilyes Choubani   general update
399
        ;Refreshing rchi2 data: 
18e47096   Ilyes Choubani   corrections for e...
400
        cmdind_m = !dustemcgwin_ncmds.rchi2.pl
e08591fe   Ilyes Choubani   To Annie: removal...
401
        xxpos = 0.985;1 - !dustemcgwin_ncmds.rchi2.txtwdth - 0.03  
5f04fa07   Ilyes Choubani   general update
402
        yypos = 0.95
9ded3be9   Ilyes Choubani   Display update. F...
403
404
        ;using cgwindow's weakness to fix the ps output.        
        if !dustem_end ne 0 then esc_txt = textoidl('r_{\chi^{2}} : ') else esc_txt = strjoin(replicate(' ', strlen(textoidl('r_{\chi^{2}} : '))))
18e47096   Ilyes Choubani   corrections for e...
405
406
        cgwindow,'cgtext', xxpos , yypos,esc_txt+strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_m, winid=winid_m ;& cmdind_m+=1
        if !dustem_end ne 0 then  cgwindow,'cgtext', xxpos , yypos,'',color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_m-1, winid=winid_m ;& cmdind_m+=1
40597848   Ilyes Choubani   Plotting of numbe...
407
        ;Refreshing number of runs data: 
18e47096   Ilyes Choubani   corrections for e...
408
        cmdind_m = !dustemcgwin_ncmds.runs.pl
e08591fe   Ilyes Choubani   To Annie: removal...
409
        xxpos = 0.015;0.03 + !dustemcgwin_ncmds.runs.txtwdth*1.35  ;(because of charsize)
40597848   Ilyes Choubani   Plotting of numbe...
410
        yypos = 0.015
e08591fe   Ilyes Choubani   To Annie: removal...
411
        esc_txt = strjoin(replicate(' ', strlen('Iteration : ')))
9ded3be9   Ilyes Choubani   Display update. F...
412
413
414
415
        if !dustem_iter.act eq 0 then txt = esc_txt+'Fit failed. '  else begin
            if !dustem_end ne 0 then esc_txt='Iteration : '
            txt = esc_txt+strtrim(!dustem_iter.act,2)
        endelse
18e47096   Ilyes Choubani   corrections for e...
416
        cgwindow,'cgtext', xxpos , yypos,txt,color=0,/normal,charsize = 1.25,/replacecmd,cmdindex=cmdind_m, winid=winid_m ;& cmdind_m+=1
40597848   Ilyes Choubani   Plotting of numbe...
417
        
dfc68a85   Ilyes Choubani   Fixed some plotti...
418
419
        ;update of the title here ?
        
0496a3ac   Ilyes Choubani   Small corrections...
420
        if !dustem_end EQ 1 then begin  ;IF & ONLY IF we're at the last iteration (refreshing title)
0496a3ac   Ilyes Choubani   Small corrections...
421
            ;tit=!dustem_plot_range.title_m
18e47096   Ilyes Choubani   corrections for e...
422
            cmdind_m = !dustemcgwin_ncmds.pltit.pl
dfc68a85   Ilyes Choubani   Fixed some plotti...
423
            
0496a3ac   Ilyes Choubani   Small corrections...
424
425
            xxpos = 0.5;!dustemcgwin_ncmds.pltit.txtwdth_m
            yypos = 0.015
dfc68a85   Ilyes Choubani   Fixed some plotti...
426
        
18e47096   Ilyes Choubani   corrections for e...
427
            cgwindow,'cgtext', xxpos , yypos,'(Final Run)',alignment=0.5,color=0,/normal,charsize = 1.6,/replacecmd,cmdindex=cmdind_m, winid=winid_m  
dfc68a85   Ilyes Choubani   Fixed some plotti...
428
429
        
        endif
25140f99   Ilyes Choubani   debugging in plot...
430
        
0496a3ac   Ilyes Choubani   Small corrections...
431
        if !dustem_end EQ -1 then begin ;Adjusting title for subsequent displays to the end of the fit 
25140f99   Ilyes Choubani   debugging in plot...
432
433
434
435
436
437
438
439
            
            tit=!dustem_plot_range.title_m
            cmdind_m = !dustemcgwin_ncmds.pltit.pl
            
            xxpos = 0.5
            yypos =0.96
                
            cgwindow,'cgtext', xxpos , yypos,tit,color=0,/normal,charsize = 1.6,/replacecmd,alignment=0.5,cmdindex=cmdind_m-1, winid=winid_m
e08591fe   Ilyes Choubani   To Annie: removal...
440
            ;this following/below call is needed so that the string disappears (string is '(FINAL RUN)' or '(RUNNING)')
0496a3ac   Ilyes Choubani   Small corrections...
441
442
            ;just to be safe
            yypos = 0.015
25140f99   Ilyes Choubani   debugging in plot...
443
444
            cgwindow,'cgtext', xxpos, yypos,'',color=0,/normal,charsize = 1.6,/replacecmd,alignment=0.5,cmdindex=cmdind_m, winid=winid_m
        ENDIF
0496a3ac   Ilyes Choubani   Small corrections...
445
       
5f04fa07   Ilyes Choubani   general update
446
    endelse
9ded3be9   Ilyes Choubani   Display update. F...
447
448
449
 
    ;This block needs to be replicated inside the dustem_plot_dataset routine
    
18e47096   Ilyes Choubani   corrections for e...
450
    if !run_pol and tag_exist(*!dustem_show,'qsed') then begin
2910e8ce   Ilyes Choubani   Draft version of ...
451
452
        
        ;position arrays for plot and normalized graph
af5bca1f   Ilyes Choubani   general update
453
        
af5bca1f   Ilyes Choubani   general update
454
        ;THIS IS HARD-CODED IN A VERY SILLY WAY
2910e8ce   Ilyes Choubani   Draft version of ...
455
456
457
        
        p_sed = [0.05,0.67,0.475,0.90]
        p_psed = [0.525,0.67,0.95,0.90]
af5bca1f   Ilyes Choubani   general update
458
        p_spsed = [0.05,0.375,0.475,0.575]
18e4331f   Ilyes Choubani   general update (f...
459
        p_psised = [0.525,0.375,0.95,0.575]
5f04fa07   Ilyes Choubani   general update
460
        p_qsed = [0.05,0.12,0.475,0.35]  
18e4331f   Ilyes Choubani   general update (f...
461
462
        p_used = [0.525,0.12,0.95,0.35]
        
2910e8ce   Ilyes Choubani   Draft version of ...
463
        np_sed = [0.05,0.60,0.475,0.67]
18e4331f   Ilyes Choubani   general update (f...
464
465
466
        np_psed = [0.525,0.60,0.95,0.67]
        np_qsed = [0.05,0.05,0.475,0.12] 
        np_used = [0.525,0.05,0.95,0.12]
af5bca1f   Ilyes Choubani   general update
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
        
        p_sed[1]+= 0.0125 & p_sed[3]+= 0.0125 
        p_psed[1]+= 0.0125 & p_psed[3]+= 0.0125
        p_spsed[1]+= 0.0125 & p_spsed[3]+= 0.0125
        p_psised[1]+= 0.0125 & p_psised[3]+= 0.0125
        p_qsed[1]+= 0.0125 & p_qsed[3]+= 0.0125
        p_used[1]+= 0.0125 & p_used[3]+= 0.0125
        
        np_sed[1]+= 0.0125 & np_sed[3]+= 0.0125 
        np_psed[1]+= 0.0125 & np_psed[3]+= 0.0125
        np_qsed[1]+= 0.0125 & np_qsed[3]+= 0.0125
        np_used[1]+= 0.0125 & np_used[3]+= 0.0125
        
        
          
2910e8ce   Ilyes Choubani   Draft version of ...
482
    endif else begin
0496a3ac   Ilyes Choubani   Small corrections...
483
484
        p_sed  = [0.07,0.30,0.97,0.88]
        np_sed = [0.07,0.12,0.97,0.30]
c8368c6e   Ilyes Choubani   updating plotting...
485
    
2910e8ce   Ilyes Choubani   Draft version of ...
486
487
    endelse

0496a3ac   Ilyes Choubani   Small corrections...
488
    plotsym,0,/fill 
18e4331f   Ilyes Choubani   general update (f...
489
    
0496a3ac   Ilyes Choubani   Small corrections...
490
    
9ded3be9   Ilyes Choubani   Display update. F...
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
    if !run_pol and tag_exist(*!dustem_show,'qsed') then begin
        ;This part can be adjusted for future releases if the user wants to plot 
        ;specific datasets 
        
        ;lists because elements have different dimensions and/or we want entire arrays as elements
        dustem_interp = list(dustem_sed,dustem_polfrac,dustem_qsed,dustem_used,dustem_psi_em,dustem_polsed) ;DustEmWrap SED predictions
        dustem_spec = list(SED_spec,SP_spec,Q_spec,U_spec,PSI_spec,P_spec) ;DustEM spectra predictions
        extra_spec = list(0,SED_spec,0,0,0,0) ;extra spectra that the dataset needs in order to be plotted. 
        ;This (extra_spec use) actually should not be generalized since the only case we need an extra spectrum is when plotting the polarization fraction.
        position = list(list(p_sed,np_sed),list(p_spsed),list(p_qsed,np_qsed),list(p_used,np_used),list(p_psised),list(p_psed,np_psed))
        
        ;these don't have to be lists
        datasets = ['SED','POLFRAC','QSED','USED','PSI_EM','POLSED']
        ;but these can be combined using a list but we're leaving it as is for the moment...
        positiveonly = [0,0,1,1,0,0] ;used for q and u
        negativeonly = [0,0,1,1,0,0] ;used for q and u
    ENDIF ELSE BEGIN
    
        dustem_interp = list(dustem_sed) ;DustEmWrap SED predictions . 
        dustem_spec = list(SED_spec) ;DustEM spectra predictions
88872c38   Ilyes Choubani   small update. Cha...
511
        position = list(p_sed,np_sed)  ;list(list(p_sed,np_sed)) ; I think I need this ...
9ded3be9   Ilyes Choubani   Display update. F...
512
513
514
515
516
517
518
519
520
521
522
523
524
525
        ;position_n =list(np_sed) 
        datasets = ['SED']
        ;replace by one keyword?
        positiveonly=[0] ;kept it for completeness. Also this loop reminds me that JP also wants the user to be able to display one dataset. 
        negativeonly=[0]
    ENDELSE
    
    if  ~iswinsed then begin ;PLOTTING OF REFRESHED DATA
         
         ;REFRESHING DATA  
         cmdind_m = !dustemcgwin_ncmds.sed.pl
         cgwindow,'dustem_plot_dataset', st, dustem_interp,dustem_spec,extra_spec=extra_spec,dataset=datasets, /refresh,position=position, positive_only=positiveonly,negative_only=negativeonly,winid=winid_m,cmdindex=cmdind_m,/replacecmd,_extra=_extra     
         
    endif else begin 
c8368c6e   Ilyes Choubani   updating plotting...
526
        
88872c38   Ilyes Choubani   small update. Cha...
527
        ; PLOTTING OF DATA THAT IS UNCHANGED 
9ded3be9   Ilyes Choubani   Display update. F...
528
529
530
531
532
533
        cgwindow,'dustem_plot_dataset', st, dataset=datasets, position=position,positive_only=positiveonly,negative_only=negativeonly, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1 
        ; REFRESHING DATA - to plot the refreshed data for the first time.
        cgwindow,'dustem_plot_dataset', st, dustem_interp,dustem_spec,extra_spec=extra_spec,dataset=datasets,positive_only=positiveonly,negative_only=negativeonly, /refresh ,position=position, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
        !dustemcgwin_ncmds.sed.pl = cmdind_m ;if this works I'll be able to get rid of one of the pointers
           
    endelse       
d4f8829f   Ilyes Choubani   small cleaning
534
      
5f04fa07   Ilyes Choubani   general update
535
    cgcontrol, winid_m, execute=1
2910e8ce   Ilyes Choubani   Draft version of ...
536
         
5f04fa07   Ilyes Choubani   general update
537
538
539
ENDIF 


9ded3be9   Ilyes Choubani   Display update. F...
540
;===========EXTINCION WINDOW
67bd858a   Ilyes Choubani   Replication of th...
541
if test_x then begin
67bd858a   Ilyes Choubani   Replication of th...
542
    
9ded3be9   Ilyes Choubani   Display update. F...
543
    ;===========If window not set, create it and plot data anew
d8df0428   Ilyes Choubani   unfortunate merge...
544
    if iswinext then begin 
52a3c8dc   Jean-Philippe Bernard   mise a jour
545
        ;stop
18e47096   Ilyes Choubani   corrections for e...
546
        cgwindow,wxsize=main_wxsize,wysize=main_wysize,wtitle='DUSTEMWRAP '+!dustem_version.version+' (EXTINCTION)';, wback='grey';,wobject=winobj_m
9ded3be9   Ilyes Choubani   Display update. F...
547
        winid_x = cgquery(dimensions=dim_x,/current) ;dimension is not used...
67bd858a   Ilyes Choubani   Replication of th...
548
549
550
        !dustemcgwin_id.ext = winid_x
        
        cgcontrol, winid_x, execute=0
9ded3be9   Ilyes Choubani   Display update. F...
551
552
        
        ;===========Display Model string
67bd858a   Ilyes Choubani   Replication of th...
553
554
        xxpos = 0.015
        yypos = 0.97
9ded3be9   Ilyes Choubani   Display update. F...
555
        ;===========Display Hydrogen Column Density
67bd858a   Ilyes Choubani   Replication of th...
556
557
558
559
        cgtext, xxpos, yypos,'Model : '+!dustem_model,color=0,/normal,charsize = 1.2,/addcmd ;& cmdind_m+=1 This is the first command in the window
        yypos = 0.95
        cgtext, xxpos, yypos,textoidl('N_{H}')+textoidl(' (H/cm^2) : ')+strmid(string(*!dustem_HCD,format='(1E10.2)'),2),color=0,/normal,charsize = 1.2,/addcmd & cmdind_x+=1
        
9ded3be9   Ilyes Choubani   Display update. F...
560
561
        ;===========Displaying current iteration
        xxpos = 0.015 
67bd858a   Ilyes Choubani   Replication of th...
562
563
        yypos = 0.015
        
9ded3be9   Ilyes Choubani   Display update. F...
564
565
566
       ;FROZEN part that does not change in-between displays.
        cgtext, xxpos, yypos,'Iteration : ',color=0,/normal,charsize = 1.25,/addcmd & cmdind_x+=1
        ;generating the equivalent escape string for the frozen part of the string
e08591fe   Ilyes Choubani   To Annie: removal...
567
        esc_txt = strjoin(replicate(' ', strlen('Iteration : ')))
9ded3be9   Ilyes Choubani   Display update. F...
568
569
         
        ;Refreshed part that changes in-between iterations/displays.
e08591fe   Ilyes Choubani   To Annie: removal...
570
        cgtext, xxpos, yypos,esc_txt+strtrim(!dustem_iter.act,2),color=0,/normal,charsize = 1.25,/addcmd & cmdind_x+=1
9ded3be9   Ilyes Choubani   Display update. F...
571
572
        
        ;
67bd858a   Ilyes Choubani   Replication of th...
573
        !dustemcgwin_ncmds.runs.pl = cmdind_x
9ded3be9   Ilyes Choubani   Display update. F...
574
575
        
        
67bd858a   Ilyes Choubani   Replication of th...
576
577
578
        ;plotting of (mostly) fixed data for rchi2
        ;Since the format of the strings is specified, the length/width of the string in thex direction is fixed. 
        
67bd858a   Ilyes Choubani   Replication of th...
579
580
581
        yypos = 0.97
        
        ;Displaying fixed part
e08591fe   Ilyes Choubani   To Annie: removal...
582
583
584
        ;replacing the chi2 value (refreshed part of the string) by spaces
        esc_txt = strjoin(replicate(' ', strlen(strtrim(string(chi2,format=frmt2),2))))
        cgtext, 0.985, yypos,textoidl('\chi^{2} : ')+esc_txt,color=0,/normal,charsize = 1.0,alignment=1.0,/addcmd & cmdind_x+=1
67bd858a   Ilyes Choubani   Replication of th...
585
        
e08591fe   Ilyes Choubani   To Annie: removal...
586
587
588
589
        ;Displaying refreshed part (first run . This is the command that will be replaced)
        ;generating the equivalent escape string for the frozen part of the string
        esc_txt = strjoin(replicate(' ', strlen(textoidl('\chi^{2} :  '))))
        cgtext, 0.985, yypos,esc_txt+strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0,alignment=1.0,/addcmd & cmdind_x+=1
67bd858a   Ilyes Choubani   Replication of th...
590
591
592
593
        
        ;saving the command id to replace it
        !dustemcgwin_ncmds.chi2.pl = cmdind_x
  
67bd858a   Ilyes Choubani   Replication of th...
594
        ;plotting of (mostly) fixed data for rchi2
e08591fe   Ilyes Choubani   To Annie: removal...
595
    
67bd858a   Ilyes Choubani   Replication of th...
596
597
598
        yypos = 0.95
        
        ;Displaying fixed part
e08591fe   Ilyes Choubani   To Annie: removal...
599
600
601
602
        ;relpacing the rchi2 value (refreshed part of the string) by spaces
        esc_txt = strjoin(replicate(' ', strlen(strtrim(string(rchi2,format=frmt2),2))))
        cgtext, 0.985, yypos,textoidl('r_{\chi^{2}} : ')+esc_txt,color=0,/normal,charsize = 1.35,alignment=1.0,/addcmd & cmdind_x+=1
        
67bd858a   Ilyes Choubani   Replication of th...
603
        ;Displaying refreshed part (first run . This is the command that will be replaced)
e08591fe   Ilyes Choubani   To Annie: removal...
604
605
606
        ;generating the equivalent escape string for the frozen part of the string
        esc_txt = strjoin(replicate(' ', strlen(textoidl('r_{\chi^{2}} : '))))
        cgtext, 0.985, yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize = 1.0,alignment=1.0,/addcmd & cmdind_x+=1
67bd858a   Ilyes Choubani   Replication of th...
607
608
609
610
611
612
        ;saving the command id to replace it
        !dustemcgwin_ncmds.rchi2.pl = cmdind_x
        
        
        ;Plotting of the title of the dashboard (plot(s))
        
e08591fe   Ilyes Choubani   To Annie: removal...
613
        ;Saving the title for the extinction plot
b8019d76   Ilyes Choubani   replacing _extra....
614
        tit=!dustem_plot_range.title_x;
67bd858a   Ilyes Choubani   Replication of th...
615
        
e08591fe   Ilyes Choubani   To Annie: removal...
616
617
618
        cgtext, 0.5, 0.96,tit,color=0,/normal,charsize = 1.6,alignment=0.5,/addcmd & cmdind_x+=1
        ;plotting the status on the bottom of the display window
        cgtext, 0.5, 0.015,'(RUNNING)',color=0,/normal,charsize = 1.6,alignment=0.5,/addcmd & cmdind_x+=1
25140f99   Ilyes Choubani   debugging in plot...
619
            
67bd858a   Ilyes Choubani   Replication of th...
620
621
        !dustemcgwin_ncmds.pltit.pl = cmdind_x
        
d8df0428   Ilyes Choubani   unfortunate merge...
622
    endif else begin ;  refreshed runs 
67bd858a   Ilyes Choubani   Replication of th...
623
624
625
626
    
        
        winid_x = !dustemcgwin_id.ext
        cgcontrol, winid_x, execute=0
9ded3be9   Ilyes Choubani   Display update. F...
627
        cgset, winid_x ;apparently specifying the window index above isn't enough. This might be because of the use of cgcontrol
67bd858a   Ilyes Choubani   Replication of th...
628
629
        
        ;Refreshing chi2 data: 
18e47096   Ilyes Choubani   corrections for e...
630
        cmdind_x = !dustemcgwin_ncmds.chi2.pl
e08591fe   Ilyes Choubani   To Annie: removal...
631
        xxpos = 0.985;1 - !dustemcgwin_ncmds.chi2.txtwdth - 0.03  
67bd858a   Ilyes Choubani   Replication of th...
632
        yypos = 0.97
9ded3be9   Ilyes Choubani   Display update. F...
633
634
        ;using cgwindow's weakness to fix the ps output.
        if !dustem_end ne 0 then esc_txt = textoidl('\chi^{2} :  ') else esc_txt = strjoin(replicate(' ', strlen(textoidl('\chi^{2} :  '))))
18e47096   Ilyes Choubani   corrections for e...
635
636
        cgwindow,'cgtext', xxpos , yypos,esc_txt+strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_x, winid=winid_x ;& cmdind_m+=1
        if !dustem_end ne 0 then  cgwindow,'cgtext', xxpos , yypos,'',color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_x-1, winid=winid_x ;& cmdind_m+=1
9ded3be9   Ilyes Choubani   Display update. F...
637
         ;Refreshing number of runs data: 
67bd858a   Ilyes Choubani   Replication of th...
638
        ;Refreshing rchi2 data: 
18e47096   Ilyes Choubani   corrections for e...
639
        cmdind_x = !dustemcgwin_ncmds.rchi2.pl
e08591fe   Ilyes Choubani   To Annie: removal...
640
        xxpos = 0.985;1 - !dustemcgwin_ncmds.rchi2.txtwdth - 0.03  
67bd858a   Ilyes Choubani   Replication of th...
641
        yypos = 0.95
9ded3be9   Ilyes Choubani   Display update. F...
642
643
        ;using cgwindow's weakness to fix the ps output.        
        if !dustem_end ne 0 then esc_txt = textoidl('r_{\chi^{2}} : ') else esc_txt = strjoin(replicate(' ', strlen(textoidl('r_{\chi^{2}} : '))))
18e47096   Ilyes Choubani   corrections for e...
644
645
        cgwindow,'cgtext', xxpos , yypos,esc_txt+strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_x, winid=winid_x ;& cmdind_m+=1
        if !dustem_end ne 0 then  cgwindow,'cgtext', xxpos , yypos,'',color=0,/normal,charsize = 1.0,alignment=1.0,/replacecmd,cmdindex=cmdind_x-1, winid=winid_x ;& cmdind_m+=1
67bd858a   Ilyes Choubani   Replication of th...
646
        ;Refreshing number of runs data: 
18e47096   Ilyes Choubani   corrections for e...
647
        cmdind_x = !dustemcgwin_ncmds.runs.pl
9ded3be9   Ilyes Choubani   Display update. F...
648
        xxpos = 0.015;0.03 + !dustemcgwin_ncmds.runs.txtwdth*1.35  ;(because of charsize)
67bd858a   Ilyes Choubani   Replication of th...
649
        yypos = 0.015
e08591fe   Ilyes Choubani   To Annie: removal...
650
        esc_txt = strjoin(replicate(' ', strlen('Iteration : ')))
9ded3be9   Ilyes Choubani   Display update. F...
651
652
653
654
        if !dustem_iter.act eq 0 then txt = esc_txt+'Fit failed. '  else begin
            if !dustem_end ne 0 then esc_txt='Iteration : '
            txt = esc_txt+strtrim(!dustem_iter.act,2)
        endelse
18e47096   Ilyes Choubani   corrections for e...
655
        cgwindow,'cgtext', xxpos , yypos,txt,color=0,/normal,charsize = 1.25,/replacecmd,cmdindex=cmdind_x, winid=winid_x ;& cmdind_m+=1
67bd858a   Ilyes Choubani   Replication of th...
656
        
67bd858a   Ilyes Choubani   Replication of th...
657
        ;update of the title here ?
25140f99   Ilyes Choubani   debugging in plot...
658
        
9ded3be9   Ilyes Choubani   Display update. F...
659
660
        if !dustem_end EQ 1 then begin  ;IF & ONLY IF we're at the last iteration (refreshing title)
            ;tit=!dustem_plot_range.title_m
18e47096   Ilyes Choubani   corrections for e...
661
            cmdind_x = !dustemcgwin_ncmds.pltit.pl
67bd858a   Ilyes Choubani   Replication of th...
662
            
9ded3be9   Ilyes Choubani   Display update. F...
663
            xxpos = 0.5;!dustemcgwin_ncmds.pltit.txtwdth_m
e08591fe   Ilyes Choubani   To Annie: removal...
664
            yypos = 0.015
67bd858a   Ilyes Choubani   Replication of th...
665
        
18e47096   Ilyes Choubani   corrections for e...
666
            cgwindow,'cgtext', xxpos , yypos,'(Final Run)',alignment=0.5,color=0,/normal,charsize = 1.6,/replacecmd,cmdindex=cmdind_x, winid=winid_x  
25140f99   Ilyes Choubani   debugging in plot...
667
        
9ded3be9   Ilyes Choubani   Display update. F...
668
669
670
        endif
        
        if !dustem_end EQ -1 then begin ;Adjusting title for subsequent displays to the end of the fit 
25140f99   Ilyes Choubani   debugging in plot...
671
672
673
674
675
676
677
678
            
            tit=!dustem_plot_range.title_x
            cmdind_x = !dustemcgwin_ncmds.pltit.pl
            
            xxpos = 0.5
            yypos =0.96
                
            cgwindow,'cgtext', xxpos , yypos,tit,color=0,/normal,charsize = 1.6,/replacecmd,alignment=0.5,cmdindex=cmdind_x-1, winid=winid_x
9ded3be9   Ilyes Choubani   Display update. F...
679
680
681
682
            ;this following/below call is needed so that the string disappears (string is '(FINAL RUN)' or '(RUNNING)')
            ;just to be safe
            yypos = 0.015
            cgwindow,'cgtext', xxpos, yypos,'',color=0,/normal,charsize = 1.6,/replacecmd,alignment=0.5,cmdindex=cmdind_x, winid=winid_x
25140f99   Ilyes Choubani   debugging in plot...
683
684
        ENDIF 
        
67bd858a   Ilyes Choubani   Replication of th...
685
686
    endelse
    
0496a3ac   Ilyes Choubani   Small corrections...
687
    if !run_pol and tag_exist(*!dustem_show,'qext') then begin
9ded3be9   Ilyes Choubani   Display update. F...
688
      
67bd858a   Ilyes Choubani   Replication of th...
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
        ;position arrays for plot and normalized graph
        
        ;THIS IS HARD-CODED IN A VERY SILLY WAY
        
        p_ext = [0.05,0.67,0.475,0.90]
        p_pext = [0.525,0.67,0.95,0.90]
        p_spext = [0.05,0.375,0.475,0.575] ; Should we plot this? tau_polext/tau_ext_tot. YES FOR NOW...
        p_psiext = [0.525,0.375,0.95,0.575]
        p_qext = [0.05,0.12,0.475,0.35]  
        p_uext = [0.525,0.12,0.95,0.35]
        
        np_ext = [0.05,0.60,0.475,0.67]
        np_pext = [0.525,0.60,0.95,0.67]
        np_qext = [0.05,0.05,0.475,0.12] 
        np_uext = [0.525,0.05,0.95,0.12]
        
        p_ext[1]+= 0.0125 & p_ext[3]+= 0.0125 
        p_pext[1]+= 0.0125 & p_pext[3]+= 0.0125
        p_spext[1]+= 0.0125 & p_spext[3]+= 0.0125
        p_psiext[1]+= 0.0125 & p_psiext[3]+= 0.0125
        p_qext[1]+= 0.0125 & p_qext[3]+= 0.0125
        p_uext[1]+= 0.0125 & p_uext[3]+= 0.0125
        
        np_ext[1]+= 0.0125 & np_ext[3]+= 0.0125 
        np_pext[1]+= 0.0125 & np_pext[3]+= 0.0125
        np_qext[1]+= 0.0125 & np_qext[3]+= 0.0125
        np_uext[1]+= 0.0125 & np_uext[3]+= 0.0125
        
        
          
    endif else begin
        p_ext  = [0.07,0.30,0.97,0.85]
        np_ext = [0.07,0.10,0.97,0.30]
    
    endelse

    ;Plotting of sed data axes (whether or not data is present)
    plotsym,0,/fill ;you might need to execute this again. hmm...

9ded3be9   Ilyes Choubani   Display update. F...
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
    if !run_pol and tag_exist(*!dustem_show,'qext') then begin
        ;This part can be adjusted for future releases if the user wants to plot 
        ;specific datasets 
        
        ;lists because elements have different dimensions and/or we want entire arrays as elements
        dustem_interp = list(dustem_ext,dustem_fpolext,dustem_qext,dustem_uext,dustem_psi_ext,dustem_polext) ;DustEmWrap SED predictions
        dustem_spec = list(EXT_spec,SPEXT_spec,QEXT_spec,UEXT_spec,PSIEXT_spec,POLEXT_spec) ;DustEM spectra predictions
        extra_spec = list(0,EXT_spec,0,0,0,0) ;extra spectra that the dataset needs in order to be plotted. 
        ;This (extra_spec use) actually should not be generalized since the only case we need an extra spectrum is when plotting the polarization fraction.
        position = list(list(p_ext,np_ext),list(p_spext),list(p_qext,np_qext),list(p_uext,np_uext),list(p_psiext),list(p_pext,np_pext))
        
        ;these don't have to be lists
        datasets = ['EXT','FPOLEXT','QEXT','UEXT','PSI_EXT','POLEXT']
        ;but these can be combined using a list but we're leaving it as is for the moment...
        positiveonly = [0,0,1,1,0,0] ;used for q and u
        negativeonly = [0,0,1,1,0,0] ;used for q and u
    ENDIF ELSE BEGIN
67bd858a   Ilyes Choubani   Replication of th...
745
    
9ded3be9   Ilyes Choubani   Display update. F...
746
747
748
749
750
751
752
753
754
        dustem_interp = list(dustem_ext) ;DustEmWrap EXT predictions . 
        dustem_spec = list(EXT_spec) ;DustEM spectra predictions
        position = list(p_ext,np_ext);list(list(p_sed,np_sed)) ; I think I need this ...
        ;position_n =list(np_sed) 
        datasets = ['EXT']
        ;replace by one keyword?
        positiveonly=[0] ;kept it for completeness. Also this loop reminds me that JP also wants the user to be able to display one dataset. 
        negativeonly=[0]
    ENDELSE
d4f8829f   Ilyes Choubani   small cleaning
755
    
18e47096   Ilyes Choubani   corrections for e...
756
    if  ~iswinext then begin ;PLOTTING OF REFRESHED DATA
9ded3be9   Ilyes Choubani   Display update. F...
757
758
759
760
761
762
         
         ;REFRESHING DATA  
         cmdind_x = !dustemcgwin_ncmds.ext.pl
         cgwindow,'dustem_plot_dataset', st, dustem_interp,dustem_spec,extra_spec=extra_spec,dataset=datasets, /refresh,position=position, positive_only=positiveonly,negative_only=negativeonly,winid=winid_x,cmdindex=cmdind_x,/replacecmd,_extra=_extra     
         
    endif else begin 
67bd858a   Ilyes Choubani   Replication of th...
763
        
9ded3be9   Ilyes Choubani   Display update. F...
764
765
766
767
        ; PLOTTING OF DATA THAT IS UNCHAED 
        cgwindow,'dustem_plot_dataset', st, dataset=datasets, position=position,positive_only=positiveonly,negative_only=negativeonly, /addcmd, winid=winid_x, _extra=_extra & cmdind_x+=1 
        ; REFRESHING DATA - to plot the refreshed data for the first time.
        cgwindow,'dustem_plot_dataset', st, dustem_interp,dustem_spec,extra_spec=extra_spec,dataset=datasets,positive_only=positiveonly,negative_only=negativeonly, /refresh ,position=position, /addcmd, winid=winid_x, _extra=_extra & cmdind_x+=1
18e47096   Ilyes Choubani   corrections for e...
768
        !dustemcgwin_ncmds.ext.pl = cmdind_x ;if this works I'll be able to get rid of one of the pointers
9ded3be9   Ilyes Choubani   Display update. F...
769
770
           
    endelse       
67bd858a   Ilyes Choubani   Replication of th...
771
        
67bd858a   Ilyes Choubani   Replication of th...
772
    cgcontrol, winid_x, execute=1
d4f8829f   Ilyes Choubani   small cleaning
773
     
67bd858a   Ilyes Choubani   Replication of th...
774
775
776
          
ENDIF 

67bd858a   Ilyes Choubani   Replication of th...
777

5f04fa07   Ilyes Choubani   general update
778
779
780
781
782
783
IF ~iswinprms THEN BEGIN;(NEXT RUNS)
    
    winid_prms = !dustemcgwin_id.prms
    cgcontrol, winid_prms, execute=0
    cgset, winid_prms
    cmdind_prms = !dustemcgwin_ncmds.prms.pl
9ded3be9   Ilyes Choubani   Display update. F...
784
785
786
    
    cgwindow,'dustem_plot_dataset', st, p_dim, errors,dataset=['PARAMETERS'], /refresh,winid=winid_prms,cmdindex=cmdind_prms,/replacecmd, _extra=_extra
    
5f04fa07   Ilyes Choubani   general update
787
ENDIF ELSE BEGIN ;(FIRST RUN)
3b1e2e39   Jean-Philippe Bernard   replaced V2.0 by ...
788
    cgwindow,wxpos=param_wxpos,wypos=param_wypos,wxsize=param_wxsize,wysize=param_wysize,wtitle='DUSTEMWRAP '+!dustem_version.version+' (PARAMETERS)' ; keeping the same y dimension of the emission/extinction plot? 
9ded3be9   Ilyes Choubani   Display update. F...
789

5f04fa07   Ilyes Choubani   general update
790
791
792
    winid_prms = cgquery(dimensions=dim_prms,/current) ;we don't need the dimension of the window so far/ I don't know why I needed it before
    cgcontrol, winid_prms, execute=0
    !dustemcgwin_id.prms = winid_prms
9ded3be9   Ilyes Choubani   Display update. F...
793
794
    cgwindow,'dustem_plot_dataset', st, p_dim, errors,dataset=['PARAMETERS'], /addcmd , winid=winid_prms,_extra=_extra ;& cmdind_prms+=1
    cgwindow,'dustem_plot_dataset', st, p_dim, errors,dataset=['PARAMETERS'], /addcmd, /refresh , winid=winid_prms, _extra=_extra & cmdind_prms+=1
5f04fa07   Ilyes Choubani   general update
795
    !dustemcgwin_ncmds.prms.pl = cmdind_prms
9ded3be9   Ilyes Choubani   Display update. F...
796
797
798
799
     
ENDELSE
cgcontrol, winid_prms ,execute=1 

5f04fa07   Ilyes Choubani   general update
800

d4f8829f   Ilyes Choubani   small cleaning
801
IF (tag_names(*!dustem_plugin))(0) NE 'NONE' THEN BEGIN  
67bd858a   Ilyes Choubani   Replication of th...
802
803
804
805
806
807
808

    IF ~iswinplgns THEN BEGIN;(NEXT RUNS)
        
        winid_plgns = !dustemcgwin_id.plgns
        cgcontrol, winid_plgns, execute=0
        cgset, winid_plgns
        cmdind_plgns = !dustemcgwin_ncmds.plgns.pl
9ded3be9   Ilyes Choubani   Display update. F...
809
810
811
        cgwindow,'dustem_plot_dataset', st, p_dim, errors,dataset=['PLUGINS'], /refresh, winid=winid_plgns,/replacecmd,cmdindex=cmdind_plgns, _extra=_extra
        
        
67bd858a   Ilyes Choubani   Replication of th...
812
    ENDIF ELSE BEGIN ;(FIRST RUN)
9ded3be9   Ilyes Choubani   Display update. F...
813
        
3b1e2e39   Jean-Philippe Bernard   replaced V2.0 by ...
814
        cgwindow,wxpos=plugin_wxpos,wypos=plugin_wypos,wxsize=plugin_wxsize,wysize=plugin_wysize,wtitle='DUSTEMWRAP '+!dustem_version.version+' (PLUGINS)' ; keeping the same y dimension of the emission/extinction plot? 
9ded3be9   Ilyes Choubani   Display update. F...
815
        
67bd858a   Ilyes Choubani   Replication of th...
816
817
        cgcontrol, winid_plgns, execute=0
        !dustemcgwin_id.plgns = winid_plgns
9ded3be9   Ilyes Choubani   Display update. F...
818
819
        cgwindow,'dustem_plot_dataset', st, p_dim, errors,dataset=['PLUGINS'], /addcmd , winid=winid_plgns,_extra=_extra ;& cmdind_prms+=1
        cgwindow,'dustem_plot_dataset', st, p_dim, errors,dataset=['PLUGINS'], /addcmd, /refresh , winid=winid_plgns, _extra=_extra & cmdind_plgns+=1
67bd858a   Ilyes Choubani   Replication of th...
820
        !dustemcgwin_ncmds.plgns.pl = cmdind_plgns
9ded3be9   Ilyes Choubani   Display update. F...
821
        
67bd858a   Ilyes Choubani   Replication of th...
822
823
824
    ENDELSE
     
ENDIF
9ded3be9   Ilyes Choubani   Display update. F...
825
826
827
828
829
830
cgcontrol, winid_plgns ,execute=1     

if !dustem_end then !dustem_end = -1 ;so that the last iteration is only plotted once.



392ede91   Jean-Philippe Bernard   included an help ...
831
the_end:
52a3c8dc   Jean-Philippe Bernard   mise a jour
832
;stop
392ede91   Jean-Philippe Bernard   included an help ...
833

2910e8ce   Ilyes Choubani   Draft version of ...
834
END