Blame view

src/idl/dustemwrap_plot.pro 26.3 KB
5f04fa07   Ilyes Choubani   general update
1
PRO dustemwrap_plot,p_dim,st,dustem_sed,SED_spec,dustem_qsed,Q_spec,dustem_used,U_spec,dustem_polsed,P_spec,dustem_polfrac,SP_spec,dustem_psi_em,PSI_spec,_extra=_extra 
2910e8ce   Ilyes Choubani   Draft version of ...
2

2910e8ce   Ilyes Choubani   Draft version of ...
3

dfc68a85   Ilyes Choubani   Fixed some plotti...
4
;This is necessary for the plotting of the results of the fit (Last iteration) 
2910e8ce   Ilyes Choubani   Draft version of ...
5
6
7
IF not keyword_set(st) THEN BEGIN
  ;Activation of the plugins is needed because of the plotting of the total emission model that includes them. 
  dustem_activate_plugins,p_dim/(*(*!dustem_fit).param_init_values)  ; 0/0 division case?
5f04fa07   Ilyes Choubani   general update
8
  st=dustem_run(p_dim)
fcb6eade   Ilyes Choubani   general update - ...
9
10
11
12
13
14
15
  dustem_sed = dustem_compute_sed(p_dim,st,SED_spec)
  
  if !run_pol && !run_lin then begin
      
      dustem_polsed = dustem_compute_polsed(p_dim,st,P_spec,SP_spec,dustem_polfrac)
      toto = dustem_compute_stokes(p_dim,st,dustem_qsed,dustem_used,Q_spec,U_spec,PSI_spec,dustem_psi_em) 
      
f2808c64   Jean-Philippe Bernard   improved
16
17
18
19
  endif
ENDIF ELSE BEGIN
  dustem_sed = dustem_compute_sed(p_dim,st,SED_spec)
ENDELSE
2910e8ce   Ilyes Choubani   Draft version of ...
20

dfc68a85   Ilyes Choubani   Fixed some plotti...
21
22


2910e8ce   Ilyes Choubani   Draft version of ...
23
24
25
26
27
28
;if ~windowavailable(cgquery()) then begin

;LIST OF TESTS THAT NEED TO BE RAN SO THAT THE PLOTTING OF THE MODEL SPECTRA OCCURS

test_sed = isa(!dustem_show.sed)
test_ext = isa(!dustem_show.ext)
b5314324   Ilyes Choubani   updating the plot...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
if !run_pol then begin
    test_polext = isa(!dustem_show.polext)
    test_polsed = isa(!dustem_show.polsed)
    test_polfrac = isa(!dustem_show.polfrac)
    test_psi_em = isa(!dustem_show.psi_em)
    test_psi_ext = isa(!dustem_show.psi_ext)
    test_qsed = isa(!dustem_show.qsed)
    test_used = isa(!dustem_show.used)
    test_qext = isa(!dustem_show.qext)
    test_uext = isa(!dustem_show.uext)
    test_m = test_sed or test_polsed or test_polfrac or test_qsed or test_used or test_psi_em
    test_x = test_ext or test_polext or test_qext or test_uext or test_psi_ext
endif else begin
    test_m = test_sed 
    test_x = test_ext 
