JURASSIC
Functions
filter.c File Reference

Create radiometric filter functions. More...

#include "jurassic.h"

Go to the source code of this file.

Functions

double ails (int apo, double opl, double dnu)
 Compute apodized instrument line shape. More...
 
int main (int argc, char *argv[])
 

Detailed Description

Create radiometric filter functions.

Definition in file filter.c.

Function Documentation

◆ ails()

double ails ( int  apo,
double  opl,
double  dnu 
)

Compute apodized instrument line shape.

Definition at line 120 of file filter.c.

123 {
124
125 double a, a2, a4, a6, a8, cosa, q0, q2, q4, sinca;
126
127 /* Auxiliary quantities... */
128 a = 2 * M_PI * dnu * opl;
129 a2 = a * a;
130 a4 = a2 * a2;
131 a6 = a4 * a2;
132 a8 = a4 * a4;
133
134 /* Sinc function... */
135 if (apo == 0) {
136 if (fabs(a) < 0.7)
137 return 1 - a2 / 6 + a4 / 120 - a6 / 5040 + a8 / 362880;
138 else
139 return sin(a) / a;
140 }
141
142 /* Norton-Beer strong apodization... */
143 else if (apo == 1) {
144 if (fabs(a) < 0.7) {
145 q0 = 1 - a2 / 6 + a4 / 120 - a6 / 5040 + a8 / 362880;
146 q2 = 1 - a2 / 14 + a4 / 504 - a6 / 33264 + a8 / 3459456;
147 q4 = 1 - a2 / 22 + a4 / 1144 - a6 / 102960 + a8 / 14002560;
148 } else {
149 sinca = sin(a) / a;
150 cosa = cos(a);
151 q0 = sinca;
152 q2 = -15 / a2 * ((1 - 3 / a2) * sinca + (3 / a2) * cosa);
153 q4 =
154 945 / a4 * ((1 - 45 / a2 + 105 / a4) * sinca +
155 5 / a2 * (2 - 21 / a2) * cosa);
156 }
157 return 0.045335 * q0 + 0.554883 * q2 * 8. / 15. +
158 0.399782 * q4 * 384. / 945.;
159 }
160
161 /* Error message.... */
162 else
163 ERRMSG("Unknown apodization!");
164}
#define ERRMSG(...)
Print error message and quit program.
Definition: jurassic.h:237

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 41 of file filter.c.

43 {
44
45 static ctl_t ctl;
46
47 static double ff[NSHAPE], fnu[NSHAPE];
48
49 double fsum = 0.0;
50
51 int fn = 0;
52
53 /* Write info... */
54 if (argc < 3)
55 ERRMSG("Give parameters: <ctl> <filter>");
56
57 /* Read control parameters... */
58 read_ctl(argc, argv, &ctl);
59 int type = (int) scan_ctl(argc, argv, "FILTER_TYPE", -1, "1", NULL);
60 double opd = scan_ctl(argc, argv, "FILTER_OPD", -1, "10.0", NULL);
61 double fwhm = scan_ctl(argc, argv, "FILTER_FWHM", -1, "1.0", NULL);
62 double center = scan_ctl(argc, argv, "FILTER_CENTER", -1, "1000.0", NULL);
63 double width = scan_ctl(argc, argv, "FILTER_WIDTH", -1, "2.1", NULL);
64 double samp = scan_ctl(argc, argv, "FILTER_SAMP", -1, "0.0005", NULL);
65
66 /* Compute filter function... */
67 for (double nu = center - 0.5 * width;
68 nu <= center + 0.5 * width; nu += samp) {
69
70 /* Set frequency... */
71 fnu[fn] = nu;
72
73 /* Boxcar... */
74 if (type == 0)
75 ff[fn] = (fabs(nu - center) <= 0.5 * fwhm ? 1.0 : 0.0);
76
77 /* Triangle... */
78 else if (type == 1) {
79 ff[fn] = 1.0 - fabs(nu - center) / fwhm;
80 ff[fn] = MAX(ff[fn], 0.0);
81 }
82
83 /* Gaussian... */
84 else if (type == 2) {
85 double sigma = fwhm / 2.355;
86 ff[fn] = exp(-0.5 * POW2((nu - center) / sigma));
87 }
88
89 /* Sinc function... */
90 else if (type == 3)
91 ff[fn] = ails(0, opd, nu - center);
92
93 /* Norton-Beer strong apodization... */
94 else if (type == 4)
95 ff[fn] = ails(1, opd, nu - center);
96
97 /* Error message... */
98 else
99 ERRMSG("Filter function type unknown!");
100
101 /* Count spectral grid points... */
102 if ((++fn) >= NSHAPE)
103 ERRMSG("Too many filter function data points!");
104 }
105
106 /* Normalize filter function... */
107 for (int i = 0; i < fn; i++)
108 fsum += ff[i];
109 for (int i = 0; i < fn; i++)
110 ff[i] /= (fsum * samp);
111
112 /* Write to file... */
113 write_shape(argv[2], fnu, ff, fn);
114
115 return (EXIT_SUCCESS);
116}
double ails(int apo, double opl, double dnu)
Compute apodized instrument line shape.
Definition: filter.c:120
void read_ctl(int argc, char *argv[], ctl_t *ctl)
Read forward model control parameters.
Definition: jurassic.c:4550
void write_shape(const char *filename, const double *x, const double *y, const int n)
Write shape function.
Definition: jurassic.c:5783
double scan_ctl(int argc, char *argv[], const char *varname, int arridx, const char *defvalue, char *value)
Search control parameter file for variable entry.
Definition: jurassic.c:5117
#define POW2(x)
Compute x^2.
Definition: jurassic.h:187
#define NSHAPE
Maximum number of shape function grid points.
Definition: jurassic.h:408
#define MAX(a, b)
Macro to determine the maximum of two values.
Definition: jurassic.h:156
Forward model control parameters.
Definition: jurassic.h:541
Here is the call graph for this function: