7 #include "IException.h"
10 #include "Photometry.h"
11 #include "PhotoModelFactory.h"
12 #include "PhotoModel.h"
13 #include "AtmosModelFactory.h"
14 #include "AtmosModel.h"
15 #include "NormModelFactory.h"
16 #include "NormModel.h"
28 Photometry::Photometry(
Pvl &pvl) {
35 std::string msg =
"A Photometric model must be specified to do any type of photometry";
41 if (pvl.
hasObject(
"NormalizationModel")) {
42 if (p_phtAmodel != NULL) {
52 if(p_phtAmodel != NULL) {
57 if(p_phtPmodel != NULL) {
62 if(p_phtNmodel != NULL) {
84 double dn,
double &albedo,
double &mult,
88 p_phtNmodel->
CalcNrmAlbedo(pha, inc, ema, dn, albedo, mult, base);
99 double deminc,
double demema,
double dn,
100 double &albedo,
double &mult,
double &base) {
103 p_phtNmodel->
CalcNrmAlbedo(pha, inc, ema, deminc, demema, dn, albedo, mult, base);
133 int iter=0, max_iter=100;
134 const gsl_root_fsolver_type *T;
137 T = gsl_root_fsolver_brent;
138 s = gsl_root_fsolver_alloc (T);
139 gsl_root_fsolver_set(s, Func, x_lo, x_hi);
143 status = gsl_root_fsolver_iterate(s);
144 root = gsl_root_fsolver_x_lower(s);
145 x_lo = gsl_root_fsolver_x_lower(s);
146 x_hi = gsl_root_fsolver_x_upper(s);
147 status = gsl_root_test_interval(x_lo, x_hi, 0, tolerance);
149 }
while (status != GSL_SUCCESS && iter < max_iter);
151 gsl_root_fsolver_free(s);
175 double & x_minimum,
double tolerance) {
177 int iter=0, max_iter=100;
179 const gsl_min_fminimizer_type *T;
180 gsl_min_fminimizer *s;
183 T = gsl_min_fminimizer_brent;
184 s = gsl_min_fminimizer_alloc(T);
190 gsl_min_fminimizer_set(s, Func, x_minimum, x_lower, x_upper);
194 status = gsl_min_fminimizer_iterate(s);
195 x_minimum = gsl_min_fminimizer_x_minimum(s);
196 x_lower = gsl_min_fminimizer_x_lower(s);
197 x_upper = gsl_min_fminimizer_x_upper(s);
199 status = gsl_min_test_interval(x_lower, x_upper, tolerance, 0.0);
200 }
while(status == GSL_CONTINUE && iter < max_iter);
203 gsl_min_fminimizer_free(s);
214 double &fc,
double Func(
double par,
void *params),
void *params) {
215 double eps = 1.0e-21;
216 double Gold = 1.618034;
217 double GrowLimit = 110;
220 fa = Func(xa, params);
221 fb = Func(xb, params);
230 xc = xb + Gold * (xb - xa);
231 fc = Func(xc, params);
235 double tmp1 = (xb - xa) * (fb - fc);
236 double tmp2 = (xb - xc) * (fb - fa);
237 double val = tmp2 - tmp1;
239 if (fabs(val) < eps) {
244 double w = xb - ((xb -xc) * tmp2 - (xb - xa) * tmp1) / denom;
245 double wlim = xb + GrowLimit * (xc - xb);
246 if (iter > maxiter) {
247 IString msg =
"Maximum iterations exceeded in minimum bracketing ";
248 msg +=
"algorithm (minbracket) - root cannot be bracketed";
253 if (((w-xc)*(xb-w)) > 0.0) {
254 fw = Func(w, params);
261 }
else if (fw > fb) {
266 w = xc + Gold * (xc - xb);
267 fw = Func(w, params);
268 }
else if (((w-wlim)*(wlim-xc)) >= 0.0) {
270 fw = Func(w, params);
271 }
else if (((w-wlim)*(xc-w)) > 0.0) {
272 fw = Func(w, params);
276 w = xc + Gold * (xc - xb);
279 fw = Func(w, params);
282 w = xc + Gold * (xc - xb);
283 fw = Func(w, params);