-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspectrum_plot.pro
More file actions
1725 lines (1550 loc) · 88.3 KB
/
spectrum_plot.pro
File metadata and controls
1725 lines (1550 loc) · 88.3 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
183
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; Copyright 2018 Euratom/CCFE/TuE
;; Permission is hereby granted, free of charge, to any person obtaining a copy of this
;; software and associated documentation files (the "Software"), to deal in the Software
;; without restriction, including without limitation the rights to use, copy, modify,
;; merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
;; permit persons to whom the Software is furnished to do so, subject to the following
;; conditions:
;; The above copyright notice and this permission notice shall be included in all copies
;; or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
;; INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
;; PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
;; OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
pro spectrum_plot, settingfile, inputfile, prefix, pictdir
; routine plots the data form the given inputfile (xdr-format)
; this data can be:
; - the 3D geometry of the MSE system
; - the emission in the (R,Z)-plane, as function of R andof psi
; - the spatial resolution
; - the spectra with the different polarised and unpolarised intensities
; - the polasitation angle
; - the polarised fraction and intensity
;
; what data is plotted and how it is plotted depends on the settings in the setting file
;
; The 'prefix' is added in front of the title of each plot and (if a Postscript file
; is created) in front of the figures-filename.
;
; Postscript files are saved in the 'pictdir'-directory
;
; v1.0, mdebock 18/07/2007
;
; v1.1, mdebock 25/07/2007: * polarised intensity is now: pol. frac * sqrt(total int.)
; because that gives a figure-of-merit for the S/N ratio
; * some output data is printed to the screen
;
; v1.2, mdebock 31/07/2007: * Settings for character size, line thickness, ... now depends
; on whether we plot to the screen or an EPS-file is written.
;
; v2.0, mdebock 07/08/2008: * Update to use Stokes vectors as input
; * also plots intensity, polarisation angle and polarised fraction profile
; for at the CWL (i.e. centre of the sigma or the filter CWL)
; v2.1, mdebock 18/07/2011: * Better determination of the wavelength range
; * Better handling of colours and EPS/X-window plotting with the init_graphic and truecolor functions
; v2.2, daussems 29/09/2011: * Ideal 1D MSE angle now indicated + deviation from full modelling
; mdebock * Position optimal pi-red, sigma and pi-blue now determined outside spectrum plot
; * Extra profile plots at optimal pi-red, sigma and pi-blue (CWL is of course still there)
; * Windows/Unix compatibility ensured
; v2.3, pgeelen 09/02/2012: * Update to use 4D Stokes vectors as input
; mdebock
;
;**********************************************************************************
;* READ IN PLOT SETTINGS AND DATA *
;**********************************************************************************
;----------------------------------------------------------------------------------
; Distinguish between Windows and UNIX directory separators
;----------------------------------------------------------------------------------
if strcmp( !version.os,'Win32',/fold_case) then sep='\' else sep='/'
;----------------------------------------------------------------------------------
; we will put the info that is printed to the screen also in a html file
; (is easy to write and can easily be converted in postscript or pdf)
;----------------------------------------------------------------------------------
; the filename of the inputfile without path or extension
inputtxt = inputfile
print,'input text', inputfile
lastdir = strpos(inputtxt, sep, /REVERSE_SEARCH)
inputtxt = strmid(inputtxt,lastdir+1)
ext = strpos(inputtxt, '.', /REVERSE_SEARCH)
inputtxt = strmid(inputtxt,0,ext)
print,'inputtxt',inputtxt
; name of the textfile
txtfile = pictdir+sep+inputtxt+'.html'
; open the file
get_lun, funit
openw, funit, txtfile
printf, funit, '<html>'
printf, funit, '<head>'
printf, funit, '<title>Output data of '+inputtxt+'.xdr</title>'
printf, funit, '<style type="text/css">'
printf, funit, '<!--'
printf, funit, ' h1 {font-size: 150%; }'
printf, funit, ' h2 {font-size: 125%; }'
printf, funit, '-->'
printf, funit, '</style>'
printf, funit, '</head>'
printf, funit, '<body>'
printf, funit, '<h1>Output data "'+inputtxt+'.xdr"</h1>
;----------------------------------------------------------------------------------
; print some info on what's happening to the screen
;----------------------------------------------------------------------------------
print,FORMAT= '("* Plotting ",(A-25))', inputtxt+'.xdr'
print,FORMAT='($," - reading data ....")'
;----------------------------------------------------------------------------------
; Read the plot settings
;----------------------------------------------------------------------------------
input = read_setting(settingfile)
;----------------------------------------------------------------------------------
; Read the data
;----------------------------------------------------------------------------------
restore, inputfile
print,FORMAT='("... done!")'
; get some inportant data
nchan = n_elements(gp_xyz[0,0,*])
gp_n = n_elements(gp_xyz[0,*,0])
nR = n_elements(R)
nZ = n_elements(Z)
npsi = n_elements(psi)
nlambda = n_elements(lambda)
dlambda = lambda[1] - lambda[0]
;**********************************************************************************
;* PREPARE FOR PLOTTING OR PRINTING *
;**********************************************************************************
case input.general.plot_print of
0: return ; no plotting or printing required
1: begin
epsfig = 0
; font 'complex roman' the X plots
fontname = 'complex roman'
end
2: begin
epsfig=1
; We don't want white spaces in filenames, so we replace all ' ' by '_' in the
; prefix for the ps-filename
i = 0
psprefix = prefix
while 1 do begin
i = strpos(psprefix,' ',i+1)
if i eq -1 then break
strput, psprefix, '_', i
endwhile
; font 'times' the EPS plots
fontname = 'times'
end
endcase
;**********************************************************************************
;* PLOT MSE SYSTEM GEOMETRY IN 3D *
;**********************************************************************************
if input.geom.geomplot then begin
;----------------------------------------------------------------------------------
; open a device and plot the 3D axis
;----------------------------------------------------------------------------------
; get centre, zoom and rotation for the 3D axis
centre = input.geom.centre
zoom = input.geom.zoom
rotation = input.geom.rotation
; set aspect ratio, figure zoom, fontsize and line thickness
aspect = 1
figzoom = 1.2
fontsize = 16
lth = 2.0
; make the figures title
ttl = prefix+' - MSE system geometry in 3D'
; open a device for plotting the MSE geometry
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom, title=ttl)
endif
if (input.general.plot_print eq 2) then begin
fname = pictdir+'/'+psprefix+'_MSE_geometry.eps'
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi=0
!p.background=truecolor('white') ; use a white background
!p.color =truecolor('black') ; use a black foreground
; plot a 3D-axis
plot_axis, centre, zoom, rotation, ttl, lth
;----------------------------------------------------------------------------------
; plot a beam wireframe is requested
;----------------------------------------------------------------------------------
if input.geom.beamplot then begin
; the beam range is chosen to be 20% more than the distance
; between the first maximum and minimum radius
dRmax = quadroots([ B_xyz[0]^2 + B_xyz[1]^2 - max(R)^2 ,$
2*(B_xyz[0]*B_vec[0] + B_xyz[1]*B_vec[1]),$
B_vec[0]^2 + B_vec[1]^2])
dRmax = min(dRmax)
dRmin = quadroots([ B_xyz[0]^2 + B_xyz[1]^2 - min(R)^2 ,$
2*(B_xyz[0]*B_vec[0] + B_xyz[1]*B_vec[1]),$
B_vec[0]^2 + B_vec[1]^2])
dRmin = min(dRmin)
B_range = [dRmax - 0.1*(dRmin-dRmax),$
dRmin + 0.1*(dRmin-dRmax) ]
plot_beam, B_xyz, B_vec, B_range, B_w
endif
;----------------------------------------------------------------------------------
; plot the grid points if requested
;----------------------------------------------------------------------------------
colors = truecolor(/help)
if input.geom.gpplot then begin
for k=1,nchan do begin
plots, gp_xyz[0,*,nchan-k], gp_xyz[1,*,nchan-k], gp_xyz[2,*,nchan-k],$
color=truecolor(colors[k mod n_elements(colors)]), psym=1, thick=0.5*lth, symsize=csz, /T3D, noclip=0
endfor
endif
;----------------------------------------------------------------------------------
; plot the B-field (T) if requested
;----------------------------------------------------------------------------------
if input.geom.Bfldplot then begin
for k=1,nchan do begin
for gp_c=0,gp_n-1 do begin
plots, [gp_xyz[0,gp_c,nchan-k], gp_xyz[0,gp_c,nchan-k]+gp_Bfld[0,gp_c,nchan-k]],$
[gp_xyz[1,gp_c,nchan-k], gp_xyz[1,gp_c,nchan-k]+gp_Bfld[1,gp_c,nchan-k]],$
[gp_xyz[2,gp_c,nchan-k], gp_xyz[2,gp_c,nchan-k]+gp_Bfld[2,gp_c,nchan-k]],$
color=truecolor('blue'), thick=lth, /T3D, noclip=0
endfor
endfor
endif
;----------------------------------------------------------------------------------
; plot beam particle velocity (1e7 m/s) if requested
;----------------------------------------------------------------------------------
if input.geom.velplot then begin
for k=1,nchan do begin
for gp_c=0,gp_n-1 do begin
plots, [gp_xyz[0,gp_c,nchan-k], gp_xyz[0,gp_c,nchan-k]+B_v0*gp_vel[0,gp_c,nchan-k]*1e-7],$
[gp_xyz[1,gp_c,nchan-k], gp_xyz[1,gp_c,nchan-k]+B_v0*gp_vel[1,gp_c,nchan-k]*1e-7],$
[gp_xyz[2,gp_c,nchan-k], gp_xyz[2,gp_c,nchan-k]+B_v0*gp_vel[2,gp_c,nchan-k]*1e-7],$
color=truecolor('red'), thick=lth, /T3D, noclip=0
endfor
endfor
endif
;----------------------------------------------------------------------------------
; plot E-field (1e7 V/m) if requested
;----------------------------------------------------------------------------------
if input.geom.Efldplot then begin
for k=1,nchan do begin
for gp_c=0,gp_n-1 do begin
plots, [gp_xyz[0,gp_c,nchan-k], gp_xyz[0,gp_c,nchan-k]+gp_Efld[0,gp_c,nchan-k]*1e-7],$
[gp_xyz[1,gp_c,nchan-k], gp_xyz[1,gp_c,nchan-k]+gp_Efld[1,gp_c,nchan-k]*1e-7],$
[gp_xyz[2,gp_c,nchan-k], gp_xyz[2,gp_c,nchan-k]+gp_Efld[2,gp_c,nchan-k]*1e-7],$
color=truecolor('green'), thick=lth, /T3D, noclip=0
endfor
endfor
endif
;----------------------------------------------------------------------------------
; plot beam emission if requested
;----------------------------------------------------------------------------------
if input.geom.emisplot then begin
; load a colour tabel
if !d.name eq 'X' then begin
device, get_decomp=decomp
device, decomp=0
endif
loadct, 5, /silent
n_colors = !d.table_size
; get the colour scaling
emismax = max(gp_emis)
emismin = min(gp_emis)
if abs(emismax-emismin) gt 1e-6 then cfactor = (n_colors-1.)/(emismax-emismin)$
else cfactor = (n_colors-1.)/(2.*emismax)
for k=1,nchan do begin
for gp_c=0l,gp_n-1 do begin
coloridx = round(cfactor*(gp_emis[gp_c,nchan-k]-emismin))
plots, gp_xyz[0,gp_c,nchan-k],gp_xyz[1,gp_c,nchan-k],gp_xyz[2,gp_c,nchan-k],$
color=coloridx, psym=1, thick=0.5*lth, symsize=csz, /T3D
endfor
endfor
if !d.name eq 'X' then device, decomp=decomp
endif
;----------------------------------------------------------------------------------
; close the figure
;----------------------------------------------------------------------------------
tmp = reset_graphic(figID, eps=epsfig)
!p.multi = 0
endif
;**********************************************************************************
;* PLOT THE EMISSION INTENSITY AND SPATIAL RESOLUTION *
;**********************************************************************************
;----------------------------------------------------------------------------------
; plot the beam emission in a RZ-plane if requested
;----------------------------------------------------------------------------------
if input.emisres.emisRZplot then begin
; make the figures title
ttl = prefix+' - Beam emission in the RZ-plane'
; set aspect ratio, figure zoom, fontsize and line thickness
if nR ge nZ then aspect = 1.6 else aspect = 0.7
figzoom = 2.0
fontsize = 14
lth = 2.0
; open a device for plotting the RZ emission
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom, title=ttl)
!p.background=truecolor('white') ; use a white background
!p.color =truecolor('black') ; use a black foreground
endif
if (input.general.plot_print eq 2) then begin
fname = pictdir+'/'+psprefix+'_RZ_emission.eps'
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, /PSfont, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi=0
!p.background=truecolor('white') ; use a white background
!p.color =truecolor('black') ; use a black foreground
; add up the RZ-emission data for all each channels
; the colorscale
RZ_total =fltarr(nR,nZ)
for k=0,nchan-1 do begin
if max(RZ_emis[*,*,k]) gt 0.0 then begin
RZ_total += RZ_emis[*,*,k]
endif
endfor
; plot the shaded contour plot
cp_shaded, RZ_total, R, Z, /isotropic, xtitle='R [m]', ytitle='Z [m]', ztitle='Intensity [photons/s/m^2]',$
title=ttl, zr=[0,max(RZ_total)],ctable=3, /invert, /showscale ; pixels=4096
; overlay the fluxsurfaces and plot the magnetic axis
contour,RZpsi,R,Z, levels=0.1*(1+findgen(10)),c_labels=1+intarr(10),$
/overplot,color=0,thick=lth,xs=1,ys=1
plots,Rm,0.0, psym=1, color=0,thick=lth
; close the figure
tmp = reset_graphic(figID, eps=epsfig)
!p.multi = 0
endif
;----------------------------------------------------------------------------------
; plot the beam emission as function of psi and R if requested
;----------------------------------------------------------------------------------
if input.emisres.emisPsiRplot then begin
; make the figures title
ttl = prefix+' - Beam emission intensity as function of ' + textoidl('\psi') + ' and R'
; set aspect ratio, figure zoom, fontsize and line thickness
aspect = 0.8
figzoom = 1.2
fontsize = 12
lth = 2.0
; open a device for plotting the emission as function of R and psi
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom, title=ttl)
endif
if (input.general.plot_print eq 2) then begin
fname = pictdir+'/'+psprefix+'_emission_psi_R.eps'
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, /PSfont, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi = [0,1,2]
!p.background=truecolor('white') ; use a white background
!p.color =truecolor('black') ; use a black foreground
; plot the axis for emitted intensity as function of psi
ttl = prefix+' - Beam emission intensity as function of ' + textoidl('\psi')
plot, [0,1.0],[0,1.2*max(psi_emis)],/nodata,xs=1,ys=1, $
xtitle='normalised flux coordinate '+textoidl('\psi'), $
ytitle='Intensity [photons/s/' + textoidl('\psi') + ']', $
title =ttl
; loop through the channels to plot the emitted intensity for each of them
for k =0,nchan-1 do begin
; color the area underneath the emission white
polyfill,[psi,reverse(psi)],$
[psi_emis[*,k],replicate(0.0,n_elements(psi))],$
color=truecolor('white')
; color the area that is used for the determination of the spatial resolution gray
idx = where( (psi ge psi_res[3,k]) AND (psi le psi_res[4,k]), count)
if count ne 0 then begin
polyfill,[psi[idx],reverse(psi[idx])], $
[psi_emis[idx,k],replicate(0.0,count)], $
color=truecolor('gray')
endif
; plot the emission
oplot, psi, psi_emis[*,k], thick=lth, linestyle=0
; plot the centre-of-mass psi
mntmp = min( abs(psi-psi_res[2,k]), idx)
oplot, [psi[idx],psi[idx]],[0,psi_emis[idx,k]],thick=1, linestyle=0
; plot the central psi
mntmp = min( abs(psi-psi_res[0,k]), idx)
oplot, [psi[idx],psi[idx]],[0,psi_emis[idx,k]],thick=1, linestyle=2
; plot the psi at maximum
mntmp = min( abs(psi-psi_res[1,k]), idx)
oplot, [psi[idx],psi[idx]],[0,psi_emis[idx,k]],thick=1, linestyle=4
endfor
; plot the legend
makelegend, ['centre of mass', 'central point', 'maximum'],$
linestyle=[0,2,4], thick=[1,1,1], /box, /top, /left
; plot the axis for emitted intensity as function of R
ttl = prefix+' - Beam emission intensity as function of R'
plot, [min(R),max(R)],[0,1.2*max(R_emis)],/nodata,xs=1,ys=1,$
xtitle='R [m]', ytitle='Intensity [photons/s/m]', title =ttl
; loop through the channels to plot the emitted intensity for each of them
for k =0,nchan-1 do begin
; color the area underneath the emission white
polyfill,[R,reverse(R)],$
[R_emis[*,k],replicate(0.0,n_elements(R))],$
color=truecolor('white')
; color the area that is used for the determination of the spatial resolution gray
idx = where( (R ge R_res[3,k]) AND (R le R_res[4,k]) , count)
if count ne 0 then begin
polyfill,[R[idx],reverse(R[idx])], $
[R_emis[idx,k],replicate(0.0,n_elements(idx))], $
color=truecolor('gray')
endif
; plot the emission
oplot, R, R_emis[*,k], thick=lth
; plot the centre-of-mass R
mntmp = min( abs(R-R_res[2,k]), idx)
oplot, [R[idx],R[idx]],[0,R_emis[idx,k]],thick=1, linestyle=0
; plot the central R
mntmp = min( abs(R-R_res[0,k]), idx)
oplot, [R[idx],R[idx]],[0,R_emis[idx,k]],thick=1, linestyle=2
; plot the R at maximum
mntmp = min( abs(R-R_res[1,k]), idx)
oplot, [R[idx],R[idx]],[0,R_emis[idx,k]],thick=1, linestyle=4
endfor
; legend
makelegend, ['centre of mass', 'central point', 'maximum'],$
linestyle=[0,2,4], thick=[1,1,1], /box, /top, /left
; close the figure
tmp = reset_graphic(figID, eps=epsfig)
!p.multi = 0
endif
;----------------------------------------------------------------------------------
; plot the total emission intensity as function of psi and R if requested
;----------------------------------------------------------------------------------
if input.emisres.temisplot then begin
; make the figures title
ttl = prefix+' - Total emission intensity as function of '+ textoidl('\psi') + ' and R'
; set aspect ratio, figure zoom, fontsize and line thickness
aspect = 0.8
figzoom = 1.2
fontsize = 12
lth = 2.0
; open a device for plotting the total emission as function of R and psi
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom, title=ttl)
endif
if (input.general.plot_print eq 2) then begin
fname = pictdir+'/'+psprefix+'_total_emission_psi_R.eps'
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, /PSfont, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi = [0,1,2]
!p.background=truecolor('white') ; use a white background
!p.color =truecolor('black') ; use a black foreground
; calculate the total emission intensity
dR = R[1] - R[0]
dpsi = psi[1] - psi[0]
R_temis = total(R_emis,1)*dR
psi_temis = total(psi_emis,1)*dpsi
; plot the total emission as function of psi
ttl = prefix+' - Total emission intensity as function of ' + textoidl('\psi')
xmin = 0
xmax = 1
ymin = 0
ymax = 1.2*max(psi_temis)
plot, psi_res[2,*], psi_temis, thick=lth, psym=-1, $
xs=1, xr=[xmin,xmax], ys=1, yr=[ymin,ymax], $
xtitle='normalised flux coordinate '+ textoidl('\psi') +' at Centre of Mass',$
ytitle='intensity [photons/s]', title=ttl
; plot the total emission as function of R
ttl = prefix+' - Total emission intensity as function of R'
xmin = min(R)
xmax = max(R)
ymin = 0
ymax = 1.2*max(R_temis)
plot, R_res[2,*], R_temis, thick=lth, psym=-1, $
xs=1, xr=[xmin,xmax], ys=1, yr=[ymin,ymax],$
xtitle='R - Centre of Mass [m]', $
ytitle='intensity [photons/s]', title=ttl
; close the figure
tmp = reset_graphic(figID, eps=epsfig)
!p.multi = 0
;----------------------------------------------------------------------------------
; print some information to the screen and the html-file
;----------------------------------------------------------------------------------
print,''
printf, funit,'<h2>Total emission intensity</h2>'
printf, funit,'<p align="center"><table width="95%" border="0" cellspacing="0" cellpadding="0">'
for k =0,nchan-1 do begin
print,format='(" - total emitted intensity channel ",A," : ",(E9.2)," (from R), ",(E9.2)," (from psi)")',$
chanID[k], total(R_emis[*,k])*dR, total(psi_emis[*,k])*dpsi
printf,funit,'<tr><td width="37%" align="left">'
printf,funit,format='("total emitted intensity channel ",A)',chanID[k]
printf,funit,'</td><td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((E9.2)," (from R), ",(E9.2)," (from psi)")',R_temis[k], psi_temis[k]
printf,funit,'</td></tr>'
endfor
print,format='(" - average emitted intensity : ",(E9.2)," (from R), ",(E9.2)," (from psi)")',$
mean(R_temis), mean(psi_temis)
printf,funit,'<tr height="7"><td width="37%" align="left"> </td><td width="5%" align="center"> </td>'
printf,funit,'<td width="58%" align="left"> </td></tr>'
printf,funit,'<tr><td width="37%" align="left">'
printf,funit,format='("average emitted intensity")'
printf,funit,'</td><td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((E9.2)," (from R), ",(E9.2)," (from psi)")', mean(R_temis), mean(psi_temis)
printf,funit,'</td></tr>'
printf,funit,'</table></p>'
endif
;----------------------------------------------------------------------------------
; plot the spatial resolution as function of psi and R if requested
;----------------------------------------------------------------------------------
if input.emisres.resplot then begin
; make the figures title
ttl = prefix+' - Spatial resolution as function of '+ textoidl('\psi') + ' and R'
; set aspect ratio, figure zoom, fontsize and line thickness
aspect = 0.8
figzoom = 1.2
fontsize = 12
lth = 2.0
; open a device for plotting the spatial resolution as function of R and psi
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom, title=ttl)
endif
if (input.general.plot_print eq 2) then begin
fname = pictdir+'/'+psprefix+'_spat_resolution_psi_R.eps'
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, /PSfont, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi = [0,1,2]
!p.background=truecolor('white') ; use a white background
!p.color =truecolor('black') ; use a black foreground
; plot the resolution as function of psi
ttl = prefix+' - Spatial resolution as function of ' + textoidl('\psi')
yttl= 'Spatial resolution ['+textoidl('\psi')+ '] - ' + string(format='(I2)',round(100*psi_res[6,0])) +'% emitted'
xmin = 0
xmax = 1
ymin = 0
ymax = 1.5*max(psi_res[5,*])
plot, psi_res[2,*], psi_res[5,*], thick=lth, psym=-1, $
xs=1, xr=[xmin,xmax], ys=1, yr=[ymin,ymax], $
xtitle='normalised flux coordinate '+ textoidl('\psi') +' at Centre of Mass',$
ytitle=yttl, title=ttl
; plot the resolution as function of R
ttl = prefix+' - Spatial resolution as function of R'
yttl= 'Spatial resolution [m] - ' + string(format='(I2)',round(100*psi_res[6,0])) +'% emitted'
xmin = min(R)
xmax = max(R)
ymin = 0
ymax = 1.5*max(R_res[5,*])
plot, R_res[2,*], R_res[5,*], thick=lth, psym=-1,$
xs=1, xr=[xmin,xmax], ys=1, yr=[ymin,ymax],$
xtitle='R - Centre of Mass [m]', $
ytitle=yttl, title=ttl
; close the figure
tmp = reset_graphic(figID, eps=epsfig)
!p.multi = 0
;----------------------------------------------------------------------------------
; print some information to the screen and the html-file
;----------------------------------------------------------------------------------
print,''
printf, funit,'<h2>Spatial resolution</h2>'
printf, funit,'<p align="center"><table width="95%" border="0" cellspacing="0" cellpadding="0">'
for k =0,nchan-1 do begin
print,format='(" - spatial resolution channel ",A," : ",(F6.3)," (m) , ",(F6.3)," (psi)")',$
chanID[k], R_res[5,k], psi_res[5,k]
printf,funit,'<tr><td width="37%" align="left">'
printf,funit,format='("spatial resolution channel ",A)',chanID[k]
printf,funit,'</td><td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((F6.3)," (m) , ",(F6.3)," (psi)")', R_res[5,k], psi_res[5,k]
printf,funit,'</td></tr>'
endfor
print,format='(" - average spatial resolution : ",(F6.3)," (m) , ",(F6.3)," (psi)")',$
total(R_res[5,*])/nchan, total(psi_res[5,*])/nchan
printf,funit,'<tr height="7"><td width="37%" align="left"> </td><td width="5%" align="center"> </td>'
printf,funit,'<td width="58%" align="left"> </td></tr>' ;<spacer height="10" type="block">
printf,funit,'<tr><td width="37%" align="left">'
printf,funit,format='("average spatial resolution")'
printf,funit,'</td><td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((F6.3)," (m) , ",(F6.3)," (psi)")', total(R_res[5,*])/nchan, total(psi_res[5,*])/nchan
printf,funit,'</td></tr>'
printf,funit,'</table></p>'
endif
;**********************************************************************************
;* PLOT THE SPECTRA *
;**********************************************************************************
;----------------------------------------------------------------------------------
; Only plot spectral data if requested
;----------------------------------------------------------------------------------
if input.spec.spectrum || input.spec.polangle || input.spec.polfrac then begin
; loop through the channels
for k=0,nchan-1 do begin
;----------------------------------------------------------------------------------
; If multiplot is selected and some spectral plotting is requested,
; then we open a device for plotting here.
;----------------------------------------------------------------------------------
nplots=1.
if (input.spec.multiplot) then begin
nplots=0.
if input.spec.spectrum then nplots++
if input.spec.polangle then nplots++
if input.spec.polfrac then nplots++
; make the figures title
if R_res[2,k] lt 10 then ttl = string(format='(" - Channel ",A," at R=",(F4.2),"m / '+textoidl('\psi')+'=",(F4.2))',$
chanID[k],R_res[2,k],psi_res[2,k]) $
else ttl = string(format='(" - Channel ",A," at R=",(I0),"m")', $
chanID[k],R_res[2,k])
ttl = prefix+ttl
; set aspect ratio, figure zoom, fontsize and line thickness
aspect = 2.5/sqrt(nplots*3.)
figzoom = 1.2
fontsize = 12*sqrt(nplots)
lth = 2.0
; open a device for plotting the spectra as function of R and psi
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom, title=ttl)
endif
if (input.general.plot_print eq 2) then begin
if R_res[2,k] lt 10 then fname = string(format='("_chan",A,"_R",(F4.2),"_psi",(F4.2),".eps")',$
chanID[k],R_res[2,k],psi_res[2,k]) $
else fname = string(format='("_chan",A,"_R",(I0),".eps")', $
chanID[k],R_res[2,k])
fname = pictdir+'/'+psprefix+fname
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, /PSfont, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi=[0,1,nplots]
!p.background=truecolor('white') ; use a white background
!p.color =truecolor('black') ; use a black foreground
!x.margin = [10,9]
endif
;----------------------------------------------------------------------------------
; Convert the Stokes vectors in (nonzero) intensity, polarised fraction,
; polarisation angle and S/N
;----------------------------------------------------------------------------------
nonzero = where(stokes[*,0,k] gt 0.0,count) ; where the total intensity isn't zero
tspec = fltarr(nlambda)
tpspec = fltarr(nlambda)
ppspec = fltarr(nlambda)
puspec = fltarr(nlambda)
spspec = fltarr(nlambda)
suspec = fltarr(nlambda)
tpfrac = fltarr(nlambda)+1.0
SN = fltarr(nlambda)
pgamma = fltarr(nlambda)
sgamma = fltarr(nlambda)
gamma = fltarr(nlambda)
if count ne 0 then begin
tspec[nonzero] = stokes[nonzero,0,k]
tpspec[nonzero] = sqrt(stokes[nonzero,1,k]^2+stokes[nonzero,2,k]^2) ;Total linear polarization intensity
ppspec[nonzero] = sqrt(pstokes[nonzero,1,k]^2+pstokes[nonzero,2,k]^2) ;Linear polarization intensity of the pi-lines
puspec[nonzero] = pstokes[nonzero,0,k] - sqrt(pstokes[nonzero,1,k]^2+pstokes[nonzero,2,k]^2) ; Circular polarization intensity + unpolarized intensity of the pi-lines
spspec[nonzero] = sqrt(sstokes[nonzero,1,k]^2+sstokes[nonzero,2,k]^2) ;sigma linear polarization intensity
suspec[nonzero] = sstokes[nonzero,0,k] - sqrt(sstokes[nonzero,1,k]^2+sstokes[nonzero,2,k]^2) ;sigma unpolarised
tpfrac[nonzero] = tpspec[nonzero]/tspec[nonzero] ;total polarised fraction
SN[nonzero] = tpspec[nonzero]/sqrt(tspec[nonzero]) ;signal to noise
tpnonzero = where(tpspec gt 0.0) ; where the total polarised intensity,
ppnonzero = where(ppspec gt 0.0) ; the polarised pi-intensity
spnonzero = where(spspec gt 0.0) ; and the polarised sigma-intensity isn't zero
pgamma[ppnonzero] = 0.5*atan(pstokes[ppnonzero,2,k],pstokes[ppnonzero,1,k])*!radeg
sgamma[spnonzero] = 0.5*atan(sstokes[spnonzero,2,k],sstokes[spnonzero,1,k])*!radeg
gamma[tpnonzero] = 0.5*atan(stokes[tpnonzero,2,k],stokes[tpnonzero,1,k])*!radeg
endif
;----------------------------------------------------------------------------------
; Set the wavelength limits for the plotting
;----------------------------------------------------------------------------------
range = where(stokes[*,0,k]-min(stokes[*,0,k]) gt 0.05*(max(stokes[*,0,k])-min(stokes[*,0,k])),nrange) ; where the intensity is larger than
if nrange ne 0 then begin ; 5% of the difference between maximum
lambdamin = lambda[range[0]]-4.0 ; and minimum intensity
lambdamax = lambda[range[nrange-1]]+4.0
endif else begin
lambdamin = lambda0+Dshift0[k]-4.0
lambdamax = lambda0+Dshift0[k]+4.0
endelse
;----------------------------------------------------------------------------------
; Locate the CWL and the wavelengths of max. pi-blue, max. sigma and max.pi-red
;----------------------------------------------------------------------------------
tmp = min(abs(lambda-cwlstokes[4,k]),cwlidx)
tmp = min(abs(lambda-pibstokes[4,k]),pbidx)
tmp = min(abs(lambda-sigstokes[4,k]),sidx)
tmp = min(abs(lambda-pirstokes[4,k]),pridx)
;----------------------------------------------------------------------------------
; print some information to the screen and the html-file
;----------------------------------------------------------------------------------
print,''
print,format='(" - Spectral information for channel ",A," at R=",F4.2,"m")',chanID[k],R_res[2,k]
printf, funit,format='("<h2>Spectral information for channel ",A," at R=",F4.2,"m</h2>")',chanID[k],R_res[2,k]
;----------------------------------------------------------------------------------
; plot spectrum if requested
;----------------------------------------------------------------------------------
if input.spec.spectrum then begin
;----------------------------------------------------------------------------------
; If multiplot is NOT selected, then we open a device for plotting here.
;----------------------------------------------------------------------------------
if ~(input.spec.multiplot) then begin
; set aspect ratio, figure zoom, fontsize and line thickness
aspect = 1.5
figzoom = 1.2
fontsize = 12
lth = 2.0
; open a device for plotting the spectra as function of wavelength
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom)
endif
if (input.general.plot_print eq 2) then begin
if R_res[2,k] lt 10 then fname = string(format='("_spec",A,"_R",(F4.2),"_psi",(F4.2),".eps")',$
chanID[k],R_res[2,k],psi_res[2,k]) $
else fname = string(format='("_spec",A,"_R",(I0),".eps")', $
chanID[k],R_res[2,k])
fname = pictdir+'/'+psprefix+fname
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, /PSfont, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi = 0
!p.background= truecolor('white') ; use a white background
!p.color = truecolor('black') ; use a black foreground
endif
;----------------------------------------------------------------------------------
; make the figures title
;----------------------------------------------------------------------------------
if R_res[2,k] lt 10 then ttl = string(format='(" - Spectrum ",A," at R=",(F4.2),"m / '+textoidl('\psi')+'=",(F4.2))',$
chanID[k],R_res[2,k],psi_res[2,k]) $
else ttl = string(format='(" - Spectrum ",A," at R=",(I0),"m")', $
chanID[k],R_res[2,k])
ttl = prefix+ttl
;----------------------------------------------------------------------------------
; the plotting
;----------------------------------------------------------------------------------
; set y-limits
ymin = 0.
ymax = 1.05 * max(tspec)
; total spectrum
if filterflag eq 0 then yttl='Intensity [photons/s/Angstrom]' else yttl='Intensity [photons/s]'
if filterflag eq 0 then xttl='Wavelength [Angstrom]' else xttl='Filter central wavelength [Angstrom]'
plot, lambda, tspec, color=truecolor('black'), thick=lth, linestyle=0,$
xs=1, xr=[lambdamin,lambdamax], ys=1, yr=[ymin,ymax], $
xtitle=xttl, ytitle=yttl, title=ttl
; pol. pi spectrum
oplot,lambda, ppspec, color=truecolor('blue'), thick=lth, linestyle=2
; pol. sigma spectrum
oplot,lambda, spspec, color=truecolor('red'), thick=lth, linestyle=3
; unpol. pi spectrum
oplot,lambda, puspec, color=truecolor('darkblue'), thick=lth, linestyle=4
; unpol. sigma spectrum
oplot,lambda, suspec, color=truecolor('darkred'), thick=lth, linestyle=5
; indicate the CWL, max. S/N blue shifted pi, red shifted pi and sigma
oplot, [cwlstokes[4,k],cwlstokes[4,k]],[ymin,ymax],color=truecolor('black'),thick=1,linestyle=1
plots, cwlstokes[4,k], cwlstokes[0,k],psym=1,color=truecolor('black'),thick=1, /data
oplot, [pibstokes[4,k],pibstokes[4,k]],[ymin,ymax],color=truecolor('blue'),thick=1,linestyle=1
plots, pibstokes[4,k], pibstokes[0,k],psym=1,color=truecolor('blue'),thick=1, /data
oplot, [pirstokes[4,k],pirstokes[4,k]],[ymin,ymax],color=truecolor('blue'),thick=1,linestyle=1
plots, pirstokes[4,k], pirstokes[0,k],psym=1,color=truecolor('blue'),thick=1, /data
oplot, [sigstokes[4,k],sigstokes[4,k]],[ymin,ymax],color=truecolor('red'),thick=1,linestyle=1
plots, sigstokes[4,k], sigstokes[0,k],psym=1,color=truecolor('red'),thick=1, /data
; legend
makelegend, ['total intensity', $
'linear pol.' + textoidl('\pi'), 'circular and upol.' + textoidl('\pi'), $
'linear pol.' + textoidl('\sigma'), 'circular and upol.' + textoidl('\sigma'), $
textoidl('\lambda') +'cwl', $
textoidl('\lambda') +'max pi', $
textoidl('\lambda') + 'max sigma'], $
textcolors=truecolor(['black','blue','darkblue','red','darkred','black','blue','red']),$
colors =truecolor(['black','blue','darkblue','red','darkred','black','blue','red']),$
linestyle=[0,2,3,4,5,1,1,1],thick=[lth,lth,lth,lth,lth,1,1,1], $
charsize=1./sqrt(nplots), spacing=1./sqrt(nplots), /clear, /box, /top, /left
;----------------------------------------------------------------------------------
; close the device if needed
;----------------------------------------------------------------------------------
if ~(input.spec.multiplot) then begin
; close the figure
tmp = reset_graphic(figID, eps=epsfig)
!p.multi = 0
endif
;----------------------------------------------------------------------------------
; print some information to the screen and the html-file
;----------------------------------------------------------------------------------
if filterflag eq 0 then unit='photons/s/A' else unit='photons/s'
if filterflag eq 0 then cwltxt='of the spectrum' else cwltxt='of the filter '
print,format='(" - central wavelength (CWL) ",A,": ", (F7.2)," A")',$
cwltxt, lambda[cwlidx]
print,format='(" - wavelength at max. pi-blue : ", (F7.2)," A")',$
lambda[pbidx]
print,format='(" - wavelength at max. sigma : ", (F7.2)," A")',$
lambda[sidx]
print,format='(" - wavelength at max. pi-red : ", (F7.2)," A")',$
lambda[pridx]
print,''
printf,funit,'<p align="center"><table width="95%" border="0" cellspacing="0" cellpadding="0">'
printf,funit,'<tr><td width="37%" align="left">'
printf,funit,format='("central wavelength (CWL) ",A)', cwltxt
printf,funit,'</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='(F7.2," A")', lambda[cwlidx]
printf,funit,'</td></tr>'
printf,funit,'<tr><td width="37%" align="left">wavelength at max. pi-blue</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='(F7.2," A")', lambda[pbidx]
printf,funit,'</td></tr>'
printf,funit,'<tr><td width="37%" align="left">wavelength at max. sigma</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='(F7.2," A")', lambda[sidx]
printf,funit,'</td></tr>'
printf,funit,'<tr><td width="37%" align="left">wavelength at max. pi-red</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='(F7.2," A")', lambda[pridx]
printf,funit,'</td></tr>'
printf,funit,'</table></p>'
print,format='(" - total intensity at the CWL : ",(E10.1)," ",A)',$
tspec[cwlidx], unit
print,format='(" - total intensity at max. pi-blue : ",(E10.1)," ",A)',$
tspec[pbidx], unit
print,format='(" - total intensity at max. sigma : ",(E10.1)," ",A)',$
tspec[sidx], unit
print,format='(" - total intensity at max. pi-red : ",(E10.1)," ",A)',$
tspec[pridx], unit
print,''
printf,funit,'<p align="center"><table width="95%" border="0" cellspacing="0" cellpadding="0">'
printf,funit,'<tr><td width="37%" align="left">total intensity at the CWL</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((E10.1)," ",A)', tspec[cwlidx], unit
printf,funit,'</td></tr>'
printf,funit,'<tr><td width="37%" align="left">total intensity at max. pi-blue</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((E10.1)," ",A)', tspec[pbidx], unit
printf,funit,'</td></tr>'
printf,funit,'<tr><td width="37%" align="left">total intensity at max. sigma</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((E10.1)," ",A)', tspec[sidx], unit
printf,funit,'</td></tr>'
printf,funit,'<tr><td width="37%" align="left">total intensity at max. pi-red</td>'
printf,funit,'<td width="5%" align="center">:</td><td width="58%" align="left">'
printf,funit,format='((E10.1)," ",A)', tspec[pridx], unit
printf,funit,'</td></tr>'
printf,funit,'</table></p>'
endif
;----------------------------------------------------------------------------------
; plot pol. angle if requested
;----------------------------------------------------------------------------------
if input.spec.polangle then begin
;----------------------------------------------------------------------------------
; If multiplot is NOT selected, then we open a device for plotting here.
;----------------------------------------------------------------------------------
if ~(input.spec.multiplot) then begin
; set aspect ratio, figure zoom, fontsize and line thickness
aspect = 1.5
figzoom = 1.2
fontsize = 12
lth = 2.0
; open a device for plotting the spectra as function of wavelength
if (input.general.plot_print eq 1) then begin
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, zoom=figzoom)
endif
if (input.general.plot_print eq 2) then begin
if R_res[2,k] lt 10 then fname = string(format='("_polangle",A,"_R",(F4.2),"_psi",(F4.2),".eps")',$
chanID[k],R_res[2,k],psi_res[2,k]) $
else fname = string(format='("_polangle",A,"_R",(I0),".eps")', $
chanID[k],R_res[2,k])
fname = pictdir+'/'+psprefix+fname
figID = init_graphic(aspect=aspect, fontsize=fontsize, fontname=fontname, /PSfont, zoom=figzoom, eps=fname, bits_per_pixel=8)
endif
!p.multi = 0
!p.background= truecolor('white') ; use a white background
!p.color = truecolor('black') ; use a black foreground
endif
;----------------------------------------------------------------------------------
; make the figures title
;----------------------------------------------------------------------------------
if R_res[2,k] lt 10 then ttl = string(format='(" - Polarisation Angle ",A," at R=",(F4.2),"m / '+textoidl('\psi')+'=",(F4.2))',$
chanID[k],R_res[2,k],psi_res[2,k]) $
else ttl = string(format='(" - Polarisation Angle ",A," at R=",(I0),"m")', $
chanID[k],R_res[2,k])
ttl = prefix+ttl
;----------------------------------------------------------------------------------
; the plotting of the pol. angles (only where the polarised intensity is nonzero)
;----------------------------------------------------------------------------------
; set y-limits
ymin = -90.0
ymax = 90.0
; overall polarisation angle
if filterflag eq 0 then xttl='Wavelength [Angstrom]' else xttl='Filter central wavelength [Angstrom]'
plot, lambda[tpnonzero], gamma[tpnonzero], thick=lth, linestyle=0,$
xs=1, xr=[lambdamin,lambdamax], ys=1, yr=[ymin,ymax],$
xtitle=xttl, ytitle='Pol. angle '+textoidl('\gamma')+' [degrees]', $
title=ttl
; pi-polarisation angle
oplot, lambda[ppnonzero], pgamma[ppnonzero], color=truecolor('blue'), thick=lth, linestyle=2
; sigma-polarisation angle
oplot, lambda[spnonzero], sgamma[spnonzero], color=truecolor('red'), thick=lth, linestyle=2
; plot ideal polarization angle at 0, -90, -180
oplot, [lambdamin,lambdamax], [alpha0[k]*!radeg,alpha0[k]*!radeg], color=truecolor('black'), thick=0.5, linestyle=3
oplot, [lambdamin,lambdamax], [alpha0[k]*!radeg-90,alpha0[k]*!radeg-90], color=truecolor('black'), thick=0.5, linestyle=3
oplot, [lambdamin,lambdamax], [alpha0[k]*!radeg-180,alpha0[k]*!radeg-180], color=truecolor('black'), thick=0.5, linestyle=3
; indicate the CWL, max. S/N blue shifted pi, red shifted pi and sigma
oplot, [cwlstokes[4,k],cwlstokes[4,k]],[ymin,ymax],color=truecolor('black'),thick=1,linestyle=1
plots, cwlstokes[4,k], 0.5*atan(cwlstokes[2,k],cwlstokes[1,k])*!radeg,psym=1,color=truecolor('black'),thick=1, /data
oplot, [pibstokes[4,k],pibstokes[4,k]],[ymin,ymax],color=truecolor('blue'),thick=1,linestyle=1
plots, pibstokes[4,k], 0.5*atan(pibstokes[2,k],pibstokes[1,k])*!radeg,psym=1,color=truecolor('blue'),thick=1, /data
oplot, [pirstokes[4,k],pirstokes[4,k]],[ymin,ymax],color=truecolor('blue'),thick=1,linestyle=1
plots, pirstokes[4,k], 0.5*atan(pirstokes[2,k],pirstokes[1,k])*!radeg,psym=1,color=truecolor('blue'),thick=1, /data
oplot, [sigstokes[4,k],sigstokes[4,k]],[ymin,ymax],color=truecolor('red'),thick=1,linestyle=1
plots, sigstokes[4,k], 0.5*atan(sigstokes[2,k],sigstokes[1,k])*!radeg,psym=1,color=truecolor('red'),thick=1, /data
; legend
makelegend, ['total polarisation angle' + textoidl('\gamma'), $
textoidl('\pi') + 'polarisation angle' + textoidl('\gamma \pi'), $
textoidl('\sigma') + 'polarisation angle' + textoidl('\gamma_\sigma'), $
'ideal polarisation angle' + textoidl('\gamma'), $
textoidl('\lambda') +'cwl', $
textoidl('\lambda') +'max pi', $
textoidl('\lambda') + 'max sigma'], $
textcolors=truecolor(['black','blue','red','black','black','blue','red']), $
colors =truecolor(['black','blue','red','black','black','blue','red']), $
linestyle=[0,2,2,3,1,1,1],thick=[lth,lth,lth,0.5,1,1,1], $
charsize=1./sqrt(nplots), spacing=1./sqrt(nplots), /clear, /box, /top, /left
;----------------------------------------------------------------------------------
; close the device if needed
;----------------------------------------------------------------------------------
if ~(input.spec.multiplot) then begin
; close the figure
tmp = reset_graphic(figID, eps=epsfig)
!p.multi = 0
endif
;----------------------------------------------------------------------------------
; print some information to the screen and the html-file
;----------------------------------------------------------------------------------
cwlrange = [(cwlidx-5)>0,(cwlidx+5)<(nlambda-1)] ; range over which the change in polarisation angle
pbrange = [(pbidx-5)>0 ,(pbidx+5)<(nlambda-1) ] ; and the change in S/N-ratio is determined
srange = [(sidx-5)>0 ,(sidx+5)<(nlambda-1) ]
prrange = [(pridx-5)>0 ,(pridx+5)<(nlambda-1) ]