35#define MAXNPTS 10000000
53 nu, nu0, nu1, nuf[
MAXNF], press, r0, temp, u;
55 static int i, i0, idx, nf, npts;
59 ERRMSG(
"Give parameters: <press> <temp> <spec> <filter>");
60 sscanf(argv[1],
"%lg", &press);
61 sscanf(argv[2],
"%lg", &temp);
64 u = 1e-6 * press * 100 / (1.380658e-23 * temp) * 1000 / 1e4;
67 if (!(in = fopen(argv[4],
"r")))
68 ERRMSG(
"Cannot open filter file!");
69 while (fgets(line,
MAXLINE, in))
70 if (sscanf(line,
"%lg %lg", &nuf[nf], &filt[nf]) == 2)
72 ERRMSG(
"Too many points in filter function");
76 if (!(in = fopen(argv[3],
"r")))
77 ERRMSG(
"Cannot open spectrum!");
79 ERRMSG(
"Error while reading spectrum!");
81 ERRMSG(
"Error while reading spectrum!");
83 ERRMSG(
"Error while reading spectrum!");
85 ERRMSG(
"Error while reading spectrum!");
86 sscanf(line,
"%d %lg %lg %lg", &npts, &nu0, &dnu, &nu1);
88 ERRMSG(
"Too many points in optical depth spectrum!");
90 while (fgets(line,
MAXLINE, in)) {
92 if ((tok = strtok(line,
" \t\n")) != NULL) {
93 sscanf(tok,
"%lg", &abs[i]);
97 while ((tok = strtok(NULL,
" \t\n")) != NULL) {
98 sscanf(tok,
"%lg", &abs[i]);
106 dnu = (nu1 - nu0) / ((
double) npts - 1.0);
107 r0 = (nuf[0] - nu0) / (nu1 - nu0) * (double) npts;
111 for (u = 1.0; u <= 1e30; u *= 1.122) {
114 double epssum = 0, fsum = 0;
115 for (i = i0; i < npts; i++) {
116 nu = nu0 + dnu * (double) i;
119 else if (nu > nuf[nf - 1])
122 if (nu < nuf[idx] || nu > nuf[idx + 1])
124 f =
LIN(nuf[idx], filt[idx], nuf[idx + 1], filt[idx + 1], nu);
126 epssum += f * exp(-abs[i] * u);
129 epssum = 1 - epssum / fsum;
132 if (epssum >= 1e-6 && epssum <= 0.999999 && epssum > epsold)
133 printf(
"%g %g %g %g\n", press, temp, u, epssum);
137 if (epssum > 0.999999)
int locate_irr(const double *xx, const int n, const double x)
Find array index for irregular grid.
JURASSIC library declarations.
#define ERRMSG(...)
Print error message and quit program.
#define LIN(x0, y0, x1, y1, x)
Compute linear interpolation.
int main(int argc, char *argv[])