25#include "IException.h" 
   27#include "SpecialPixel.h" 
   28#include "NaifStatus.h" 
   34bool HiCalConf::_naifLoaded = 
false;
 
   39  HiCalConf::HiCalConf() : DbAccess() {
 
   49  HiCalConf::HiCalConf(Pvl &label) : DbAccess() {
 
   60  HiCalConf::HiCalConf(Pvl &label, 
const QString &conf) :
 
   61       DbAccess(Pvl(filepath(conf)).findObject(
"Hical", PvlObject::Traverse)) {
 
   71  void HiCalConf::setLabel(Pvl &label) {
 
   88  QString HiCalConf::filepath(
const QString &fname)
 const {
 
   89    FileName efile(fname);
 
   90    if (efile.isVersioned()) {
 
   91      QString path(efile.originalPath());
 
   92      if (!path.isEmpty()) path += 
"/";
 
   94      efile = efile.highestVersion();
 
   96      return (path + efile.name());
 
  111  void HiCalConf::setConf(
const QString &conf) {
 
  112    load(Pvl(filepath(conf)).findObject(
"Hical", PvlObject::Traverse));
 
  124  void HiCalConf::selectProfile(
const QString &profile) {
 
  136  QString HiCalConf::getProfileName()
 const {
 
  153  QString HiCalConf::getMatrixSource(
const QString &name)
 const {
 
  154    return (getMatrixSource(name, getMatrixProfile()));
 
  171  QString HiCalConf::getMatrixSource(
const QString &name,
 
  172                                         const DbProfile &matconf)
 const {
 
  174    QString mfile = parser(matconf.value(name),
 
  175                               getList(matconf,
"OptionKeywords"),
 
  179    return (filepath(mfile));
 
  182  HiVector HiCalConf::getMatrix(
const QString &name,
 
  183                                int expected_size)
 const {
 
  184    return (getMatrix(name,getMatrixProfile(), expected_size));
 
  188  QString HiCalConf::resolve(
const QString &composite,
 
  189                                 const DbProfile &matconf)
 const {
 
  190    return (parser(composite,getList(matconf,
"OptionKeywords"), matconf));
 
  218  HiVector HiCalConf::getMatrix(
const QString &name,
 
  219                                const DbProfile &profile,
 
  220                                int expected_size)
 const {
 
  222    QString mfile = getMatrixSource(name, profile);
 
  229    if (expected_size != 0) {
 
  230      if (cube.sampleCount() != expected_size) {
 
  232        mess << 
"Specifed matrix  (" << name
 
  233             << 
") from file \"" << mfile
 
  234             << 
"\" does not have expected samples (" << expected_size
 
  235             << 
") but has " << cube.sampleCount();
 
  237        throw IException(IException::User, mess.str(), _FILEINFO_);
 
  242    Brick bandio(cube.sampleCount(), 1, 1, Real);
 
  243    bandio.SetBasePosition(1,1,getMatrixBand(profile));
 
  247    HiVector temp(cube.sampleCount(), bandio.DoubleBuffer());
 
  268  HiVector HiCalConf::getScalar(
const QString &name,
 
  269                                const DbProfile &profile,
 
  270                                int expected_size)
 const {
 
  271    int nvals = profile.count(name);
 
  274    if (expected_size != 0) {
 
  275      if (nvals != expected_size) {
 
  277        mess << 
"Specifed scalar (" << name
 
  278             << 
") does not have expected size (" << expected_size
 
  279             << 
") but has " << nvals;
 
  280        throw IException(IException::User, mess.str(), _FILEINFO_);
 
  285    for (
int i = 0  ; i < nvals ; i++) {
 
  286      mtx[i] = 
ToDouble(profile(name, i));
 
  299  double HiCalConf::sunDistanceAU(Cube *cube) {
 
  303      cam = cube->camera();
 
  304      cam->SetImage(0.5, 0.5);
 
  305      sunkm = cam->sunToBodyDist();
 
  306      NaifStatus::CheckErrors();
 
  308    catch (IException &e) {
 
  312        QString scStartTime = getKey(
"SpacecraftClockStartCount", 
"Instrument");
 
  314        NaifStatus::CheckErrors();
 
  315        scs2e_c (-74999,scStartTime.toLatin1().data(),&obsStartTime);
 
  317        QString targetName = getKey(
"TargetName", 
"Instrument");
 
  318        if (targetName.toLower() == 
"sky" ||
 
  319            targetName.toLower() == 
"cal" ||
 
  320            targetName.toLower() == 
"phobos" ||
 
  321            targetName.toLower() == 
"deimos") {
 
  326        (void) spkpos_c(targetName.toLatin1().data(), obsStartTime, 
"J2000", 
"LT+S", 
"sun",
 
  328        sunkm = vnorm_c(sunv);
 
  330        NaifStatus::CheckErrors();
 
  332      catch(IException &e) {
 
  333        QString msg = 
"Unable to determine the distance from the target to the sun";
 
  334        throw IException(e, IException::User, msg, _FILEINFO_);
 
  339    return (sunkm/1.49597870691E8);
 
  357  int HiCalConf::getMatrixBand()
 const {
 
  359    DbProfile parms = makeParameters(label);
 
  360    return (getMatrixBand(parms));
 
  376  int HiCalConf::getMatrixBand(
const DbProfile &p)
 const {
 
  392  HiCalConf::ValueList HiCalConf::getList(
const DbProfile &profile,
 
  393                                          const QString &key)
 const {
 
  397    if ( profile.exists(key) ) {
 
  398      int nvals = profile.count(key);
 
  399      for (
int i = 0 ; i < nvals ; i++) {
 
  400        slist.push_back(profile.value(key, i));
 
  412void HiCalConf::loadNaifTiming( ) {
 
  413  NaifStatus::CheckErrors();
 
  417    leapseconds = leapseconds.highestVersion();
 
  419    Isis::FileName sclk(
"$mro/kernels/sclk/MRO_SCLKSCET.?????.65536.tsc");
 
  420    sclk = sclk.highestVersion();
 
  423    pck = pck.highestVersion();
 
  426    sat = sat.highestVersion();
 
  429    QString lsk = leapseconds.expanded();
 
  430    QString sClock = sclk.expanded();
 
  431    QString pConstants = pck.expanded();
 
  432    QString satConstants = sat.expanded();
 
  433    furnsh_c(lsk.toLatin1().data());
 
  434    furnsh_c(sClock.toLatin1().data());
 
  435    furnsh_c(pConstants.toLatin1().data());
 
  436    furnsh_c(satConstants.toLatin1().data());
 
  437    NaifStatus::CheckErrors();
 
  448void HiCalConf::init() {
 
  462void HiCalConf::init(Pvl &label) {
 
  479PvlKeyword &HiCalConf::getKey(
const QString &key,
 
  480                              const QString &group) {
 
  481  if (!group.isEmpty()) {
 
  482    PvlGroup &grp = _label.findGroup(group, Pvl::Traverse);
 
  486    return (_label.findKeyword(key));
 
  508DbProfile HiCalConf::getMatrixProfile(
const QString &profile)
 const {
 
  509  QString myprof = (!profile.isEmpty()) ? profile : _profName;
 
  510  DbProfile matconf = getProfile(myprof);
 
  511  if (!matconf.isValid()) {
 
  513    mess << 
"Specifed matrix profile (" << matconf.Name()
 
  514         << 
") does not exist or is invalid!";
 
  515    throw IException(IException::User, mess.str(), _FILEINFO_);
 
  519  matconf = DbProfile(getLabelProfile(matconf), matconf, matconf.Name());
 
  522  matconf = DbProfile(matconf, makeParameters(matconf), matconf.Name());
 
  525  ValueList profkeys = getList(matconf,
"OptionKeywords");
 
  526  ValueList proforder = getList(matconf,
"ProfileOptions");
 
  527  QString pName(matconf.Name());
 
  528  for (
unsigned int i = 0 ; i < proforder.size() ; i++) {
 
  529    QString profile = parser(proforder[i], profkeys, matconf);
 
  530    if (profileExists(profile)) {
 
  531      pName += 
"+[" + profile + 
"]";
 
  532      matconf = DbProfile(matconf,getProfile(profile), pName);
 
  539DbProfile HiCalConf::getLabelProfile(
const DbProfile &profile)
 const {
 
  540  DbProfile lblprof(
"Label");
 
  541  if ( profile.exists(
"LabelGroups") ) {
 
  542    int ngroups = profile.count(
"LabelGroups");
 
  544    for ( 
int g = 0 ; g < ngroups ; g++ ) {
 
  545      QString group = profile(
"LabelGroups", g);
 
  546      PvlGroup grp = label.findGroup(group, Pvl::Traverse);
 
  547      lblprof = DbProfile(lblprof,DbProfile(grp));
 
  553int HiCalConf::getChannelIndex(
const int &ccd, 
const int &channel)
 const {
 
  554  return(1 + (ccd*2) + channel);
 
  557DbProfile HiCalConf::makeParameters(Pvl &label)
 const {
 
  558  PvlGroup inst = label.findGroup(
"Instrument", Pvl::Traverse);
 
  559  DbProfile parms(
"Parameters");
 
  561  int ccd = 
CpmmToCcd((
int) inst[
"CpmmNumber"]);
 
  562  int channel = inst[
"ChannelNumber"];
 
  564  parms.add(
"CHANNEL", 
ToString(channel));
 
  565  parms.add(
"TDI", inst[
"Tdi"]);
 
  566  parms.add(
"BIN", inst[
"Summing"]);
 
  568  parms.add(
"CCDCHANNELINDEX", 
ToString(getChannelIndex(ccd, channel)));
 
  572DbProfile HiCalConf::makeParameters(
const DbProfile &profile)
 const {
 
  573  DbProfile parms(
"Parameters");
 
  575  int channel = 
ToInteger(profile(
"ChannelNumber"));
 
  577  parms.add(
"CHANNEL", 
ToString(channel));
 
  578  parms.add(
"TDI", profile(
"Tdi"));
 
  579  parms.add(
"BIN", profile(
"Summing"));
 
  581  parms.add(
"CCDCHANNELINDEX", 
ToString(getChannelIndex(ccd, channel)));
 
  585QString  HiCalConf::makePattern(
const QString &str)
 const {
 
  586  return (QString(
"{" + str + 
"}"));
 
  600QString HiCalConf::parser(
const QString &s, 
const ValueList &vlist,
 
  601                          const DbProfile &prof)
 const {
 
  604    ValueList::const_iterator ciVlist;
 
  605    for ( ciVlist = vlist.begin() ; ciVlist != vlist.end() ; ++ciVlist ) {
 
  606      QString str(*ciVlist);
 
  607      if ( prof.exists(str) ) {
 
  608        sout = sout.replace(makePattern(str), prof(str));
 
File name manipulation and expansion.
This is free and unencumbered software released into the public domain.
QString CcdToFilter(int ccd)
Convert HiRISE Ccd number to string filter name.
int CpmmToCcd(int cpmm)
Convert HiRISE Cpmm number to Ccd number.
TNT::Array1D< double > HiVector
1-D Buffer
QString ToString(const T &value)
Helper function to convert values to strings.
double ToDouble(const T &value)
Helper function to convert values to doubles.
int ToInteger(const T &value)
Helper function to convert values to Integers.
Namespace for the standard library.