endelse
18e4331f   Ilyes Choubani   general update (f...
45

2910e8ce   Ilyes Choubani   Draft version of ...
46
;testing on the fitting of emission vs extinction data
2910e8ce   Ilyes Choubani   Draft version of ...
47

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

5f04fa07   Ilyes Choubani   general update
50
51
52
53
frmt0='(A36)'
frmt1='(1E10.2)'
frmt2='(10F10.2)'

2910e8ce   Ilyes Choubani   Draft version of ...
54
55
56
;I have decided to keep track of the command index manually as I did not find any command online that does this.
cmdind_m = 0 ;for emission
cmdind_x = 0 ;for extinction
5f04fa07   Ilyes Choubani   general update
57
58
59
;trying to do the same thing for parameters and plugins
cmdind_prms = 0 ;for parameters
cmdind_plgns = 0 ;for plugins
2910e8ce   Ilyes Choubani   Draft version of ...
60

2910e8ce   Ilyes Choubani   Draft version of ...
61
;ADDING PLUGIN(S) TO SPECTRUM----------------
2910e8ce   Ilyes Choubani   Draft version of ...
62
63
64
65

;these following indices will be used to change the keep the same information in the _extra structure
;this is an initial solution until I finish coding the _extra-filtering procedure. 

2910e8ce   Ilyes Choubani   Draft version of ...
66
67
68
iswinsed = !dustemcgwin_id.sed EQ la_undef()
iswinext = !dustemcgwin_id.ext EQ la_undef()

5f04fa07   Ilyes Choubani   general update
69
70
71
72
73
74
75
;trying to do the same thing for parameters and plugins
;But we need to know if the extinction or the emission mode is on.
;so the use of ths pointer will be different than the others
iswinprms = !dustemcgwin_id.prms EQ la_undef()
iswinplgns = !dustemcgwin_id.plgns EQ la_undef()


18e4331f   Ilyes Choubani   general update (f...
76
77
78
;plotstrct = !p
degtorad = !pi/180 ;factor that the arctan will be devided by in order to have an axis in degrees. Talk to JP maybe he wants angle in radians.

5f04fa07   Ilyes Choubani   general update
79
80
81
82
;I think I will test over the presence of the errors because they are not computed at that point.

;errors = ((*!dustem_fit).current_param_errors)
if isa((*!dustem_fit).current_param_errors) then begin
fcb6eade   Ilyes Choubani   general update - ...
83
    errors = (*(*!dustem_fit).current_param_errors) * (*(*!dustem_fit).param_init_values)
5f04fa07   Ilyes Choubani   general update
84
endif else begin
dfc68a85   Ilyes Choubani   Fixed some plotti...
85
    errors = (*(*!dustem_fit).param_init_values)*0.;+la_undef();Initialized to 0 instead of la_undef() 
5f04fa07   Ilyes Choubani   general update
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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 

707e83c5   Ilyes Choubani   updating dustewra...
100

fcb6eade   Ilyes Choubani   general update - ...
101
if isa(p_dim) then begin
dfc68a85   Ilyes Choubani   Fixed some plotti...
102
103
104
105
106
107
108
109
110
111
    
    if isa((*!dustem_fit).current_param_values) then begin
        
        res  = (*(*!dustem_fit).current_param_values) 
        
    endif else begin  
    
        res = p_dim    
    
    endelse
fcb6eade   Ilyes Choubani   general update - ...
112
113
endif else begin
    
dfc68a85   Ilyes Choubani   Fixed some plotti...
114
   res = (*(*!dustem_fit).param_init_values)*0.;+la_undef()
fcb6eade   Ilyes Choubani   general update - ...
115
116
    
endelse
2910e8ce   Ilyes Choubani   Draft version of ...
117
118
119

;if iswinsed then begin ;I believe the iswin test should be below the case condition because I am not copying all the first 'HUGE LOOP' but rather replacing the positional arrays.            
if test_m then begin
2910e8ce   Ilyes Choubani   Draft version of ...
120
121
122
    ;Generating emission window and saving window ID
    
    if iswinsed then begin
dfc68a85   Ilyes Choubani   Fixed some plotti...
123
        
af5bca1f   Ilyes Choubani   general update
124
        if !run_pol then cgwindow,wxsize=910,wysize=658,wtitle='DUSTEMWRAP v2.0 (EMISSION)' else cgwindow, wtitle='DUSTEMWRAP v2.0 (EMISSION)';, wback='grey';,wobject=winobj_m
2910e8ce   Ilyes Choubani   Draft version of ...
125
126
127
        winid_m = cgquery(dimensions=dim_m,/current) ;this has to be changed because the dimensions of this array change with the data sets present (extinction/emission).
        !dustemcgwin_id.sed = winid_m
        
5f04fa07   Ilyes Choubani   general update
128
129
130
131
132
133
        cgcontrol, winid_m, execute=0
        ;cgset, winid_m
        ;Plotting model string (legend)
        xxpos = 0.015
        yypos = 0.97
        ;Plotting Hydrogen column density string (legend)
abebbdf3   Ilyes Choubani   General update: A...
134
        cgtext, xxpos, yypos,'Model : '+!dustem_model,color=0,/normal,charsize = 1.2,/addcmd ;& cmdind_m+=1 This is the first command in the window
5f04fa07   Ilyes Choubani   general update
135
        yypos = 0.95
abebbdf3   Ilyes Choubani   General update: A...
136
        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
5f04fa07   Ilyes Choubani   general update
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
        
        ;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. 
        
        
        ;Getting the width of the unrefreshed string
        widthtot=0.
        cgtext, xxpos, yypos,textoidl('\chi^{2} : '),color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_m+=1
        widthtext = thiswidth
        widthtot+= thiswidth ;fixed width
        
        ;Getting the width of the refresh.ed string
        cgtext, xxpos, yypos,strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_m+=1
        widthtot+= thiswidth;varying width        
        ;saving the command string width to replace it
        !dustemcgwin_ncmds.chi2.txtwdth = thiswidth
        
        
abebbdf3   Ilyes Choubani   General update: A...
155
        xxpos = 1.0 - widthtot - 0.03
5f04fa07   Ilyes Choubani   general update
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
        
        yypos = 0.97
        
        ;Displaying fixed part
        cgtext, xxpos, yypos,textoidl('\chi^{2} : '),color=0,/normal,charsize = 1.0,/addcmd & cmdind_m+=1
        ;Displaying refreshed part (first run . This is the command that will be replaced)
        
        cgtext, xxpos + widthtext , yypos,strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0,/addcmd & cmdind_m+=1
       
        ;saving the command id to replace it
        !dustemcgwin_ncmds.chi2.pl = cmdind_m
 
        
        
        ;plotting of (mostly) fixed data for rchi2
        
        ;Getting the width of the unrefreshed string
        widthtot=0.
        cgtext, xxpos, yypos,textoidl('r_{\chi^{2}} : '),color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_m+=1
        widthtext = thiswidth
        widthtot+= thiswidth ;fixed width
        ;!dustemcgwin_ncmds.rchi2.txtwdth1 = thiswidth
        ;Getting the width of the refreshed string
        cgtext, xxpos, yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_m+=1
        widthtot+= thiswidth;varying width        
        !dustemcgwin_ncmds.rchi2.txtwdth = thiswidth
        ;These two lines will also have to      be modified when plotting the refreshed values
abebbdf3   Ilyes Choubani   General update: A...
183
        xxpos = 1.0 - widthtot - 0.03
5f04fa07   Ilyes Choubani   general update
184
185
186
187
188
189
190
191
192
193
        yypos = 0.95
        
        ;Displaying fixed part
        cgtext, xxpos, yypos,textoidl('r_{\chi^{2}} : '),color=0,/normal,charsize = 1.35,/addcmd & cmdind_m+=1
        ;Displaying refreshed part (first run . This is the command that will be replaced)
        cgtext, xxpos + widthtext , yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize = 1.0,/addcmd & cmdind_m+=1
        ;saving the command id to replace it
        !dustemcgwin_ncmds.rchi2.pl = cmdind_m
        
        
5f04fa07   Ilyes Choubani   general update
194
195
        ;Plotting of the title of the dashboard (plot(s))
        
5f04fa07   Ilyes Choubani   general update
196
        ;Getting the width of the title 
dfc68a85   Ilyes Choubani   Fixed some plotti...
197
198
199
200
        tit=string(_extra.title);
    
        cgtext, 0.3, 0.95,tit+' (RUNNING)',color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_m+=1
        widthtot = thiswidth
5f04fa07   Ilyes Choubani   general update
201
202
        xxpos = (1 - thiswidth)/2
        yypos = 0.96
dfc68a85   Ilyes Choubani   Fixed some plotti...
203
204
205
206
        
        cgtext, 0.3, 0.95,tit,color=0,/normal,charsize=-1,width=thiswidth,/addcmd & cmdind_m+=1 
        !dustemcgwin_ncmds.pltit.txtwdth = thiswidth*1.6 + (1 - widthtot)/2
         
5f04fa07   Ilyes Choubani   general update
207
        cgtext, xxpos, yypos,tit,color=0,/normal,charsize = 1.6,/addcmd & cmdind_m+=1
dfc68a85   Ilyes Choubani   Fixed some plotti...
208
209
        xxpos+=thiswidth*1.6
        cgtext, xxpos, yypos,' (RUNNING)',color=0,/normal,charsize = 1.6,/addcmd & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
210
211
212
213
        
        !dustemcgwin_ncmds.pltit.pl = cmdind_m
        
    endif else begin 
2910e8ce   Ilyes Choubani   Draft version of ...
214
    
5f04fa07   Ilyes Choubani   general update
215
216
217
218
219
220
221
        
        winid_m = !dustemcgwin_id.sed
        cgcontrol, winid_m, execute=0
        cgset, winid_m ;apparently specifying the window index isn't enough. This might be because of the use of cgcontrol
        
        ;Refreshing chi2 data: 
        cmdin_m = !dustemcgwin_ncmds.chi2.pl
abebbdf3   Ilyes Choubani   General update: A...
222
        xxpos = 1 - !dustemcgwin_ncmds.chi2.txtwdth - 0.03  
5f04fa07   Ilyes Choubani   general update
223
224
225
226
227
228
229
        yypos = 0.97
        cgwindow,'cgtext', xxpos , yypos,strtrim(string(chi2,format=frmt2),2),color=0,/normal,charsize = 1.0,/replacecmd,cmdindex=cmdin_m, winid=winid_m ;& cmdind_m+=1
        
        
        
        ;Refreshing rchi2 data: 
        cmdin_m = !dustemcgwin_ncmds.rchi2.pl
abebbdf3   Ilyes Choubani   General update: A...
230
        xxpos = 1 - !dustemcgwin_ncmds.rchi2.txtwdth - 0.03  
5f04fa07   Ilyes Choubani   general update
231
232
        yypos = 0.95
        cgwindow,'cgtext', xxpos , yypos,strtrim(string(rchi2,format=frmt2),2),color=0,/normal,charsize = 1.0,/replacecmd,cmdindex=cmdin_m, winid=winid_m ;& cmdind_m+=1
dfc68a85   Ilyes Choubani   Fixed some plotti...
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
         
         
        ;update of the title here ?
        
        if isa((*!dustem_fit).current_param_values) then begin
            ;replacing my count - 3
            tit=string(_extra.title)
            cmdin_m = !dustemcgwin_ncmds.pltit.pl
            
            xxpos = !dustemcgwin_ncmds.pltit.txtwdth
            yypos = 0.96
        
            cgwindow,'cgtext', xxpos , yypos,' (Final Run)',color=0,/normal,charsize = 1.6,/replacecmd,cmdindex=cmdin_m, winid=winid_m  
        
        endif
    
5f04fa07   Ilyes Choubani   general update
249
    endelse
2910e8ce   Ilyes Choubani   Draft version of ...
250
251
252
253
    
    ;cgWindow_GetDefs,xsize=xsize,ysize=ysize
    ;cgcontrol, resize=[xsize,ysize]
    if !run_pol then begin
c8368c6e   Ilyes Choubani   updating plotting...
254
        ;,wback='grey'
2910e8ce   Ilyes Choubani   Draft version of ...
255
256
        
        ;position arrays for plot and normalized graph
af5bca1f   Ilyes Choubani   general update
257
        
af5bca1f   Ilyes Choubani   general update
258
        ;THIS IS HARD-CODED IN A VERY SILLY WAY
2910e8ce   Ilyes Choubani   Draft version of ...
259
260
261
        
        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
262
        p_spsed = [0.05,0.375,0.475,0.575]
18e4331f   Ilyes Choubani   general update (f...
263
        p_psised = [0.525,0.375,0.95,0.575]
5f04fa07   Ilyes Choubani   general update
264
        p_qsed = [0.05,0.12,0.475,0.35]  
18e4331f   Ilyes Choubani   general update (f...
265
266
        p_used = [0.525,0.12,0.95,0.35]
        
2910e8ce   Ilyes Choubani   Draft version of ...
267
        np_sed = [0.05,0.60,0.475,0.67]
18e4331f   Ilyes Choubani   general update (f...
268
269
270
        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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
        
        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 ...
286
287
288
    endif else begin
        p_sed  = [0.07,0.30,0.97,0.85]
        np_sed = [0.07,0.10,0.97,0.30]
c8368c6e   Ilyes Choubani   updating plotting...
289
    
2910e8ce   Ilyes Choubani   Draft version of ...
290
291
292
293
    endelse

    ;Plotting of sed data axes (whether or not data is present)
    plotsym,0,/fill ;you might need to execute this again. hmm...
5f04fa07   Ilyes Choubani   general update
294
295


bc224f3e   Ilyes Choubani   Update of plottin...
296
    ;This is not the right test the user might want to show the prediction for sed and fit the stokes parameters
2910e8ce   Ilyes Choubani   Draft version of ...
297
298
    if ~test_sed then begin ; SED data is not present (For completeness) # This is only valid when !run_pol=1
        
5f04fa07   Ilyes Choubani   general update
299
300
        cgwindow,'dustemcgwin_dataset', st, dataset='SED', /nodata, position=p_sed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
        cgwindow,'dustemcgwin_dataset', st, dataset='SED', /nodata, /norm, position=np_sed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
2910e8ce   Ilyes Choubani   Draft version of ...
301

2910e8ce   Ilyes Choubani   Draft version of ...
302
    endif else begin ;SED exists
18e4331f   Ilyes Choubani   general update (f...
303
304

       if  ~iswinsed then begin
5f04fa07   Ilyes Choubani   general update
305
       
18e4331f   Ilyes Choubani   general update (f...
306
           cmdind_m = !dustemcgwin_ncmds.sed.pl
5f04fa07   Ilyes Choubani   general update
307
308
           cgwindow,'dustemcgwin_dataset', st, dustem_sed,SED_spec,dataset='SED', /refresh ,position=p_sed, winid=winid_m,cmdindex=cmdind_m,/replacecmd,_extra=_extra     
           
18e4331f   Ilyes Choubani   general update (f...
309
           cmdind_m = !dustemcgwin_ncmds.sed.nrm
5f04fa07   Ilyes Choubani   general update
310
311
312
           cgwindow,'dustemcgwin_dataset', st, dustem_sed,SED_spec,dataset='SED', /norm, /refresh,position=np_sed, winid=winid_m,cmdindex=cmdind_m,/replacecmd,_extra=_extra
           
           
18e4331f   Ilyes Choubani   general update (f...
313
       endif else begin
5f04fa07   Ilyes Choubani   general update
314
315
316
      
           cgwindow,'dustemcgwin_dataset', st, dataset='SED', position=p_sed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1 
           cgwindow,'dustemcgwin_dataset', st, dustem_sed,SED_spec, dataset='SED', /refresh ,position=p_sed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
317
           !dustemcgwin_ncmds.sed.pl = cmdind_m
5f04fa07   Ilyes Choubani   general update
318
           
18e4331f   Ilyes Choubani   general update (f...
319
           cgwindow,'dustemcgwin_dataset', st, dataset='SED',/norm, position=np_sed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1 ;I think nodata can also be used too
5f04fa07   Ilyes Choubani   general update
320
321
           
           cgwindow,'dustemcgwin_dataset', st, dustem_sed,SED_spec, dataset='SED', /norm, /refresh,position=np_sed, /addcmd ,winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
322
           !dustemcgwin_ncmds.sed.nrm = cmdind_m
5f04fa07   Ilyes Choubani   general update
323
              
18e4331f   Ilyes Choubani   general update (f...
324
325
326
327
328
       endelse       
    endelse
    
    ;if ~!run_pol then begin;I don't think the order of the  ;goto, end_m
      if !run_pol then begin ;then goto, end_m
2910e8ce   Ilyes Choubani   Draft version of ...
329
        
18e4331f   Ilyes Choubani   general update (f...
330
331
332
        if ~test_qsed then begin ;Qsed is not present
            
            cgwindow,'dustemcgwin_dataset', st, dataset='QSED', /nodata, position=p_qsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
333
            cgwindow,'dustemcgwin_dataset', st, dataset='QSED', /nodata, /norm, position=np_qsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
c8368c6e   Ilyes Choubani   updating plotting...
334
        
18e4331f   Ilyes Choubani   general update (f...
335
336
337
338
339
        endif else begin ;Qsed data is present
               
            if  ~iswinsed then begin
                cmdind_m = !dustemcgwin_ncmds.qsed.pl
                ;refreshing the positive_only and negative_only plots if data is present in them
5f04fa07   Ilyes Choubani   general update
340
341
342
343
                cgwindow,'dustemcgwin_dataset', st, dustem_qsed,Q_spec,SED_spec,dataset='QSED',/positive_only, nodata=0, /refresh ,position=p_qsed, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
                
                cgwindow,'dustemcgwin_dataset', st, dustem_qsed,Q_spec,SED_spec, dataset='QSED',/negative_only, nodata=0, /refresh ,position=p_qsed, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
                
18e4331f   Ilyes Choubani   general update (f...
344
                cmdind_m = !dustemcgwin_ncmds.qsed.nrm
5f04fa07   Ilyes Choubani   general update
345
346
                cgwindow,'dustemcgwin_dataset', st, dustem_qsed,Q_spec,SED_spec, dataset='QSED', /refresh, nodata=0, /norm,position=np_qsed, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
                
18e4331f   Ilyes Choubani   general update (f...
347
            endif else begin
5f04fa07   Ilyes Choubani   general update
348
                
dfc68a85   Ilyes Choubani   Fixed some plotti...
349
                ;Plotting of postive values if they exist (if hidden data is present it is plotted if not an empty plot is rendered)
18e4331f   Ilyes Choubani   general update (f...
350
351
                cgwindow,'dustemcgwin_dataset', st, dataset='QSED', position=p_qsed, /addcmd, winid=winid_m,/positive_only, _extra=_extra & cmdind_m+=1
                ;Refreshing the positive_only plot ONLY if there is data. If not do nothing
5f04fa07   Ilyes Choubani   general update
352
                cgwindow,'dustemcgwin_dataset', st, dustem_qsed,Q_spec,SED_spec, dataset='QSED',/positive_only, /refresh ,position=p_qsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
353
354
355
                
                cgwindow,'dustemcgwin_dataset', st, dataset='QSED', position=p_qsed, /addcmd, winid=winid_m,/negative_only, _extra=_extra & cmdind_m+=1
                ;Refreshing the negative_only plot ONLY if there is data. If not do nothing
5f04fa07   Ilyes Choubani   general update
356
357
                cgwindow,'dustemcgwin_dataset', st, dustem_qsed,Q_spec,SED_spec,dataset='QSED',/negative_only, /refresh ,position=p_qsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
            
18e4331f   Ilyes Choubani   general update (f...
358
359
                !dustemcgwin_ncmds.qsed.pl = cmdind_m
                
5f04fa07   Ilyes Choubani   general update
360
                
18e4331f   Ilyes Choubani   general update (f...
361
                cgwindow,'dustemcgwin_dataset', st, dataset='QSED',/norm, position=np_qsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1 ;I think nodata can also be uqsed too
5f04fa07   Ilyes Choubani   general update
362
                cgwindow,'dustemcgwin_dataset', st, dustem_qsed,Q_spec,SED_spec,dataset='QSED', /norm, /refresh,position=np_qsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
363
                !dustemcgwin_ncmds.qsed.nrm = cmdind_m
5f04fa07   Ilyes Choubani   general update
364
                
18e4331f   Ilyes Choubani   general update (f...
365
366
        endelse       
      endelse
5f04fa07   Ilyes Choubani   general update
367
         ;stop        
18e4331f   Ilyes Choubani   general update (f...
368
369
370
        if ~test_used then begin ;used is not present
            
            cgwindow,'dustemcgwin_dataset', st, dataset='USED', /nodata, position=p_used, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
371
            cgwindow,'dustemcgwin_dataset', st, dataset='USED', /nodata, /norm, position=np_used, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
c8368c6e   Ilyes Choubani   updating plotting...
372
        
18e4331f   Ilyes Choubani   general update (f...
373
374
375
376
377
        endif else begin ;used data is present
               
            if  ~iswinsed then begin
                cmdind_m = !dustemcgwin_ncmds.used.pl
                ;refreshing the positive_only and negative_only plots if data is present in them
5f04fa07   Ilyes Choubani   general update
378
379
380
381
                cgwindow,'dustemcgwin_dataset', st, dustem_used,U_spec,SED_spec, dataset='USED',/positive_only, /refresh, nodata=0 ,position=p_used, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
                
                cgwindow,'dustemcgwin_dataset', st, dustem_used,U_spec,SED_spec, dataset='USED',/negative_only, /refresh, nodata=0 ,position=p_used, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
                
18e4331f   Ilyes Choubani   general update (f...
382
                cmdind_m = !dustemcgwin_ncmds.used.nrm
5f04fa07   Ilyes Choubani   general update
383
384
                cgwindow,'dustemcgwin_dataset', st, dustem_used,U_spec,SED_spec, dataset='USED', /refresh, nodata=0, /norm,position=np_used, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
                
18e4331f   Ilyes Choubani   general update (f...
385
386
387
388
389
            endif else begin
            ;stop
                ;Plotting of postive values if they exist (if hidden data is present it is plotted if not an empty plot is rendred)
                cgwindow,'dustemcgwin_dataset', st, dataset='USED', position=p_used, /addcmd, winid=winid_m,/positive_only, _extra=_extra & cmdind_m+=1
                ;Refreshing the positive_only plot ONLY if there is data. If not do nothing
5f04fa07   Ilyes Choubani   general update
390
                cgwindow,'dustemcgwin_dataset', st, dustem_used,U_spec,SED_spec, dataset='USED',/positive_only, /refresh ,position=p_used, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
391
392
393
                
                cgwindow,'dustemcgwin_dataset', st, dataset='USED', position=p_used, /addcmd, winid=winid_m,/negative_only, _extra=_extra & cmdind_m+=1
                ;Refreshing the negative_only plot ONLY if there is data. If not do nothing
5f04fa07   Ilyes Choubani   general update
394
                cgwindow,'dustemcgwin_dataset', st, dustem_used,U_spec,SED_spec, dataset='USED',/negative_only, /refresh ,position=p_used, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
395
396
397
398
                
                !dustemcgwin_ncmds.used.pl = cmdind_m
                
                cgwindow,'dustemcgwin_dataset', st, dataset='USED',/norm, position=np_used, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1 ;I think nodata can also be uused too
5f04fa07   Ilyes Choubani   general update
399
                cgwindow,'dustemcgwin_dataset', st, dustem_used,U_spec,SED_spec, dataset='USED', /norm, /refresh,position=np_used, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
400
                !dustemcgwin_ncmds.used.nrm = cmdind_m
5f04fa07   Ilyes Choubani   general update
401
                
18e4331f   Ilyes Choubani   general update (f...
402
403
404
405
406
407
        endelse       
      endelse
      
      if ~test_psi_em then begin ; psi_em data is not present (For completeness) # This is only valid when !run_pol=1
          
          cgwindow,'dustemcgwin_dataset', st, dataset='psi_em', /nodata, position=p_psised, /addcmd, winid=winid_m, _extra=_extra  & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
408
409
410
411
412

      endif else begin ;psi_em exists

         if  ~iswinsed then begin
             cmdind_m = !dustemcgwin_ncmds.psi_em.pl
5f04fa07   Ilyes Choubani   general update
413
             cgwindow,'dustemcgwin_dataset', st, dustem_psi_em,PSI_spec,SED_spec, dataset='psi_em', /refresh ,position=p_psised, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
af5bca1f   Ilyes Choubani   general update
414
             
18e4331f   Ilyes Choubani   general update (f...
415
416
417
         endif else begin
         ;stop
             cgwindow,'dustemcgwin_dataset', st, dataset='psi_em', position=p_psised, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
418
             cgwindow,'dustemcgwin_dataset', st, dustem_psi_em,PSI_spec,SED_spec, dataset='psi_em', /refresh ,position=p_psised, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
419
             !dustemcgwin_ncmds.psi_em.pl = cmdind_m
af5bca1f   Ilyes Choubani   general update
420

18e4331f   Ilyes Choubani   general update (f...
421
422
         endelse       
      endelse
c8368c6e   Ilyes Choubani   updating plotting...
423
        
18e4331f   Ilyes Choubani   general update (f...
424
425
426
427
      
      if ~test_polsed then begin ; polsed data is not present (For completeness) # This is only valid when !run_pol=1
          
          cgwindow,'dustemcgwin_dataset', st, dataset='polsed', /nodata, position=p_psed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
428
          cgwindow,'dustemcgwin_dataset', st, dataset='polsed', /nodata, /norm, position=np_psed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
429
430
431
432
433

      endif else begin ;polsed exists

         if  ~iswinsed then begin
             cmdind_m = !dustemcgwin_ncmds.polsed.pl
5f04fa07   Ilyes Choubani   general update
434
             cgwindow,'dustemcgwin_dataset', st, dustem_polsed,P_spec, dataset='polsed', /refresh ,position=p_psed, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
18e4331f   Ilyes Choubani   general update (f...
435
             cmdind_m = !dustemcgwin_ncmds.polsed.nrm
5f04fa07   Ilyes Choubani   general update
436
             cgwindow,'dustemcgwin_dataset', st, dustem_polsed,P_spec, dataset='polsed', /norm, /refresh,position=np_psed, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
18e4331f   Ilyes Choubani   general update (f...
437
438
439
         endif else begin
         ;stop
             cgwindow,'dustemcgwin_dataset', st, dataset='polsed', position=p_psed, /addcmd, winid=winid_m, _extra=_extra  & cmdind_m+=1  
5f04fa07   Ilyes Choubani   general update
440
             cgwindow,'dustemcgwin_dataset', st, dustem_polsed,P_spec, dataset='polsed', /refresh ,position=p_psed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
441
442
             !dustemcgwin_ncmds.polsed.pl = cmdind_m
             cgwindow,'dustemcgwin_dataset', st, dataset='polsed',/norm, position=np_psed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1 ;I think nodata can also be upolsed too
5f04fa07   Ilyes Choubani   general update
443
             cgwindow,'dustemcgwin_dataset', st, dustem_polsed,P_spec, dataset='polsed', /norm, /refresh,position=np_psed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
444
445
446
             !dustemcgwin_ncmds.polsed.nrm = cmdind_m
         endelse       
      endelse      
af5bca1f   Ilyes Choubani   general update
447
448
      
      
af5bca1f   Ilyes Choubani   general update
449
450
451
      if ~test_polfrac then begin ; polfrac data is not present (For completeness) # This is only valid when !run_pol=1
          
          cgwindow,'dustemcgwin_dataset', st, dataset='polfrac', /nodata, position=p_spsed, /addcmd, winid=winid_m, _extra=_extra  & cmdind_m+=1
18e4331f   Ilyes Choubani   general update (f...
452

af5bca1f   Ilyes Choubani   general update
453
      endif else begin ;polfrac exists
18e4331f   Ilyes Choubani   general update (f...
454

af5bca1f   Ilyes Choubani   general update
455
456
         if  ~iswinsed then begin
             cmdind_m = !dustemcgwin_ncmds.polfrac.pl
5f04fa07   Ilyes Choubani   general update
457
             cgwindow,'dustemcgwin_dataset', st, dustem_polfrac,SP_spec,SED_spec, dataset='polfrac', /refresh ,position=p_spsed, winid=winid_m,/replacecmd,cmdindex=cmdind_m, _extra=_extra
af5bca1f   Ilyes Choubani   general update
458
459
460
461
             
         endif else begin
         ;stop
             cgwindow,'dustemcgwin_dataset', st, dataset='polfrac', position=p_spsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
5f04fa07   Ilyes Choubani   general update
462
             cgwindow,'dustemcgwin_dataset', st, dustem_polfrac,SP_spec,SED_spec, dataset='polfrac', /refresh ,position=p_spsed, /addcmd, winid=winid_m, _extra=_extra & cmdind_m+=1
af5bca1f   Ilyes Choubani   general update
463
             !dustemcgwin_ncmds.polfrac.pl = cmdind_m
18e4331f   Ilyes Choubani   general update (f...
464

af5bca1f   Ilyes Choubani   general update
465
466
         endelse       
      endelse  
5f04fa07   Ilyes Choubani   general update
467
      
18e4331f   Ilyes Choubani   general update (f...
468

5f04fa07   Ilyes Choubani   general update
469
470
    ENDIF
        
c8368c6e   Ilyes Choubani   updating plotting...
471
    end_m:
2910e8ce   Ilyes Choubani   Draft version of ...
472
    
2910e8ce   Ilyes Choubani   Draft version of ...
473
474
475
476
477
478
479
480
481
482
483
    ;cgcontrol, update=1
;     varrr=cgquery(dimensions=dim_m) ;be careful because the dim_m array can be multi-dimensional because of the presence of two windows.
;     cgcontrol, update=1
;     cgcontrol, resize=[dim_m(0),dim_m(1)]
;     
    ;cgcontrol, resize=1
;     cgcontrol,update=1
;     cgcontrol,update=1
        
;     cgcontrol, resize=[!D.X_SIZE,!D.Y_SIZE]
    
2910e8ce   Ilyes Choubani   Draft version of ...
484
    ;cgcontrol, update=1
5f04fa07   Ilyes Choubani   general update
485
486
487
488
489
490
491
492
    ;cgcontrol, update=0
    
    
 ;   cgcontrol, update=1 
    
    
    
    
2910e8ce   Ilyes Choubani   Draft version of ...
493
    ;varr=cgquery(dimensions=dim_m,objectref=winobj_m)
18e4331f   Ilyes Choubani   general update (f...
494
   ;stop
5f04fa07   Ilyes Choubani   general update
495
496
    cgcontrol, winid_m, execute=1
    ;cgcontrol, winid_m, execute=0      
2910e8ce   Ilyes Choubani   Draft version of ...
497
         
5f04fa07   Ilyes Choubani   general update
498
499
500
501
502
503
504
ENDIF 


;Plotting of the parameter and plugin values / This will have to be placed after the extinction block which hasn't been 
;written yet. 

;This block will be different because it does not depend on wether dustemwrap is used in polarization or not
af5bca1f   Ilyes Choubani   general update
505
506


2910e8ce   Ilyes Choubani   Draft version of ...
507
;stop
5f04fa07   Ilyes Choubani   general update
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
;Plotting the parameter window 
;cgcontrol, execute=0
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
    cgwindow,'dustemcgwin_dataset', st, res, errors, p_dim,dataset='PARAMETERS', /refresh, winid=winid_prms,/replacecmd,cmdindex=cmdind_prms, _extra=_extra
    cgcontrol, winid_prms ,execute=1 
ENDIF ELSE BEGIN ;(FIRST RUN)
    cgwindow,wxsize=350,wysize=200,wtitle='DUSTEMWRAP v2.0 (PARAMETERS)' ; keeping the same y dimension of the emission/extinction plot? 
    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
    cgwindow,'dustemcgwin_dataset', st, res, errors, p_dim,dataset='PARAMETERS', /addcmd , winid=winid_prms,_extra=_extra ;& cmdind_prms+=1
    cgwindow,'dustemcgwin_dataset', st, res, errors, p_dim,dataset='PARAMETERS', /addcmd, /refresh , winid=winid_prms, _extra=_extra & cmdind_prms+=1
    !dustemcgwin_ncmds.prms.pl = cmdind_prms
    cgcontrol, winid_prms ,execute=1        
ENDELSE 

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
    cgwindow,'dustemcgwin_dataset', st, res, errors, p_dim,dataset='PLUGINS', /refresh, winid=winid_plgns,/replacecmd,cmdindex=cmdind_plgns, _extra=_extra
    cgcontrol, winid_plgns ,execute=1 
ENDIF ELSE BEGIN ;(FIRST RUN)
    cgwindow,wxsize=350,wysize=200,wtitle='DUSTEMWRAP v2.0 (PLUGINS)' ; keeping the same y dimension of the emission/extinction plot? 
    winid_plgns = cgquery(dimensions=dim_plgns,/current) ;we don't need the dimension of the window so far/ I don't know why I needed it before
    cgcontrol, winid_plgns, execute=0
    !dustemcgwin_id.plgns = winid_plgns
    cgwindow,'dustemcgwin_dataset', st, res, errors, p_dim,dataset='PLUGINS', /addcmd , winid=winid_plgns,_extra=_extra ;& cmdind_prms+=1
    cgwindow,'dustemcgwin_dataset', st, res, errors, p_dim,dataset='PLUGINS', /addcmd, /refresh , winid=winid_plgns, _extra=_extra & cmdind_plgns+=1
    !dustemcgwin_ncmds.plgns.pl = cmdind_plgns
    cgcontrol, winid_plgns ,execute=1        
ENDELSE 
2910e8ce   Ilyes Choubani   Draft version of ...
547
548


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