47 {
48
50
52
53 double fsum = 0.0;
54
55 int fn = 0;
56
57
59
60
61 if (argc < 3)
62 ERRMSG(
"Missing or invalid command-line arguments.\n\n"
63 "Usage: filter <ctl> <filter> [KEY VALUE ...]\n\n"
64 "Use -h for full help.");
65
66
68 const int type = (int)
scan_ctl(argc, argv,
"FILTER_TYPE", -1,
"1", NULL);
69 const double opd =
scan_ctl(argc, argv,
"FILTER_OPD", -1,
"10.0", NULL);
70 const double fwhm =
scan_ctl(argc, argv,
"FILTER_FWHM", -1,
"1.0", NULL);
71 const double center =
72 scan_ctl(argc, argv,
"FILTER_CENTER", -1,
"1000.0", NULL);
73 const double width =
scan_ctl(argc, argv,
"FILTER_WIDTH", -1,
"2.1", NULL);
74 const double samp =
scan_ctl(argc, argv,
"FILTER_SAMP", -1,
"0.0005", NULL);
75
76
77 for (double nu = center - 0.5 * width;
78 nu <= center + 0.5 * width; nu += samp) {
79
80
81 fnu[fn] = nu;
82
83
84 if (type == 0)
85 ff[fn] = (fabs(nu - center) <= 0.5 * fwhm ? 1.0 : 0.0);
86
87
88 else if (type == 1) {
89 ff[fn] = 1.0 - fabs(nu - center) / fwhm;
90 ff[fn] =
MAX(ff[fn], 0.0);
91 }
92
93
94 else if (type == 2) {
95 double sigma = fwhm / 2.355;
96 ff[fn] = exp(-0.5 *
POW2((nu - center) / sigma));
97 }
98
99
100 else if (type == 3)
101 ff[fn] =
ails(0, opd, nu - center);
102
103
104 else if (type == 4)
105 ff[fn] =
ails(1, opd, nu - center);
106
107
108 else
109 ERRMSG(
"Filter function type unknown!");
110
111
113 ERRMSG(
"Too many filter function data points!");
114 }
115
116
117 for (int i = 0; i < fn; i++)
118 fsum += ff[i];
119 for (int i = 0; i < fn; i++)
120 ff[i] /= (fsum * samp);
121
122
124
125 return (EXIT_SUCCESS);
126}
double ails(int apo, double opl, double dnu)
Compute apodized instrument line shape.
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read model control parameters from command-line and configuration input.
double scan_ctl(int argc, char *argv[], const char *varname, const int arridx, const char *defvalue, char *value)
Scan control file or command-line arguments for a configuration variable.
void write_shape(const char *filename, const double *x, const double *y, const int n)
Write tabulated shape function data to a text file.
#define POW2(x)
Compute the square of a value.
#define USAGE
Print usage information on -h or --help.
#define NSHAPE
Maximum number of shape function grid points.
#define MAX(a, b)
Determine the maximum of two values.