-
Notifications
You must be signed in to change notification settings - Fork 18
/
readopactable.c
122 lines (87 loc) · 3.39 KB
/
readopactable.c
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
/* This file is part of Exo_Transmit.
Exo_Transmit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Exo_Transmit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Exo_Transmit. If not, see <http://www.gnu.org/licenses/>.
*/
/*----------------------- readopactable.c ------------------------
Author: Eliza Kempton ([email protected])
------------------------------------------------------------------ */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "atmos.h"
#include "opac.h"
#include "nrutil.h"
#include "constant.h"
#include "vars.h"
#include "prototypes.h"
/* --- Global variables ------------------------------------------ */
extern struct Atmos atmos;
/* ---------------------------------------------------------------
* Read in opacity files: kappa(pressure, temperature, lambda)
* Opacity file actually contains cross section in units of m^2.
* Need to multiply by the number density to get kappa in units of
* m^-1
* --------------------------------------------------------------- */
/* ------- begin ------------ ReadOpacTable.c -------------------- */
void ReadOpacTable(struct Opac opac, char *filename) {
int i, j, k;
double junk;
vars variables = getVars();
int NLAMBDA = variables.NLAMBDA;
int NTEMP = variables.NTEMP;
int NPRESSURE = variables.NPRESSURE;
FILE *f1;
atmos.lambda = dvector(0, NLAMBDA-1);
opac.NP = NPRESSURE;
opac.NT = NTEMP;
f1 = fopen(filename,"r");
if(f1 == NULL){
printf("\nreadopactable.c:\nError opening %s opacity file\nPlease check that the proper name and path is specified in otherInput.in\n", opac.name);
exit(1);
}
for (k=0; k<opac.NT; k++) {
fscanf(f1,"%le", &opac.T[k]);
}
for (j=0; j<opac.NP; j++) {
fscanf(f1,"%le", &opac.P[j]);
opac.Plog10[j] = log10(opac.P[j]);
}
for (i=0; i<NLAMBDA; i++) {
fscanf(f1,"%le", &atmos.lambda[i]);
for (j=0; j<opac.NP; j++) {
fscanf(f1,"%le", &junk);
for (k=0; k<opac.NT; k++) {
fscanf(f1,"%le", &opac.kappa[i][j][k]);
/* kappa in file is actually cross section, sigma.
Need to multiply by number density */
opac.kappa[i][j][k] *= opac.abundance[j][k] * opac.P[j] /
(KBOLTZMANN * opac.T[k]);
}
}
}
fclose(f1);
printf("opac %e %e %e\n", atmos.lambda[NLAMBDA-1], opac.P[0], opac.T[0]);
}
/* ------- end -------------- ReadOpacTable.c -------------------- */
/* ------- begin ------------ FreeOpacTable.c -------------------- */
void FreeOpacTable(struct Opac opac)
{
vars variables = getVars();
int NLAMBDA = variables.NLAMBDA;
int NTEMP = variables.NTEMP;
int NPRESSURE = variables.NPRESSURE;
free_dvector(opac.T, 0, NTEMP-1);
free_dvector(opac.P, 0, NPRESSURE-1);
free_dvector(opac.Plog10, 0, NPRESSURE-1);
free_dmatrix(opac.abundance, 0, NPRESSURE-1, 0, NTEMP-1);
free_d3tensor(opac.kappa, 0, NLAMBDA-1, 0, NPRESSURE-1, 0, NTEMP-1);
}
/* ------- end -------------- FreeOpacTable.c -------------------- */