49 bool HiCalConf::_naifLoaded =
false;
54 HiCalConf::HiCalConf() : DbAccess() {
64 HiCalConf::HiCalConf(Pvl &label) : DbAccess() {
75 HiCalConf::HiCalConf(Pvl &label,
const QString &conf) :
76 DbAccess(Pvl(filepath(conf)).findObject(
"Hical", PvlObject::Traverse)) {
86 void HiCalConf::setLabel(Pvl &label) {
103 QString HiCalConf::filepath(
const QString &fname)
const {
104 FileName efile(fname);
105 if (efile.isVersioned()) {
106 QString path(efile.originalPath());
107 if (!path.isEmpty()) path +=
"/";
109 efile = efile.highestVersion();
111 return (path + efile.name());
126 void HiCalConf::setConf(
const QString &conf) {
139 void HiCalConf::selectProfile(
const QString &profile) {
151 QString HiCalConf::getProfileName()
const {
168 QString HiCalConf::getMatrixSource(
const QString &name)
const {
169 return (getMatrixSource(name, getMatrixProfile()));
186 QString HiCalConf::getMatrixSource(
const QString &name,
187 const DbProfile &matconf)
const {
189 QString mfile = parser(matconf.value(name),
190 getList(matconf,
"OptionKeywords"),
194 return (filepath(mfile));
197 HiVector HiCalConf::getMatrix(
const QString &name,
198 int expected_size)
const {
199 return (getMatrix(name,getMatrixProfile(), expected_size));
203 QString HiCalConf::resolve(
const QString &composite,
204 const DbProfile &matconf)
const {
205 return (parser(composite,getList(matconf,
"OptionKeywords"), matconf));
233 HiVector HiCalConf::getMatrix(
const QString &name,
234 const DbProfile &profile,
235 int expected_size)
const {
237 QString mfile = getMatrixSource(name, profile);
244 if (expected_size != 0) {
245 if (cube.sampleCount() != expected_size) {
247 mess <<
"Specifed matrix (" << name
248 <<
") from file \"" << mfile
249 <<
"\" does not have expected samples (" << expected_size
250 <<
") but has " << cube.sampleCount();
257 Brick bandio(cube.sampleCount(), 1, 1, Real);
258 bandio.SetBasePosition(1,1,getMatrixBand(profile));
262 HiVector temp(cube.sampleCount(), bandio.DoubleBuffer());
283 HiVector HiCalConf::getScalar(
const QString &name,
284 const DbProfile &profile,
285 int expected_size)
const {
286 int nvals = profile.count(name);
289 if (expected_size != 0) {
290 if (nvals != expected_size) {
292 mess <<
"Specifed scalar (" << name
293 <<
") does not have expected size (" << expected_size
294 <<
") but has " << nvals;
300 for (
int i = 0 ; i < nvals ; i++) {
301 mtx[i] =
ToDouble(profile(name, i));
314 double HiCalConf::sunDistanceAU() {
318 QString scStartTime = getKey(
"SpacecraftClockStartCount",
"Instrument");
320 scs2e_c (-74999,scStartTime.toLatin1().data(),&obsStartTime);
322 QString targetName = getKey(
"TargetName",
"Instrument");
323 if (targetName.toLower() ==
"sky" ||
324 targetName.toLower() ==
"cal" ||
325 targetName.toLower() ==
"phobos" ||
326 targetName.toLower() ==
"deimos") {
331 (void) spkpos_c(targetName.toLatin1().data(), obsStartTime,
"J2000",
"LT+S",
"sun",
333 double sunkm = vnorm_c(sunv);
336 return (sunkm/1.49597870691E8);
354 int HiCalConf::getMatrixBand()
const {
356 DbProfile parms = makeParameters(label);
357 return (getMatrixBand(parms));
373 int HiCalConf::getMatrixBand(
const DbProfile &p)
const {
389 HiCalConf::ValueList HiCalConf::getList(
const DbProfile &profile,
390 const QString &key)
const {
394 if ( profile.exists(key) ) {
395 int nvals = profile.count(key);
396 for (
int i = 0 ; i < nvals ; i++) {
397 slist.push_back(profile.value(key, i));
409 void HiCalConf::loadNaifTiming( ) {
414 leapseconds = leapseconds.highestVersion();
416 Isis::FileName sclk(
"$mro/kernels/sclk/MRO_SCLKSCET.?????.65536.tsc");
417 sclk = sclk.highestVersion();
420 pck = pck.highestVersion();
423 sat = sat.highestVersion();
426 QString lsk = leapseconds.expanded();
427 QString sClock = sclk.expanded();
428 QString pConstants = pck.expanded();
429 QString satConstants = sat.expanded();
430 furnsh_c(lsk.toLatin1().data());
431 furnsh_c(sClock.toLatin1().data());
432 furnsh_c(pConstants.toLatin1().data());
433 furnsh_c(satConstants.toLatin1().data());
445 void HiCalConf::init() {
459 void HiCalConf::init(Pvl &label) {
476 PvlKeyword &HiCalConf::getKey(
const QString &key,
477 const QString &group) {
478 if (!group.isEmpty()) {
483 return (_label.findKeyword(key));
505 DbProfile HiCalConf::getMatrixProfile(
const QString &profile)
const {
506 QString myprof = (!profile.isEmpty()) ? profile : _profName;
507 DbProfile matconf = getProfile(myprof);
508 if (!matconf.isValid()) {
510 mess <<
"Specifed matrix profile (" << matconf.Name()
511 <<
") does not exist or is invalid!";
516 matconf = DbProfile(getLabelProfile(matconf), matconf, matconf.Name());
519 matconf = DbProfile(matconf, makeParameters(matconf), matconf.Name());
522 ValueList profkeys = getList(matconf,
"OptionKeywords");
523 ValueList proforder = getList(matconf,
"ProfileOptions");
524 QString pName(matconf.Name());
525 for (
unsigned int i = 0 ; i < proforder.size() ; i++) {
526 QString profile = parser(proforder[i], profkeys, matconf);
527 if (profileExists(profile)) {
528 pName +=
"+[" + profile +
"]";
529 matconf = DbProfile(matconf,getProfile(profile), pName);
536 DbProfile HiCalConf::getLabelProfile(
const DbProfile &profile)
const {
537 DbProfile lblprof(
"Label");
538 if ( profile.exists(
"LabelGroups") ) {
539 int ngroups = profile.count(
"LabelGroups");
541 for (
int g = 0 ; g < ngroups ; g++ ) {
542 QString group = profile(
"LabelGroups", g);
544 lblprof = DbProfile(lblprof,DbProfile(grp));
550 int HiCalConf::getChannelIndex(
const int &ccd,
const int &channel)
const {
551 return(1 + (ccd*2) + channel);
554 DbProfile HiCalConf::makeParameters(Pvl &label)
const {
555 PvlGroup inst = label.findGroup(
"Instrument",
Pvl::Traverse);
556 DbProfile parms(
"Parameters");
558 int ccd =
CpmmToCcd((
int) inst[
"CpmmNumber"]);
559 int channel = inst[
"ChannelNumber"];
561 parms.add(
"CHANNEL",
ToString(channel));
562 parms.add(
"TDI", inst[
"Tdi"]);
563 parms.add(
"BIN", inst[
"Summing"]);
565 parms.add(
"CCDCHANNELINDEX",
ToString(getChannelIndex(ccd, channel)));
569 DbProfile HiCalConf::makeParameters(
const DbProfile &profile)
const {
570 DbProfile parms(
"Parameters");
572 int channel =
ToInteger(profile(
"ChannelNumber"));
574 parms.add(
"CHANNEL",
ToString(channel));
575 parms.add(
"TDI", profile(
"Tdi"));
576 parms.add(
"BIN", profile(
"Summing"));
578 parms.add(
"CCDCHANNELINDEX",
ToString(getChannelIndex(ccd, channel)));
582 QString HiCalConf::makePattern(
const QString &str)
const {
583 return (QString(
"{" + str +
"}"));
597 QString HiCalConf::parser(
const QString &s,
const ValueList &vlist,
598 const DbProfile &prof)
const {
601 ValueList::const_iterator ciVlist;
602 for ( ciVlist = vlist.begin() ; ciVlist != vlist.end() ; ++ciVlist ) {
603 QString str(*ciVlist);
604 if ( prof.exists(str) ) {
605 sout = sout.replace(makePattern(str), prof(str));
const double Null
Value for an Isis Null pixel.
int CpmmToCcd(int cpmm)
Convert HiRISE Cpmm number to Ccd number.
File name manipulation and expansion.
Namespace for the standard library.
int ToInteger(const T &value)
Helper function to convert values to Integers.
QString CcdToFilter(int ccd)
Convert HiRISE Ccd number to string filter name.
#define _FILEINFO_
Macro for the filename and line number.
A type of error that could only have occurred due to a mistake on the user's part (e...
double ToDouble(const T &value)
Helper function to convert values to doubles.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Namespace for ISIS/Bullet specific routines.
QString ToString(const T &value)
Helper function to convert values to strings.
TNT::Array1D< double > HiVector
1-D Buffer