9 #include "NumericalApproximation.h" 
   10 #include "IException.h" 
   18   TopoAtm::TopoAtm(Pvl &pvl, PhotoModel &pmodel, AtmosModel &amodel) : NormModel(pvl, pmodel, amodel) {
 
   30     PvlGroup &algorithm = pvl.findObject(
"NormalizationModel").findGroup(
"Algorithm", 
Pvl::Traverse);
 
   37     if(algorithm.hasKeyword(
"Incref")) {
 
   41     if(algorithm.hasKeyword(
"Pharef")) {
 
   45       p_normPharef = p_normIncref;
 
   48     if(algorithm.hasKeyword(
"Emaref")) {
 
   52     if(algorithm.hasKeyword(
"Albedo")) {
 
   62       std::string msg = 
"Divide by zero encountered";
 
   66       p_normRhobar = p_normAlbedo / psurf0;
 
   69     psurfref = GetPhotoModel()->
CalcSurfAlbedo(p_normPharef, p_normIncref, p_normEmaref);
 
   70     pprimeref = GetPhotoModel()->
PhtTopder(p_normPharef, p_normIncref, p_normEmaref);
 
   78     munotref = cos((
PI / 180.0) * p_normIncref);
 
   82     GetAtmosModel()->
CalcAtmEffect(p_normPharef, p_normIncref, p_normEmaref, &pstdref, &transref,
 
   83                                    &trans0ref, &sbar, &transs);
 
   89     p_normAout = p_normRhobar * pprimeref * trans0ref;
 
   90     p_normBout = pstdref + p_normRhobar * (transref * ahref * munotref /
 
   91                                            (1.0 - p_normRhobar * GetAtmosModel()->
AtmosAb() * sbar) + trans0ref *
 
   92                                            (psurfref - ahref * munotref));
 
  100   void TopoAtm::NormModelAlgorithm(
double phase, 
double incidence, 
double emission,
 
  101                                    double demincidence, 
double dememission, 
double dn,
 
  102                                    double &albedo, 
double &mult, 
double &base) {
 
  105     static double pprime;
 
  106     static double ahInterp;
 
  123     static double old_phase = -9999;
 
  124     static double old_incidence = -9999;
 
  125     static double old_emission = -9999;
 
  126     static double old_demincidence = -9999;
 
  127     static double old_dememission = -9999;
 
  129     if (old_phase != phase || old_incidence != incidence || old_emission != emission ||
 
  130         old_demincidence != demincidence || old_dememission != dememission) {
 
  132       psurf = GetPhotoModel()->
CalcSurfAlbedo(phase, demincidence, dememission);
 
  133       pprime = GetPhotoModel()->
PhtTopder(phase, demincidence, dememission);
 
  136       munot = cos(incidence * (
PI / 180.0));
 
  139       old_incidence = incidence;
 
  140       old_emission = emission;
 
  141       old_demincidence = demincidence;
 
  142       old_dememission = dememission;
 
  145     GetAtmosModel()->
CalcAtmEffect(phase, incidence, emission, &pstd, &trans, &trans0, &sbar,
 
  147     pflat = pstd + p_normRhobar * (trans * ahInterp * munot /
 
  148                                    (1.0 - p_normRhobar * GetAtmosModel()->
AtmosAb() * sbar) + trans0 * (psurf -
 
  150     ptilt = pflat + p_normRhobar * pprime * trans0 * eps;
 
  152     dpm = (psurf - ahInterp * munot) * trans0;
 
  153     q = ahInterp * munot * trans + GetAtmosModel()->
AtmosAb() * sbar * dpo + dpm;
 
  154     rhotlt = 2.0 * dpo / (q + sqrt(pow(q, 2.0) - 4.0 * GetAtmosModel()->AtmosAb() * sbar * dpo * dpm));
 
  156     q = ahInterp * munot * trans + GetAtmosModel()->
AtmosAb() * sbar * dpo + dpm;
 
  157     rhoflat = 2.0 * dpo / (q + sqrt(pow(q, 2.0) - 4.0 * GetAtmosModel()->AtmosAb() * sbar * dpo * dpm));
 
  158     pprimeeff = (rhotlt - rhoflat) / (rhoflat * eps);
 
  159     slope = (dn - 1.0) / pprimeeff;
 
  160     albedo = p_normAout * slope + p_normBout;
 
  173     if(pharef < 0.0 || pharef >= 180.0) {
 
  174       std::string msg = 
"Invalid value of normalization pharef [" + 
IString(pharef) + 
"]";
 
  178     p_normPharef = pharef;
 
  191     if(incref < 0.0 || incref >= 90.0) {
 
  192       std::string msg = 
"Invalid value of normalization incref [" + 
IString(incref) + 
"]";
 
  196     p_normIncref = incref;
 
  209     if(emaref < 0.0 || emaref >= 90.0) {
 
  210       std::string msg = 
"Invalid value of normalization emaref [" + 
IString(emaref) + 
"]";
 
  214     p_normEmaref = emaref;
 
  226     p_normAlbedo = albedo;