Manticore  Version 2.0alpha
Physics of Molecular Clouds
pacsResponse.cc
Go to the documentation of this file.
1 
17 #include <gsl/gsl_interp.h>
18 #include <mutils/util.h>
19 #include <manticore.h>
20 
21 namespace mu = mutils;
22 
23 int main(int argc, char *argv[])
24 {
25  if (argc != 3) {
26  fprintf(stderr, "Usage: %s PacsAbsorption.txt PacsFilter.txt\n", argv[0]);
27  exit(EXIT_FAILURE);
28  }
29 
30  // Open files.
31  FILE *bolo = fopen(argv[1], "r"), *band = fopen(argv[2], "r");
32  MU_EXCEPTION_ERRNO_IF(!bolo, argv[0], "Failed to open '%s'", argv[1]);
33  MU_EXCEPTION_ERRNO_IF(!band, argv[0], "Failed to open '%s'", argv[2]);
34 
35  // Read tables.
36  std::vector<double> lBolo, rBolo, lBand, rBand;
37  double lamb, resp;
38  while (fscanf(bolo, "%lf%lf", &lamb, &resp) == 2) {
39  lBolo.push_back(lamb), rBolo.push_back(resp);
40  }
41  while (fscanf(band, "%lf%lf", &lamb, &resp) == 2) {
42  lBand.push_back(lamb), rBand.push_back(resp);
43  }
44  fclose(bolo);
45  fclose(band);
46 
47  // Interpolate and multiply.
48  gsl_interp_accel *acc = gsl_interp_accel_alloc();
49  gsl_interp *interp = gsl_interp_alloc(gsl_interp_cspline, lBolo.size());
50  MU_EXCEPTION_IF(gsl_interp_init(interp, &lBolo[0], &rBolo[0], lBolo.size()),
51  argv[0], "Interpolator initialization failed");
52 
53  puts(" // {nu0, response0}");
54  for (size_t i = lBand.size()-1; i != 0; i--) {
55  double nu = 1e4*manticore::c_light / lBand[i];
56  if (rBand[i] > 1e-4) {
57  resp = rBand[i] *
58  gsl_interp_eval(interp, &lBolo[0], &rBolo[0], lBand[i], acc);
59  if (resp > 1e-4) { printf(" {%.5e, %.5e},\n", nu, resp); }
60  }
61  }
62 
63  exit(EXIT_SUCCESS);
64 }
#define MU_EXCEPTION_IF(cond, src, msg,...)
Conditionally throws mutils::Exception.
Definition: Exception.h:101
constexpr double c_light
Speed of light (cm/s).
Definition: manticore.h:23
int main(int argc, char *argv[])
Definition: pacsResponse.cc:23
#define MU_EXCEPTION_ERRNO_IF(cond, src, msg,...)
Conditionally throws mutils::Exception (including errno text).
Definition: Exception.h:124
The MathUtils miscellaneous utilities library.
MathUtils package.
Definition: CommandLine.cc:10