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