-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoeqwidth.pro
1037 lines (890 loc) · 32.7 KB
/
autoeqwidth.pro
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
;---------------------------------------------------------------------------------------------------
;----------------------------------------Autoeqwidth v1.2-------------------------------------------
;---------------------Written by Sriram Sankar and Jayadev Pradeep 2019-----------------------------
;-----------Some parts have been adopted from codes written by Dr Anand Narayanan-------------------
;---------------------------------------------------------------------------------------------------
;The code calculates equivalent-width and Apparent column density for a list of ions
;For non-detections the linear relation of CoG is used to estimate the upper limits.
;The code does not account for continuum fitting uncertainties.
;
;Input file format: 'Ion' 'wavelength' 'oscillator strength' 'gamma-value' 'Detection Flag'
;1 - Detection & 0 - Non-detection - [Optional input]
;
;Equations for equivalent width calculation and column density measurement for the case of detections
;have been adopted from the thesis of Chris Churchill (1997) - The Low Ionization Gaseous Content in
;Intermediate Redshift Galaxies: http://astronomy.nmsu.edu/cwc/Research/thesis/Pages/ch2.html.
;Labelled as 'CC Eq: 2.xx'
;Curve of Growth Linear regime relation for the case of non-detections adopted from:
;Meiksin, Avery A. “The Physics of the Intergalactic Medium.” Reviews of Modern Physics 81, no. 4
;(October 5, 2009): 1405–69. https://doi.org/10.1103/RevModPhys.81.1405.
;Labelled as 'MA Eq:xx'
;Note that the order of magnitude of the constant of proportionality has been changed to account for
;values input in cm and Angstrom.
;---------------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------------
;-----------If you wish to thank me or report bugs mail me at [email protected]
;---------------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------------
;--------------------------------------------Features-----------------------------------------------
;Scale the continuum, apply velocity offsets, generate .csv table and Latex table of measurements,
;choose limits by clicking on the plot, and generate input file for system plot or for later runs...
;---------------------------------------------------------------------------------------------------
;------------------------------------------Aug 01 2019----------------------------------------------
;---------------------------------------------------------------------------------------------------
;Changes after release
;saving v1 and v2 as long in input file
;Significance level, detection prediction and option to flip detection flag
;FIxed lname bug for wavelength outside coverage
;Bug fix in formula to accurately measure equivalent width of saturated features - 13-Dec-2019
;/detflag added, automatic run from previous run file added and other minor bug fixes - 5-Jan-2020
;chknew1 declared to better differentiate between new runs and atmsip runs. {vl not declared error} - 26-Apr-2021
;
;
;
;
PRO autoeqwidth,ipfile=ipfile,ionlist=ionlist,z=z,detflag=dflag
if NOT KEYWORD_SET(ipfile) then begin
print,'Syntax - ' + $
'autoeqwidth, ipfile=xyz.asc (within quotes), ionlist=xyz.dat (within quotes), z=00.00,/detflag'
return
endif
if NOT KEYWORD_SET(ionlist) then ionlist='atomsnew.dat'
print,'-------- Welcome to autoeqwidth v1.2 2019 --------'
close,1,2,3
c=299792.458 ;speed of light in vacuum in km/s
;Default range
X1d=0
X2d=0
;Previous limit set to default for first time
X1=X1d
X2=X2d
j=0L
k=0
vmax=600 ;km/s
v_xmax=vmax
v_xmin=-1.0*vmax
cscale=0
ni=0 ; Number of iterations
chkc=0 ;Continuum scaling chk
chkv=0 ;Velocity shift chk
chkdf=0 ;Flip detection flag chk
readcol,ipfile,wav,flux,err,cont,/SILENT
i1=n_elements(wav)
contnew=cont
ion=strarr(file_lines(ionlist))
xyz=fltarr(file_lines(ionlist))
t3=strarr(file_lines(ionlist))
lamdao=fltarr(file_lines(ionlist))
f=fltarr(file_lines(ionlist))
lamda=fltarr(file_lines(ionlist))
wl=fltarr(file_lines(ionlist))
wl_e=fltarr(file_lines(ionlist))
nf=fltarr(file_lines(ionlist))
nf_e=fltarr(file_lines(ionlist))
range=strarr(file_lines(ionlist))
v1=fltarr(file_lines(ionlist))
v2=fltarr(file_lines(ionlist))
DUM_ar=fltarr(1)
adet=strarr(file_lines(ionlist))
dum=0
k=0
;------------------------------------------------------------------------------------------------
chkatm=0
chknew=0 ;re-measure
chknew1=0 ;new measurements
atmsip='atomsip'+strtrim(string(z),2)+'.dat'
atmip=file_search(atmsip)
if atmip eq atmsip then begin
print,'Input file from previous run found: ',atmsip
ysno=''
READ,ysno,PROMPT='Do you wish to re-generate output files directly? (y/any key): '
chkatm=STRCMP(ysno,'y',/FOLD_CASE)
endif
if chkatm eq 1 then begin
;------------------------------Reading autoeq i/p file---------------------------------
j=0L
vl=fltarr(file_lines(atmsip))
vr=fltarr(file_lines(atmsip))
openr,2,atmsip
while NOT EOF(2) do begin
var1=' '
var2=''
var3=''
var4=''
var5=''
var6=''
var7=''
readf,2,var1,var2,var3,var4,var5,var7,var6,format='(A14,A13,A15,A10,A12,A4,A4)'
;If the previous one gives an error try - '(A14,A12,A19,A4,A12,A4,A4)'
ion[j]=var1
lamdao[j]=var2
f[j]=var3
vl[j]=long(var4)
vr[j]=long(var5)
t3[j]=var6
print,ion[j],' | ',lamdao[j],' | ',f[j],' | ',vl[j],' | ',vr[j],' | ',t3[j]
j=j+1 ;j = Number of ions
endwhile
close,2
det=fix(t3)
sm=total(det)
while (k lt j) do begin
lamda[k]=lamdao[k]*(1+z)
lname=ion[k]
if (lamda[k] lt wav[0]) or (lamda[k] gt wav[i1-5]) then begin
print,strtrim(ion[k],2)+' '+strtrim(string(nint(lamdao[k])),2)+' is outside wavelength coverage.'
dum=dum+1
DUM_ar=[DUM_ar,k]
endif else begin
v_wav=((wav-lamda[k])/lamda[k])*c
;--------------------------------Equivalent width calculation------------------------------------
ew=0
ew_err_sqsum=0
ew_err=0
w_X1=lamda[k]*(1+vl[k]/c)
p1=min(abs(wav-w_X1), index1)
w_X2=lamda[k]*(1+vr[k]/c)
p2=min(abs(wav-w_X2), index2)
if index2 lt index1 then begin
temp=index1
tempX=X1
index1=index2
X1=X2
index2=temp
X2=tempX
endif
for q=index1,index2 do begin
if flux[q] gt 0.0000 then begin
val=1-(flux[q]/cont[q])
endif else begin
val=1
endelse
w_diff=wav[q+1]-wav[q]
if q eq index2 then w_diff=wav[q]-wav[q-1]
ew=ew+val*w_diff
tx=((err[q]^2)*(-1/(cont[q]))^2) ;CC Eq: 2.36 - Dimenssion corrected
ew_err_sqsum = ew_err_sqsum + tx*w_diff^2
endfor
ew_err=sqrt(ew_err_sqsum)/(1+z)
ew=ew/(1+z)
;---------------------------------------Significance---------------------------------------------
;------------------------------------------------------------------------------------------------
if KEYWORD_SET(dflag) then begin
sign=ew/ew_err
sign=float(round(sign*100)/100.0d)
significance=strmid(strtrim(string(long(sign)),2),0,5)+' sigma '
if sign ge 3 then adet[k] = 1 else adet[k] = 0
if det[k] ne adet[k] and sm ne 0 then begin
print,''
print,'**Alert**'
print,'Mismatch noted between derived detection flag and input detection flag for ',strtrim(ion[k],2)
Print,'In certain cases of contamination, it is better to measure the upper limit using AOD method.'
print,'But be careful to modify the output for the ion and make it an upper limit'
print,''
Print,'Please check the feature and enter the detection flag manually'
print,'0 - Non-detection'
print,'1 - Detection'
print,''
if adet[k] eq 1 then print,'It could be a ',significance,'detection for the selected range'
if adet[k] eq 0 then print,'It could be a non-detection. Significance (< 3 sigma) = ',significance
print,''
detf=0
READ,detf,PROMPT='What will it be?: '
print,''
det[k]=detf
endif else begin
det[k]=adet[k]
sm=1
endelse
endif
;--------------------------------------------AOD-------------------------------------------------
tauv=alog(cont/flux)
nav=3.768e14*tauv/(f[k]*lamdao[k])
nav_12=nav/1e12
;-----------------------------------------Detection----------------------------------------------
if(det[k] ne 0.00) then begin
na=0
tau=0
sigma_tau_sumsq=0
for q=index1,index2 do begin
if flux[q] gt 0 then begin
v_diff=v_wav[q+1]-v_wav[q]
if q eq index2 then v_diff = v_wav[q]-v_wav[q-1]
na=na+(nav[q]*v_diff)
tau=tau+(tauv[q]*v_diff)
current = (err[q]^2)*((-1.0/flux[q])^2)*v_diff
sigma_tau_sumsq= sigma_tau_sumsq + current
endif
endfor
logna=alog10(na)
sigma_tau=sqrt(sigma_tau_sumsq)
sigma_na = na * (sigma_tau^2) / tau
sigma_logna=0.4343*sigma_na/na
wl[k]=ew*1e3
wl_e[k]=ew_err*1e3
nf[k]=logna
nf_e[k]=sigma_logna
range[k]='['+strtrim(string(Long(vl[k])),2)+','+strtrim(string(Long(vr[k])),2)+']' ;Just trimming white spaces and decimals
v1[k]=vl[k]
v2[k]=vr[k]
endif else begin
;----------------------------------------Non-Detection-------------------------------------------
wlamda= 3*ew_err
nu=wlamda/((8.855e-21)*f(k)*((lamdao[k])^2))
nuf=alog10(nu)
wl[k]=0.000
wl_e[k]= wlamda*1e3
nf[k]=0.000
nf_e[k]= nuf
range[k]='['+strtrim(string(Long(vl[k])),2)+','+strtrim(string(Long(vr[k])),2)+']' ;Just trimming white spaces and decimals
v1[k]=vl[k]
v2[k]=vr[k]
endelse
endelse
k=k+1
ni=ni+1
endwhile
if ni ne 0 and dum ne 0 then DUM_ar=DUM_ar[1:*]
print,'---------------------------------------------------'
print,ni-dum,' measurements made' ;'Number of iterations: ',ni
print,'---------------------------------------------------'
print,''
endif ;chkatm
;------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------
ysno=''
if chkatm eq 1 then begin
READ,ysno,PROMPT='Do you wish to re-measure specific ions manually? (if y, make sure that the ionlist and the input file from the previous run have the same index values for the ions): '
chknew=STRCMP(ysno,'y',/FOLD_CASE)
endif else begin
READ,ysno,PROMPT='Do you wish to measure specific ions manually?: '
chknew1=STRCMP(ysno,'y',/FOLD_CASE)
endelse
if chknew1 eq 1 or chknew eq 1 then begin
ni=0
;------------------------------------------------------------------------------------------------
j=0L
openr,1,ionlist
while NOT EOF(1) do begin
var1=' '
var2=1.0D
var3=1.0D
var4=1.0D
var5=''
readf,1,var1,var2,var3,var4,var5,format='(A11,1x,F9.4,1x,F9.7,1x,E8.5,1x,A2)'
ion[j]=var1
lamdao[j]=var2
f[j]=var3
xyz[j]=var4
t3[j]=var5
j=j+1 ;j = Number of ions
endwhile
close,1
det=fix(t3)
sm=total(det)
yn=''
nil='-'
print,''
print,'If the detection flag has not been added to the ionlist, you will encounter type conversion errors.'
print,'No need to be alarmed you can choose the detection flag while measuring each ion.'
print,''
READ,yn,PROMPT='Do you wish to verify if the ionlist has been read correctly? (y/any key): '
chk=STRCMP(yn,'y',/FOLD_CASE)
;if chkatm eq 1 then det=dettemp
if chk eq 1 then begin
print,'Ion | Rest-wavelength | Oscillator strength | detection flag'
k=0
while k lt j do begin
if sm eq 0 then print,ion[k],' | ',lamdao[k],' | ',f[k],' | ',nil
if sm ne 0 then print,ion[k],' | ',lamdao[k],' | ',f[k],' | ',det[k]
k=k+1
endwhile
endif
;------------------------------------------------------------------------------------------------
dum=0
k=0
DUM_ar=fltarr(1)
print,''
print,'*********** PRO TIP ***********'
print,'For best flow of work, align the terminal to the left (58x37) and set it to be always visible on workspace.'
print,''
print,'Hit enter when you are ready.'
enter=get_kbrd()
if chknew eq 1 then begin
kt=0
while (kt lt j) do begin
print,kt+1,' --- ',ion[kt]
kt=kt+1
endwhile
Print,''
READ,knew,PROMPT='Enter the index value of the ion to be measured: '
k=knew-1
if chknew eq 1 then begin
X1d=vl[k]
X2d=vr[k]
endif
endif
endif
while (k lt j) do begin
lamda[k]=lamdao[k]*(1+z)
lname=ion[k]
outsidecoverage=0
if (lamda[k] lt wav[0]) or (lamda[k] gt wav[i1-5]) then begin
print,strtrim(ion[k],2)+' '+strtrim(string(nint(lamdao[k])),2)+' is outside wavelength coverage.'
dum=dum+1
DUM_ar=[DUM_ar,k]
outsidecoverage=1
endif else begin
dv=0
dx=0
v_wav=0
cscale=0
cont=contnew
v_wav=((wav-lamda[k])/lamda[k])*c
;------------------------------------Operation on each ion---------------------------------------
;------------------------------------------------------------------------------------------------
;--------------------------------------Continuum scaling-----------------------------------------
if ni ne 0 AND chkc eq 1 then begin
cscale=1.0
print,''
print,'Continuum of the order of ',strtrim(string(cont[25]),2)
print,''
READ,cscale,PROMPT='Enter value to scale the continuum (value will be multiplied by 1e-15): '
print,'Scaling the continuum by: ',cscale
contnew=cont
cont=cont+(cscale*1e-15)
endif
;---------------------------------------Shift Spectrum--------------------------------------------
if ni ne 0 AND chkv eq 1 then begin
dv=1.0
READ,dv,PROMPT='Enter the shift to be applied in km/s: '
print,'Shifting the spectrum by: ',strtrim(string(dv),2)
dx=(dv/c)*lamda[k]
wavold=wav
wav=wavold+dx
v_wav=((wav-lamda[k])/lamda[k])*c
endif
;------------------------------------------------------------------------------------------------
w_xmin=lamda[k]*(1+v_xmin/c)
w_xmax=lamda[k]*(1+v_xmax/c)
;------------------------------------------------------------------------------------------------
;lname=ion[k]
print,''
print,'*****************************'
print,'Analysing now: ',lname
print,'*****************************'
print,''
;------------------------------------------------------------------------------------------------
norm_flux=flux/cont
norm_cont=cont/cont
norm_err=err/cont
;----------------------------------------------Plot----------------------------------------------
!MOUSE.button = 1
cgdisplay, 1000, 800
ERASE
cgplot,v_wav, norm_flux, xtitle=textoidl('!6 Velocity (km/s)'), ytitle=textoidl('!6 Normalized Flux'),$
xstyle=1,charsize=1.5,ycharsize=1.2,xcharsize=1.2,$
yrange=[0.0,1.5],xrange=[v_xmin,v_xmax],/ystyle,PSym=10,xthick=5,ythick=5,thick=2
cgoplot, v_wav, norm_err,PSym=10, color='blue', thick=1
cgoplot, v_wav, norm_cont,PSym=10,linestyle=2, color='green', thick=3
vline, [0.0],/NOERASE,linestyle=2, thick=3
cgtext, v_xmin+0.13*(v_xmax-v_xmin),0.2, textoidl(lname), charthick=2.0, color='red', charsize=2
obs_wav_text = '!6 \lambda ='+strtrim(string(lamda[k]),2)+'A^{o}'
cgtext, v_xmax-0.35*(v_xmax-v_xmin),0.2, textoidl(obs_wav_text), charthick=2.0, color='green', charsize=2
vline, [X1d], thick=2, linestyle=2
vline, [X2d], thick=2, linestyle=2
;------------------------------------------------------------------------------------------------
;---------------------------------------Default limits-------------------------------------------
input=''
print,'---------------------------------------------------'
Print,'d - default limits ',strtrim(string(Long(X1d)),2),' - ',strtrim(string(Long(X2d)),2)
Print,'o - previous limits ',strtrim(string(Long(X1)),2),' - ',strtrim(string(Long(X2)),2)
Print,'e - to enter range '
Print,'ds - to set new default limits and measure '
Print,'s - to click and select '
Print,'Enter any other key to exit '
print,'---------------------------------------------------'
Print,''
READ,input,PROMPT='What will it be?: '
Print,''
chk=STRCMP(input,'d',/FOLD_CASE)
chk2=STRCMP(input,'o',/FOLD_CASE)
chk3=STRCMP(input,'e',/FOLD_CASE)
chk4=STRCMP(input,'s',/FOLD_CASE)
chk5=STRCMP(input,'ds',/FOLD_CASE)
if chk ne 1 AND chk2 ne 1 AND chk3 ne 1 AND chk4 ne 1 and chk5 ne 1 THEN begin
READ,yn,PROMPT='**ALERT** Do you really want to exit? (y/n): '
chke=STRCMP(yn,'y',/FOLD_CASE)
if chke eq 1 THEN begin
break
endif else begin
k=k
input=''
print,''
print,'---------------------------------------------------'
Print,'d - default limits ',strtrim(string(Long(X1d)),2),' - ',strtrim(string(Long(X2d)),2)
Print,'o - previous limits ',strtrim(string(Long(X1)),2),' - ',strtrim(string(Long(X2)),2)
Print,'e - to enter range '
Print,'ds - to set new default limits and measure '
Print,'s - to click and select '
Print,'Enter any other key to exit '
print,'---------------------------------------------------'
Print,''
READ,input,PROMPT='What will it be?: '
Print,''
chk=STRCMP(input,'d',/FOLD_CASE)
chk2=STRCMP(input,'o',/FOLD_CASE)
chk3=STRCMP(input,'e',/FOLD_CASE)
chk4=STRCMP(input,'s',/FOLD_CASE)
chk5=STRCMP(input,'ds',/FOLD_CASE)
if chk ne 1 AND chk2 ne 1 AND chk3 ne 1 AND chk4 ne 1 and chk5 ne 1 THEN break
endelse
endif
if chk eq 1 THEN BEGIN
X1=X1d
X2=X2d
endif
if chk5 eq 1 THEN BEGIN
Print,''
read, X1d, prompt= 'Enter new default lower limit of Velocity in km/s: '
vline, [X1d],/NOERASE, thick=2, linestyle=2
read, X2d, prompt= 'Enter new default upper limit of Velocity in km/s: '
vline, [X2d],/NOERASE, thick=2, linestyle=2
Print,''
X1=X1d
X2=X2d
endif
if chk3 eq 1 then begin
Print,''
read, X1, prompt= 'Enter the lower limit of Velocity in km/s: '
vline, [X1],/NOERASE, thick=2, linestyle=2
read, X2, prompt= 'Enter the upper limit of Velocity in km/s: '
vline, [X2],/NOERASE, thick=2, linestyle=2
Print,''
endif
;------------------------------------------------------------------------------------------------
;---------------------------------------Manual limits--------------------------------------------
if chk4 eq 1 then begin
Print,''
print,'Click to choose the index manually'
Print,''
print,'---------------------------------------------------'
Print,'Right click to exit'
Print,'Left Click to choose the range'
Print,'Middle Mouse to enter the final range'
print,'---------------------------------------------------'
Print,''
cont_tester=0
ERASE
WHILE (!MOUSE.button NE 4) DO BEGIN
cgdisplay, 1000, 800
cgplot,v_wav, norm_flux, xtitle=textoidl('!6 Velocity (km/s)'), ytitle=textoidl('!6 Normalized Flux'),$
xstyle=1,charsize=1.5,ycharsize=1.2,xcharsize=1.2,$
yrange=[0.0,1.5],xrange=[v_xmin,v_xmax],/ystyle,PSym=10,xthick=5,ythick=5,thick=2
cgoplot, v_wav, norm_err,PSym=10, color='blue', thick=1
cgoplot, v_wav, norm_cont,PSym=10,linestyle=2, color='green', thick=3
vline, [0.0],/NOERASE,linestyle=2, thick=3
cgtext, v_xmin+0.13*(v_xmax-v_xmin),0.2, textoidl(lname), charthick=2.0, color='red', charsize=2
obs_wav_text = '!6 \lambda ='+strtrim(string(lamda[k]),2)+'A^{o}'
cgtext, v_xmax-0.35*(v_xmax-v_xmin),0.2, textoidl(obs_wav_text), charthick=2.0, color='green', charsize=2
if cont_tester eq 0 then begin
cont_tester=1
;ERASE
CONTINUE
endif
if(!MOUSE.button EQ 4) then break
CURSOR, X1, Y1, /DOWN, /DATA
if(!MOUSE.button EQ 2) then begin
read, X1, prompt= 'Enter the lower limit of Velocity in km/s: '
vline, [X1],/NOERASE, thick=2, linestyle=2
read, X2, prompt= 'Enter the upper limit of Velocity in km/s: '
vline, [X2],/NOERASE, thick=2, linestyle=2
break
endif else begin
CURSOR, X1, Y1, /DOWN, /DATA
print,'Lower limit: ', X1
vline, [X1],/NOERASE, thick=1, linestyle=2,color=106
CURSOR, X2, Y2, /DOWN, /DATA
if(!MOUSE.button EQ 4) then break
print,'Upper limit: ', X2
vline, [X2],/NOERASE, thick=1,linestyle=2,color=106
CURSOR, X3, Y3, /DOWN, /DATA
if(!MOUSE.button EQ 4) then break
endelse
endwhile
endif
;------------------------------------------------------------------------------------------------
;--------------------------------Equivalent width calculation------------------------------------
ew=0
ew_err_sqsum=0
ew_err=0
w_diff=wav[2]-wav[1]
w_X1=lamda[k]*(1+X1/c)
p1=min(abs(wav-w_X1), index1)
w_X2=lamda[k]*(1+X2/c)
p2=min(abs(wav-w_X2), index2)
if index2 lt index1 then begin
temp=index1
tempX=X1
index1=index2
X1=X2
index2=temp
X2=tempX
endif
print,'Continuum scaled by: ',cscale
print,'Spectrum shifted by: ',dv,' km/s'
for q=index1,index2 do begin
if flux[q] gt 0.0000 then begin
val=1-(flux[q]/cont[q])
endif else begin
val=1
endelse
w_diff=wav[q+1]-wav[q]
if q eq index2 then w_diff=wav[q]-wav[q-1]
ew=ew+val*w_diff
tx=((err[q]^2)*(-1/(cont[q]))^2) ;CC Eq: 2.36 - Dimenssion corrected
ew_err_sqsum = ew_err_sqsum + tx*w_diff^2
endfor
ew_err=sqrt(ew_err_sqsum)/(1+z)
ew=ew/(1+z)
;ERASE
;Cgdisplay,1000,800
for q=index1,index2 do begin
xpoly=[v_wav[q]-w_diff/2,v_wav[q]+w_diff/2, v_wav[q]-w_diff/2,v_wav[q]+w_diff/2]
ypoly=[norm_flux[q],norm_flux[q], 1, 1]
cgplots,xpoly,ypoly, color='dodger blue', thick=5
endfor
;If you get multiple plots one over the other comment the lines below
cgoplot,v_wav, norm_flux,xtitle=textoidl('!6 Velocity (km/s)'), ytitle=textoidl('!6 Normalized Flux'),$
xstyle=1,charsize=1.5,ycharsize=1.2,xcharsize=1.2,$
yrange=[0.0,1.5],xrange=[v_xmin,v_xmax],/ystyle,PSym=10,xthick=5,ythick=5,thick=2
cgoplot, v_wav, norm_cont,PSym=10,linestyle=2, color='green', thick=3
cgoplot, v_wav, norm_err,PSym=10, color='blue', thick=1
vline, [0.0],/NOERASE,linestyle=3, thick=2
cgtext, v_xmin+0.13*(v_xmax-v_xmin),0.2, textoidl(lname), charthick=2.0, color='red', charsize=2
obs_wav_text = '!6 \lambda ='+strtrim(string(lamda[k]),2)+'A^{o}'
cgtext, v_xmax-0.35*(v_xmax-v_xmin),0.2, textoidl(obs_wav_text), charthick=2.0, color='green', charsize=2
;till here
vline, [X1],/NOERASE, thick=2, linestyle=2
vline, [X2],/NOERASE, thick=2,linestyle=2
ew1 = ew * 1e3
ew_err1 = ew_err * 1e3
;------------------------------------------------------------------------------------------------
;---------------------------------------Significance---------------------------------------------
;------------------------------------------------------------------------------------------------
sign=ew/ew_err
sign=float(round(sign*100)/100.0d)
significance=strmid(strtrim(string(long(sign)),2),0,5)+' sigma '
if sign ge 3 then adet[k] = 1 else adet[k] = 0 ;Significance
output1 = 'Equivalent Width = '+strtrim(string(ew1),2)+' +/- '+strtrim(string(ew_err1),2)+'mA^{o}'
cgtext, v_xmin+0.01*(v_xmax-v_xmin),1.5+0.03, textoidl(output1), charthick=2.0, color=109, charsize=2.0
;------------------------------------------------------------------------------------------------
if total(det) eq 0 AND chkdf ne 1 then sm = 0
if KEYWORD_SET(dflag) then begin
if det[k] ne adet[k] and sm ne 0 then begin
print,''
print,'**Alert**'
print,'Mismatch noted between derived detection flag and input detection flag for ',strtrim(ion[k],2)
Print,'In certain cases of contamination, it is better to measure the upper limit using AOD method.'
print,'But be careful to modify the output for the ion and make it an upper limit'
print,''
Print,'Please check the feature and enter the detection flag manually'
print,'0 - Non-detection'
print,'1 - Detection'
print,''
if adet[k] eq 1 then print,'It could be a ',significance,'detection for the selected range'
if adet[k] eq 0 then print,'It could be a non-detection. Significance (< 3 sigma) = ',significance
print,''
detf=0
READ,detf,PROMPT='What will it be?: '
print,''
det[k]=detf
endif else begin
det[k]=adet[k]
sm=1
endelse
endif
if det[k] ne adet[k] AND sm ne 0 then begin
print,''
print,'**Is the detection flag for ',lname,'accurate?**'
if adet[k] eq 1 then print,'It could be a ',significance,'detection for the selected range'
if adet[k] eq 0 then print,'It could be a non-detection. Significance (< 3 sigma) = ',significance
endif
;------------------------------------------------------------------------------------------------
;--------------------------------------------AOD-------------------------------------------------
tauv=alog(cont/flux)
nav=3.768e14*tauv/(f[k]*lamdao[k])
nav_12=nav/1e12
print,''
detf=0
if sm eq 0 then begin
Print,'Please enter the detection flag manually'
print,'0 - Non-detection'
print,'1 - Detection'
print,''
if adet[k] eq 1 then print,'It could be a ',significance,'detection for the selected range'
if adet[k] eq 0 then print,'It could be a non-detection. Significance (< 3 sigma) = ',significance
print,''
READ,detf,PROMPT='What will it be?: '
print,''
det[k]=detf
endif
;-----------------------------------------Detection----------------------------------------------
if(det[k] ne 0.00) then begin
na=0
v_diff=v_wav[2]-v_wav[1]
tau=0
sigma_tau_sumsq=0
for q=index1,index2 do begin
if flux[q] gt 0 then begin
v_diff=v_wav[q+1]-v_wav[q]
if q eq index2 then v_diff = v_wav[q]-v_wav[q-1]
na=na+(nav[q]*v_diff)
tau=tau+(tauv[q]*v_diff)
current = (err[q]^2)*((-1.0/flux[q])^2)*v_diff
sigma_tau_sumsq= sigma_tau_sumsq + current
endif
endfor
logna=alog10(na)
sigma_tau=sqrt(sigma_tau_sumsq)
sigma_na = na * (sigma_tau^2) / tau
sigma_logna=0.4343*sigma_na/na
print,significance,'detection: Proceeding to AOD'
Print,''
print,'*****************************'
print,lname
print,'*****************************'
print,'Lower Velocity Limit: ', strtrim(string(Long(X1)),2)
print,'Upper Velocity Limit: ', strtrim(string(Long(X2)),2)
print,'Rest-frame Equivalent Width = ',strtrim(string(ew*1e3),2),' +/- ',strtrim(string(ew_err*1e3),2),' mA'
print,'log10(Integrated Apparent Column Density) = ',strtrim(string(logna),2),' +/- ',strtrim(string(sigma_logna),2)
print,'*****************************'
wl[k]=ew*1e3
wl_e[k]=ew_err*1e3
nf[k]=logna
nf_e[k]=sigma_logna
range[k]='['+strtrim(string(Long(X1)),2)+','+strtrim(string(Long(X2)),2)+']' ;Just trimming white spaces and decimals
v1[k]=long(X1)
v2[k]=long(X2)
endif else begin
;------------------------------------------------------------------------------------------------
;----------------------------------------Non-Detection-------------------------------------------
Print,''
print,'Non-detection: Proceeding to curve of growth'
print,'Significance: ',significance
Print,''
print,'Rest-frame Equivalent Width = ',strtrim(string(ew*1e3),2),' +/- ',strtrim(string(ew_err*1e3),2),' mA'
wlamda= 3*ew_err
print,'3 sigma upper limit: ',strtrim(string(wlamda*1e3),2),' A'
print,'Error underpredicted as continuum fitting uncertainty not considered'
print,'Oscillator strength: ',f[k]
nu=wlamda/((8.855e-21)*f(k)*((lamdao[k])^2))
nuf=alog10(nu)
Print,''
print,'*****************************'
print,lname
print,'*****************************'
print,'Lower Velocity Limit: ', strtrim(string(Long(X1)),2)
print,'Upper Velocity Limit: ', strtrim(string(Long(X2)),2)
print,'Equivalent width upper limit < ',strtrim(string(wlamda*1e3),2),' mA'
print,'log10(Apparent Column Density limit) < ',strtrim(string(nuf),2)
print,'*****************************'
wl[k]=0.000
wl_e[k]= wlamda*1e3
nf[k]=0.000
nf_e[k]= nuf
range[k]='['+strtrim(string(Long(X1)),2)+','+strtrim(string(Long(X2)),2)+']' ;Just trimming white spaces and decimals
v1[k]=long(X1)
v2[k]=long(X2)
endelse
endelse ;Main else
print,''
if outsidecoverage eq 1 then begin
k=k+1
if k ge j then break
print,'Proceeding to the next ion ',ion[k]
endif else begin
ni=ni+1
yn=''
if k eq j-2 then print,'*** Attention: Next ion is the last in the list ***'
if k eq j-1 then print,'*** Attention: Last ion in the list ***'
Print,''
print,'---------------------------------------------------'
if k ne j-1 then Print,'y - to continue to the next ion ',ion[k+1]
Print,'r - to remeasure ',lname
Print,'c - to scale the continuum and remeasure ',lname
Print,'v - to shift the spectrum and remeasure ',lname
Print,'df - to flip the detection flag and remeasure ',lname
Print,'k - to measure a specific ion '
Print,'Enter any other key to exit '
print,'---------------------------------------------------'
Print,''
READ,yn,PROMPT='What will it be?: '
Print,''
chk=STRCMP(yn,'y',/FOLD_CASE)
chk2=STRCMP(yn,'r',/FOLD_CASE)
chkc=STRCMP(yn,'c',/FOLD_CASE)
chk4=STRCMP(yn,'k',/FOLD_CASE)
chkv=STRCMP(yn,'v',/FOLD_CASE)
chkdf=STRCMP(yn,'df',/FOLD_CASE)
if chk ne 1 AND chk2 ne 1 AND chkc ne 1 AND chk4 ne 1 AND chkv ne 1 AND chkdf ne 1 THEN begin
READ,yn,PROMPT='**ALERT** Do you really want to exit? (y/any key): '
chke=STRCMP(yn,'y',/FOLD_CASE)
if chke eq 1 THEN begin
kn=k+1 ;Note about Kn - It is not used anywhere. It was intended to serve as the number of ions measured
break
endif else begin
k=k+1
cscale=0
endelse
endif
if chk4 eq 1 THEN begin
kt=0
while (kt lt j) do begin
print,kt+1,' --- ',ion[kt]
kt=kt+1
endwhile
Print,''
READ,knew,PROMPT='Enter the index value of the ion to be measured: '
k=knew-1
if chkatm eq 1 then begin
X1d=vl[k]
X2d=vr[k]
endif
endif
if chk2 eq 1 or chkc eq 1 or chkv eq 1 THEN begin
k=k
kn=k
endif
if chkdf eq 1 THEN begin
k=k
kn=k
if det[k] eq 0 then det[k] = 1 else det[k] = 0
if sm eq 0 then sm=1
endif
if chk eq 1 THEN begin
k=k+1
kn=k
if chkatm eq 1 then begin
X1d=vl[k]
X2d=vr[k]
endif
endif
endelse ;outside coverage check
endwhile ;Main While
;----------------------------------------End of loop---------------------------------------------
if ni ne 0 and dum ne 0 then DUM_ar=DUM_ar[1:*]
print,'---------------------------------------------------'
print,ni-dum,' measurements made' ;'Number of iterations: ',ni
print,'---------------------------------------------------'
print,''
;------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------
;------------------------------------------------------------------------------------------------
;------------------------------------Writing to CSV file-----------------------------------------
yn=''
READ,yn,PROMPT='Do you wish to generate a .csv table? (y/any key): '
chk=STRCMP(yn,'y',/FOLD_CASE)
head=strarr(6)
head(0)='Ion'
head(1)='w (mA)'
head(2)='sigma_w (mA)'
head(3)='Na (cm^-2)'
head(4)='sigma_Na (cm^-2)'
head(5)='v (km/s)'
if chk eq 1 THEN begin
opfile=''
READ,opfile,PROMPT='Enter the output table filename: '
output=opfile+'.csv'
write_csv, output,ion,wl,wl_e,nf,nf_e,range,HEADER=head
print,'File saved: ',output
print,'---------------------------------------------------'
if dum ne 0 then begin
print,''
print,'It seems like your ionlist contains lines that are outside the wavelength coverage.'
print,ion[DUM_ar]
print,''
print,'Please remove them from the table.'
endif
endif
;------------------------------------------------------------------------------------------------
;------------------------------------Writing LaTex output----------------------------------------
print,''
yn=''
READ,yn,PROMPT='Do you wish to generate a LaTex table? (y/any key): '
chk=STRCMP(yn,'y',/FOLD_CASE)
if chk eq 1 THEN begin
wl_r=strarr(file_lines(ionlist))
wl_e_r=strarr(file_lines(ionlist))
nf_r=strarr(file_lines(ionlist))
nf_e_r=strarr(file_lines(ionlist))
col1=strarr(file_lines(ionlist))
k=0
while (k lt j) do begin
if wl[k] eq 0 then begin ;Non-Detection
wl_e_r[k]=strmid(strtrim(string(float(Round(wl_e[k]))),2),0,5)
nf_e_r[k]=strmid(strtrim(string(float(Round(nf_e[k]*100)/100.0d)),2),0,4)
wl_r[k]='$<$ '+ wl_e_r[k]
nf_r[k]='$<$ '+ nf_e_r[k]
endif else begin ;Detection
if wl_e[k] ge 10 then wl_e_r[k]=strmid(strtrim(string(Round(wl_e[k])),2),0,5)
;wl_r[k]=strmid(strtrim(string(float(Round(wl[k]*100)/100.0d)),2),0,5)
;wl_e_r[k]=strmid(strtrim(string(float(Round(wl_e[k]*100)/100.0d)),2),0,4)
wl_r[k]=strmid(strtrim(string(Round(wl[k])),2),0,5)
wl_e_r[k]=strmid(strtrim(string(Round(wl_e[k])),2),0,4)
nf_r[k]=strmid(strtrim(string(float(Round(nf[k]*100)/100.0d)),2),0,5)
nf_e_r[k]=strmid(strtrim(string(float(Round(nf_e[k]*100)/100.0d)),2),0,4)
if nf_e[k] gt 1.0 and det[k] eq 1 then begin ;Saturated
sat=''
READ,sat,PROMPT='Is '+ion[k]+' saturated? (y/n): '
chk=STRCMP(sat,'y',/FOLD_CASE)
if chk eq 1 then wl_r[k]= '$>$ '+ wl_r[k] & nf_r[k]= '$>$ '+ nf_r[k]
endif else begin
wl_r[k]= wl_r[k]+' $\pm$ '+wl_e_r[k]
nf_r[k]= nf_r[k]+' $\pm$ '+nf_e_r[k]
endelse
endelse
range[k]='$'+range[k]+'$'
col1[k]=ion[k]+' & '+wl_r[k]+' & '+nf_r[k]+' & & '+range[k]+' \\'
k=k+1
endwhile
lopfile=''
READ,lopfile,PROMPT='Enter the LaTex output filename: '
loutput=lopfile+'.txt'
writecol,loutput,col1
print,'File saved: ',loutput
Print,'Values rounded to 2 decimal places. Please check the values and make neccesary approximations.'