1 /***************************************************************************
2 * This File is a part of the CADS/UV Stellar Spectrum model software *
3 * Copyright (C) 2012 by CADS/UV Software Team, *
4 * Indian Institute of Astrophysics *
5 * Bangalore 560034 *
6 * cads_AT_iiap.res.in *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
24 /*-------------------------------------------------------------------------*
25 File Description: The following functions are defined in this file
26 1. READ_TABLE() Selects are reads input file MKSpTypewwww.in
27 2. RCross_Sec() Estimates the Absorption coefficient using "crossec0.dat"
28 3. GET_REF1() Gets the flux in various bands
29 4. ALPHA() Calculate Scale value for Kurucz flux]
30 5. WRITE_LINE() Write spectrum to output file (one line per call)
31 *-------------------------------------------------------------------------*/
33 #include "stellar_spectrum.h"
35 /*---------------- Select & Reads input file MKSpTypewwww.in--------------*/
36 int READ_TABLE(struct S_TABLE *mkstTG)
37 {
38 FILE *fp =NULL;
39 int j;
40 int Nmax;
41 char s_tmp[MAX_TEXT], TG_tmp[MAX_TEXT], tok[MAX_TEXT];
42 char KFdir[MAX_TEXT];
43 char tab_line[TAB_LEN], *token, filename[MAX_TEXT];
45 strcpy(filename,mkstTG->w_filename);
47 if ((fp = fopen(filename, "r")) == NULL)
48 {
49 fprintf(stderr, "ERROR : Unable to open file %s\n",filename);
50 exit(EXIT_FAILURE);
51 }
53 fscanf(fp, "%i", &Nmax);
54 mkstTG->N_tab = Nmax;
56 fgets(tab_line, TAB_LEN, fp);
58 fgets(tab_line, TAB_LEN, fp);
59 sscanf(tab_line, "%s", KFdir);
60 strcpy(mkstTG->KFluxdir0, KFdir);
62 fgets(tab_line, TAB_LEN, fp);
63 fgets(tab_line, TAB_LEN, fp);
65 /*LOOP BEGINS HERE*/
66 for (j=1; j <= Nmax; j++)
67 {
69 fgets(tab_line, TAB_LEN, fp);
71 token = strtok(tab_line, TAB_DELIM);
72 /* Reads Sp_Type */
73 strcpy(tok, token);
74 sscanf(tok, "%s", s_tmp);
75 strcpy(mkstTG->star_name[j], s_tmp);
77 token = strtok(NULL, TAB_DELIM);
78 /* Reads Temp. Gravity Filename */
79 strcpy(tok, token);
80 sscanf(tok, "%s", TG_tmp);
81 strcpy(mkstTG->TG_name[j], TG_tmp);
83 token = strtok(NULL, TAB_DELIM);
84 /* Reads Bflux */
85 mkstTG->Bflux[j] = atof(token);
86 token = strtok(NULL, TAB_DELIM);
88 /* Reads Vflux */
89 mkstTG->Vflux[j] = atof(token);
90 token = strtok(NULL, TAB_DELIM);
92 /* Reads Observed flux */
93 mkstTG->Oflux[j] = atof(token);
94 }/*End for */
96 fclose(fp);
97 return (EXIT_SUCCESS);
99 }/* End READ_TABLE */
101 /*---------------------------- RCross_Sec -------------------------------*/
102 int RCross_Sec( struct STARS *line, char filename[MAX_TEXT])
103 {
104 FILE *fp = NULL;
105 int n1;
106 float Wo, WW1, WW2, C_Sectiono;
108 if ((fp = fopen(filename, "r")) == NULL)
109 {
110 fprintf(stderr, "ERROR : Unable to open file %s \n",filename);
111 exit(EXIT_FAILURE);
112 }
113 else
114 {
115 fscanf(fp,"%i%f", &n1, &line->Wlength[1]);
116 }
118 fclose(fp);
119 fp = NULL;
121 /* The following steps are to find out the Absorption CrossSection from
122 "crossec0.dat" corresponding to our wavelength of interest*/
124 if ((fp = fopen(line->SigmaFile, "r")) == NULL)
125 {
126 fprintf(stderr, "ERROR : Unable to open Cross Section File %s\n",
127 line->SigmaFile);
128 exit(EXIT_FAILURE);
129 }
131 WW1 = pow(line->Wlength[1],2);
132 fscanf(fp, "%f %e", &Wo, &C_Sectiono);
133 while (feof(fp) == 0)
134 {
135 WW2 = pow((Wo - line->Wlength[1]),2);
136 if (WW2 <= WW1)
137 {
138 WW1 = WW2;
139 line->C_Section[1] = C_Sectiono;
140 }
141 fscanf(fp, "%f %e", &Wo, &C_Sectiono);
142 } /* End while feof */
143 fclose(fp);
145 return (EXIT_SUCCESS);
146 }
149 /*----------------------------- GET_REF1 --------------------------------*/
150 int GET_REF1(struct STARS * line, struct S_TABLE * mkstTG,
151 char input_file[MAX_TEXT])
152 {
153 int i = 1, gr = 1;
155 while ((strcmp(line->sp_type, mkstTG->star_name[i]) != 0)
156 && (i<=mkstTG->N_tab))
157 i++;
158 if (i <= mkstTG->N_tab)
159 {
160 strcpy(line->tg_type, mkstTG->TG_name[i]);
161 line->Bflux = mkstTG->Bflux[i];
162 line->Vflux = mkstTG->Vflux[i];
163 line->Oflux = mkstTG->Oflux[i];
164 gr = 0;
165 }
166 else
167 {
168 fprintf(stderr, "ERROR : Unknown Spectral-Type : '%s'\n",
169 line->sp_type);
170 exit(EXIT_FAILURE);
171 }
172 return (gr);
173 }
175 /*------------------ Calculate Scale value for Kurucz flux ----------*/
176 int ALPHA(struct STARS *line)
177 {
178 double Tau, Fmv;
179 double flux_zero = 3.64e-9;
181 if (line->Ebv >=0.0)
182 {
183 Tau = ( line->Ebv * 3.1) / 1.0863 ;
184 Fmv = flux_zero * pow(10.0,(-0.4*line->mv));
185 if (line->Vflux > 0.0) line->alpha = ( Fmv * exp(Tau))/line->Vflux;
186 } /* end if */
187 else
188 line->alpha = 0.0 ;
189 return (EXIT_SUCCESS);
190 }
192 /*---------------- Write output file "hip_wwww.dat" ---------------------*/
193 int WRITE_LINE(FILE *staro_file, struct STARS *line)
194 {
195 double f_tmp,fstar,tau;
196 double gas_to_dust = 5.8e21;
198 f_tmp = (line->alpha * line->Oflux);
199 tau = line->C_Section[1] * line->Ebv * gas_to_dust;
200 fstar = f_tmp * exp(-tau);
201 fprintf(staro_file, " %5.8f %5.8e \n", line->Wlength[1],fstar);
202 return (EXIT_SUCCESS);
203 }