1 | subroutine ave_stelspec(STELLAR) |
---|
2 | |
---|
3 | !================================================================== |
---|
4 | ! |
---|
5 | ! Purpose |
---|
6 | ! ------- |
---|
7 | ! Average the chosen high resolution stellar spectrum over the |
---|
8 | ! visible bands in the model. |
---|
9 | ! |
---|
10 | ! Authors |
---|
11 | ! ------- |
---|
12 | ! Robin Wordsworth (2010). |
---|
13 | ! Generalized to very late spectral types (and Brown dwarfs) Jeremy Leconte (2012) |
---|
14 | ! |
---|
15 | ! Called by |
---|
16 | ! --------- |
---|
17 | ! setspv.F |
---|
18 | ! |
---|
19 | ! Calls |
---|
20 | ! ----- |
---|
21 | ! none |
---|
22 | ! |
---|
23 | !================================================================== |
---|
24 | |
---|
25 | use radinc_h, only: L_NSPECTV |
---|
26 | use radcommon_h, only: BWNV, DWNV, tstellar |
---|
27 | use datafile_mod, only: datadir |
---|
28 | use callkeys_mod, only: stelbbody,stelTbb,startype |
---|
29 | |
---|
30 | implicit none |
---|
31 | |
---|
32 | real*8 STELLAR(L_NSPECTV) |
---|
33 | ! integer startype |
---|
34 | |
---|
35 | integer Nfine |
---|
36 | integer,parameter :: Nfineband=200 |
---|
37 | integer ifine,band |
---|
38 | |
---|
39 | real,allocatable,save :: lam(:),stel_f(:) !read by master |
---|
40 | real lamm,lamp |
---|
41 | real dl |
---|
42 | |
---|
43 | character(len=100) :: file_id,file_id_lam |
---|
44 | character(len=200) :: file_path,file_path_lam |
---|
45 | |
---|
46 | real lam_temp |
---|
47 | double precision stel_temp |
---|
48 | |
---|
49 | integer :: ios ! file opening/reading status |
---|
50 | |
---|
51 | STELLAR(:)=0.0 |
---|
52 | |
---|
53 | print*,'enter ave_stellspec' |
---|
54 | if(stelbbody)then |
---|
55 | tstellar=stelTbb |
---|
56 | Nfine=L_NSPECTV*Nfineband |
---|
57 | do band=1,L_NSPECTV |
---|
58 | lamm=10000.0/BWNV(band+1) |
---|
59 | lamp=10000.0/BWNV(band) |
---|
60 | dl=(lamp-lamm)/(Nfineband) |
---|
61 | do ifine=1,Nfineband |
---|
62 | lam_temp=lamm+(lamp-lamm)*(ifine-1.)/(Nfineband) |
---|
63 | call blackl(dble(lam_temp*1e-6),dble(tstellar),stel_temp) |
---|
64 | STELLAR(band)=STELLAR(band)+stel_temp*dl |
---|
65 | enddo |
---|
66 | end do |
---|
67 | STELLAR(1:L_NSPECTV)=STELLAR(1:L_NSPECTV)/sum(STELLAR(1:L_NSPECTV)) |
---|
68 | else |
---|
69 | ! load high resolution stellar data |
---|
70 | Select Case(startype) |
---|
71 | Case(1) |
---|
72 | file_id='/stellar_spectra/sol.txt' |
---|
73 | tstellar=5800. |
---|
74 | file_id_lam='/stellar_spectra/lam.txt' |
---|
75 | Nfine=5000 |
---|
76 | Case(2) |
---|
77 | file_id='/stellar_spectra/gl581.txt' |
---|
78 | tstellar=3200. |
---|
79 | file_id_lam='/stellar_spectra/lam.txt' |
---|
80 | Nfine=5000 |
---|
81 | Case(3) |
---|
82 | file_id='/stellar_spectra/adleo.txt' |
---|
83 | tstellar=3200. |
---|
84 | file_id_lam='/stellar_spectra/lam.txt' |
---|
85 | Nfine=5000 |
---|
86 | Case(4) |
---|
87 | file_id='/stellar_spectra/gj644.txt' |
---|
88 | print*,'Find out tstellar before using this star!' |
---|
89 | call abort |
---|
90 | file_id_lam='/stellar_spectra/lam.txt' |
---|
91 | Nfine=5000 |
---|
92 | Case(5) |
---|
93 | file_id='/stellar_spectra/hd128167.txt' |
---|
94 | tstellar=6700. ! Segura et al. (2003) |
---|
95 | file_id_lam='/stellar_spectra/lam.txt' |
---|
96 | Nfine=5000 |
---|
97 | Case(6) |
---|
98 | file_id='/stellar_spectra/BD_Teff-1600K.txt' |
---|
99 | tstellar=1600. |
---|
100 | file_id_lam='/stellar_spectra/lamBD.txt' |
---|
101 | Nfine=5000 |
---|
102 | Case(7) |
---|
103 | file_id='/stellar_spectra/BD_Teff-1000K.txt' |
---|
104 | tstellar=1000. |
---|
105 | file_id_lam='/stellar_spectra/lamBD.txt' |
---|
106 | Nfine=5000 |
---|
107 | Case(8) |
---|
108 | file_id='/stellar_spectra/Flux_K5_Teff4700_logg4.5_Met-0.5_BTsettle.dat' |
---|
109 | tstellar=4700. |
---|
110 | file_id_lam='/stellar_spectra/lambda_K5_Teff4700_logg4.5_Met-0.5_BTsettle.dat' |
---|
111 | Nfine=3986 |
---|
112 | Case Default |
---|
113 | print*,'Error: unknown star type chosen' |
---|
114 | call abort |
---|
115 | End Select |
---|
116 | |
---|
117 | !$OMP MASTER |
---|
118 | allocate(lam(Nfine),stel_f(Nfine)) |
---|
119 | |
---|
120 | file_path_lam=TRIM(datadir)//TRIM(file_id_lam) |
---|
121 | open(110,file=file_path_lam,form='formatted',status='old',iostat=ios) |
---|
122 | if (ios.ne.0) then ! file not found |
---|
123 | write(*,*) 'Error from ave_stelspec' |
---|
124 | write(*,*) 'Data file ',trim(file_id_lam),' not found.' |
---|
125 | write(*,*)'Check that your path to datagcm:',trim(datadir) |
---|
126 | write(*,*)' is correct. You can change it in callphys.def with:' |
---|
127 | write(*,*)' datadir = /absolute/path/to/datagcm' |
---|
128 | write(*,*)' Also check that there is a ',trim(file_id_lam),' there.' |
---|
129 | call abort |
---|
130 | else |
---|
131 | do ifine=1,Nfine |
---|
132 | read(110,*) lam(ifine) |
---|
133 | enddo |
---|
134 | close(110) |
---|
135 | endif |
---|
136 | |
---|
137 | |
---|
138 | ! load high resolution wavenumber data |
---|
139 | file_path=TRIM(datadir)//TRIM(file_id) |
---|
140 | open(111,file=file_path,form='formatted',status='old',iostat=ios) |
---|
141 | if (ios.ne.0) then ! file not found |
---|
142 | write(*,*) 'Error from ave_stelspec' |
---|
143 | write(*,*) 'Data file ',trim(file_id),' not found.' |
---|
144 | write(*,*)'Check that your path to datagcm:',trim(datadir) |
---|
145 | write(*,*)' is correct. You can change it in callphys.def with:' |
---|
146 | write(*,*)' datadir = /absolute/path/to/datagcm' |
---|
147 | write(*,*)' Also check that there is a ',trim(file_id),' there.' |
---|
148 | call abort |
---|
149 | else |
---|
150 | do ifine=1,Nfine |
---|
151 | read(111,*) stel_f(ifine) |
---|
152 | enddo |
---|
153 | close(111) |
---|
154 | endif |
---|
155 | !$OMP END MASTER |
---|
156 | !$OMP BARRIER |
---|
157 | |
---|
158 | ! sum data by band |
---|
159 | band=1 |
---|
160 | Do while(lam(1).lt. real(10000.0/BWNV(band+1))) |
---|
161 | if (band.gt.L_NSPECTV-1) exit |
---|
162 | band=band+1 |
---|
163 | enddo |
---|
164 | dl=lam(2)-lam(1) |
---|
165 | STELLAR(band)=STELLAR(band)+stel_f(1)*dl |
---|
166 | do ifine = 2,Nfine |
---|
167 | if(lam(ifine) .gt. real(10000.0/BWNV(band)))then |
---|
168 | band=band-1 |
---|
169 | endif |
---|
170 | if(band .lt. 1) exit |
---|
171 | dl=lam(ifine)-lam(ifine-1) |
---|
172 | STELLAR(band)=STELLAR(band)+stel_f(ifine)*dl |
---|
173 | end do |
---|
174 | |
---|
175 | |
---|
176 | STELLAR(1:L_NSPECTV)=STELLAR(1:L_NSPECTV)/sum(STELLAR(1:L_NSPECTV)) |
---|
177 | !$OMP BARRIER |
---|
178 | !$OMP MASTER |
---|
179 | if (allocated(lam)) deallocate(lam) |
---|
180 | if (allocated(stel_f)) deallocate(stel_f) |
---|
181 | !$OMP END MASTER |
---|
182 | !$OMP BARRIER |
---|
183 | endif |
---|
184 | |
---|
185 | end subroutine ave_stelspec |
---|