23 #include "IsisDebug.h" 
   68   Cube::Cube(
const FileName &fileName, QString access) {
 
   70     open(fileName.toString(), access);
 
   88     delete m_formatTemplateFile;
 
   89     m_formatTemplateFile = NULL;
 
   98   bool Cube::isOpen()
 const {
 
   99     bool open = (m_ioHandler != NULL);
 
  101     ASSERT(open == (
bool)m_labelFile);
 
  102     ASSERT(open == (
bool)m_labelFileName);
 
  103     ASSERT(open == (
bool)m_label);
 
  117   bool Cube::isProjected()
 const {
 
  118     return label()->findObject(
"IsisCube").hasGroup(
"Mapping");
 
  128   bool Cube::isReadOnly()
 const {
 
  129     bool readOnly = 
false;
 
  132       QString msg = 
"No cube opened";
 
  136     if ((m_labelFile->openMode() & QIODevice::ReadWrite) != QIODevice::ReadWrite)
 
  150   bool Cube::isReadWrite()
 const {
 
  151     return !isReadOnly();
 
  163   bool Cube::labelsAttached()
 const {
 
  175   void Cube::close(
bool removeIt) {
 
  176     if (isOpen() && isReadWrite())
 
  186                        QObject::tr(
"Cube::copy requires the originating cube to be open"),
 
  191     Cube *result = 
new Cube;
 
  194       result->setDimensions(sampleCount(), lineCount(), bandCount());
 
  195       result->setByteOrder(newFileAttributes.
byteOrder());
 
  196       result->setFormat(newFileAttributes.
fileFormat());
 
  199         result->setLabelsAttached(
false);
 
  203         result->setPixelType(pixelType());
 
  206         result->setPixelType(newFileAttributes.
pixelType());
 
  210         if(result->pixelType() == Isis::Real) {
 
  211           result->setBaseMultiplier(0.0, 1.0);
 
  213         else if(result->pixelType() >= pixelType()) {
 
  214           result->setBaseMultiplier(base(), multiplier());
 
  218               QObject::tr(
"Cannot reduce the output PixelType for [%1] from [%2] without output " 
  219                           "pixel range").arg(newFile.original()).arg(fileName());
 
  220           throw IException(IException::User, msg, 
_FILEINFO_);
 
  225         result->setMinMax(newFileAttributes.
minimum(), newFileAttributes.
maximum());
 
  228       result->setLabelSize(labelSize(
true) + (1024 * 6));
 
  233         m_ioHandler->clearCache(
true);
 
  236       result->setExternalDnData(fileName());
 
  240     result->create(newFile.expanded());
 
  242     PvlObject &isisCube = label()->findObject(
"IsisCube");
 
  243     PvlObject &outIsisCube = result->label()->findObject(
"IsisCube");
 
  244     for(
int i = 0; i < isisCube.groups(); i++) {
 
  245       outIsisCube.addGroup(isisCube.group(i));
 
  248     if (label()->hasObject(
"NaifKeywords")) {
 
  249       result->label()->addObject(
 
  250           label()->findObject(
"NaifKeywords"));
 
  253     for (
int i = 0; i < m_label->objects(); i++) {
 
  254       PvlObject &obj = m_label->object(i);
 
  255       if (obj.isNamed(
"Table") || obj.isNamed(
"Polygon") || obj.isNamed(
"OriginalLabel") ||
 
  256           obj.isNamed(
"History")) {
 
  257         Isis::Blob t((QString)obj[
"Name"], obj.name());
 
  264       BufferManager input(sampleCount(), lineCount(), bandCount(),
 
  267       BufferManager output(sampleCount(), lineCount(), bandCount(),
 
  269                            result->pixelType());
 
  274       while (!input.end()) {
 
  276         output.Copy(input, 
false);
 
  278         result->write(output);
 
  321   void Cube::create(
const QString &cubeFileName) {
 
  324       string msg = 
"You already have a cube opened";
 
  328     if (m_samples < 1 || m_lines < 1 || m_bands < 1) {
 
  329       QString msg = 
"Number of samples [" + 
toString(m_samples) +
 
  331           "] cannot be less than 1";
 
  335     if (m_pixelType == None) {
 
  337           QString(
"Cannot create the cube [%1] with a pixel type set to None")
 
  342     if (m_storesDnData) {
 
  344       BigInt size = (BigInt)m_samples * m_lines *
 
  345                     (BigInt)m_bands * (BigInt)
SizeOf(m_pixelType);
 
  351       int maxSizePreference = 0;
 
  354           Preference::Preferences().findGroup(
"CubeCustomization")[
"MaximumSize"];
 
  356       if (size > maxSizePreference) {
 
  358         msg += 
"The cube you are attempting to create [" + cubeFileName + 
"] is [" 
  359                + 
toString(size) + 
"GB]. This is larger than the current allowed " 
  360                "size of [" + 
toString(maxSizePreference) + 
"GB]. The cube " 
  361                "dimensions were (S,L,B) [" + 
toString(m_samples) + 
", " +
 
  363                toString(
SizeOf(m_pixelType)) + 
"] bytes per pixel. If you still " 
  364                "wish to create this cube, the maximum value can be changed in the" 
  365                " file [~/.Isis/IsisPreferences] within the group " 
  366                "CubeCustomization, keyword MaximumSize.";
 
  376     if (m_storesDnData) {
 
  377       cubFile = cubFile.addExtension(
"cub");
 
  383         m_labelFileName = 
new FileName(cubFile);
 
  384         m_dataFileName = 
new FileName(cubFile);
 
  385         m_labelFile = 
new QFile(m_labelFileName->expanded());
 
  390         m_dataFileName = 
new FileName(cubFile);
 
  391         m_dataFile = 
new QFile(realDataFileName().expanded());
 
  394         labelFileName = labelFileName.setExtension(
"lbl");
 
  395         m_labelFileName = 
new FileName(labelFileName);
 
  396         m_labelFile = 
new QFile(m_labelFileName->expanded());
 
  411       ptype += 
PvlKeyword(
"ByteOrder", ByteOrderName(m_byteOrder));
 
  417       cubFile = cubFile.addExtension(
"ecub");
 
  419       ASSERT(m_dataFileName);
 
  421       core += 
PvlKeyword(
"^DnFile", m_dataFileName->original());
 
  423       m_dataFile = 
new QFile(realDataFileName().expanded());
 
  425       m_labelFileName = 
new FileName(cubFile);
 
  426       m_labelFile = 
new QFile(cubFile.expanded());
 
  437     m_label->addObject(lbl);
 
  440         Preference::Preferences().findGroup(
"CubeCustomization");
 
  441     bool overwrite = pref[
"Overwrite"][0].toUpper() == 
"ALLOW";
 
  442     if (!overwrite && m_labelFile->exists() && m_labelFile->size()) {
 
  443       QString msg = 
"Cube file [" + m_labelFileName->original() + 
"] exists, " +
 
  444                    "user preference does not allow overwrite";
 
  448     if (!m_labelFile->open(QIODevice::Truncate | QIODevice::ReadWrite)) {
 
  449       QString msg = 
"Failed to create [" + m_labelFile->fileName() + 
"]";
 
  455       if (m_storesDnData && !m_dataFile->open(QIODevice::Truncate | QIODevice::ReadWrite)) {
 
  456         QString msg = 
"Failed to create [" + m_dataFile->fileName() + 
"]";
 
  460       else if (!m_storesDnData && !m_dataFile->open(QIODevice::ReadOnly)) {
 
  461         QString msg = 
"Failed to open [" + m_dataFile->fileName() + 
"] for reading";
 
  467     bool dataAlreadyOnDisk = m_storesDnData ? 
false : 
true;
 
  469     if (m_format == Bsq) {
 
  470       m_ioHandler = 
new CubeBsqHandler(dataFile(), m_virtualBandList, realDataFileLabel(),
 
  474       m_ioHandler = 
new CubeTileHandler(dataFile(), m_virtualBandList, realDataFileLabel(),
 
  479       m_ioHandler->updateLabels(*m_label);
 
  497     create(cubeFileName);
 
  509   void Cube::open(
const QString &cubeFileName, QString access) {
 
  513       string msg = 
"You already have a cube opened";
 
  517     initLabelFromFile(cubeFileName, (access == 
"rw"));
 
  525         if (!temp.originalPath().startsWith(
"/")) {
 
  526           m_dataFileName = 
new FileName(m_labelFileName->path() + 
"/" + temp.original());
 
  529           m_dataFileName = 
new FileName(temp);
 
  533         m_storesDnData = 
true;
 
  535         m_dataFile = 
new QFile(realDataFileName().expanded());
 
  538         FileName dataFileName(core[
"^DnFile"][0]);
 
  540         if (dataFileName.originalPath() == 
".") {
 
  541           m_dataFileName = 
new FileName(m_labelFileName->path() + 
"/" + dataFileName.name());
 
  544           m_dataFileName = 
new FileName(dataFileName);
 
  548         m_storesDnData = 
false;
 
  550         m_dataFile = 
new QFile(realDataFileName().expanded());
 
  553         m_dataFileName = 
new FileName(*m_labelFileName);
 
  555         m_storesDnData = 
true;
 
  564       if (!m_labelFile->open(QIODevice::ReadOnly)) {
 
  565         QString msg = 
"Failed to open [" + m_labelFile->fileName() + 
"] with " 
  572         if (!m_dataFile->open(QIODevice::ReadOnly)) {
 
  573           QString msg = 
"Failed to open [" + m_dataFile->fileName() + 
"] with " 
  581     else if (access == 
"rw") {
 
  582       if (!m_labelFile->open(QIODevice::ReadWrite)) {
 
  583         QString msg = 
"Failed to open [" + m_labelFile->fileName() + 
"] with " 
  590         if (m_storesDnData && !m_dataFile->open(QIODevice::ReadWrite)) {
 
  591           QString msg = 
"Failed to open [" + m_dataFile->fileName() + 
"] with " 
  596         else if (!m_storesDnData && !m_dataFile->open(QIODevice::ReadOnly)) {
 
  597           QString msg = 
"Failed to open [" + m_dataFile->fileName() + 
"] with " 
  605       QString msg = 
"Unknown value for access [" + access + 
"]. Expected 'r' " 
  611     initCoreFromLabel(*m_label);
 
  615       m_labelBytes = m_label->findObject(
"Label")[
"Bytes"];
 
  618       m_labelBytes = labelSize(
true);
 
  622     if (!m_storesDnData) {
 
  623       dataLabel = qMakePair(
true, 
new Pvl(m_dataFileName->expanded()));
 
  627     if (m_format == Bsq) {
 
  629           realDataFileLabel(), 
true);
 
  633           realDataFileLabel(), 
true);
 
  636     if (dataLabel.first) {
 
  637       delete dataLabel.second;
 
  638       dataLabel.second = NULL;
 
  641     applyVirtualBandsToLabel();
 
  653   void Cube::reopen(QString access) {
 
  655       QString msg = 
"Cube has not been opened yet. The filename to re-open is " 
  661     FileName filename = *m_labelFileName;
 
  664     if (m_virtualBandList)
 
  665       virtualBandList = *m_virtualBandList;
 
  668     open(filename.expanded(), access);
 
  670     if (virtualBandList.size()) {
 
  671       if (m_virtualBandList)
 
  672         *m_virtualBandList = virtualBandList;
 
  674         m_virtualBandList = 
new QList<int>(virtualBandList);
 
  686   void Cube::read(
Blob &blob)
 const {
 
  688       string msg = 
"The cube is not opened so you can't read a blob from it";
 
  692     FileName cubeFile = *m_labelFileName;
 
  694       cubeFile = *m_tempCube;
 
  696     QMutexLocker locker(m_mutex);
 
  697     QMutexLocker locker2(m_ioHandler->dataFileMutex());
 
  698     blob.
Read(cubeFile.toString(), *label());
 
  708   void Cube::read(
Buffer &bufferToFill)
 const {
 
  710       string msg = 
"Try opening a file before you read it";
 
  714     QMutexLocker locker(m_mutex);
 
  715     m_ioHandler->read(bufferToFill);
 
  727       string msg = 
"The cube is not opened so you can't write a blob to it";
 
  731     if (!m_labelFile->isWritable()) {
 
  732       string msg = 
"The cube must be opened in read/write mode, not readOnly";
 
  738       QMutexLocker locker(m_mutex);
 
  739       QMutexLocker locker2(m_ioHandler->dataFileMutex());
 
  743       fstream stream(m_labelFileName->expanded().toLatin1().data(),
 
  744                      ios::in | ios::out | ios::binary);
 
  745       stream.seekp(0, ios::end);
 
  748       streampos endByte = stream.tellp();
 
  750       streampos maxbyte = (streampos) m_labelBytes;
 
  752       if (m_storesDnData) {
 
  753         maxbyte += (streampos) m_ioHandler->getDataSize();
 
  757       if (endByte < maxbyte) {
 
  758         stream.seekp(maxbyte, ios::beg);
 
  761       blob.
Write(*m_label, stream);
 
  767       blobFileName = blobFileName.removeExtension();
 
  768       blobFileName = blobFileName.addExtension(blob.
Type());
 
  769       blobFileName = blobFileName.addExtension(blob.
Name());
 
  770       QString blobFile(blobFileName.expanded());
 
  771       ios::openmode flags = ios::in | ios::binary | ios::out | ios::trunc;
 
  772       fstream detachedStream;
 
  773       detachedStream.open(blobFile.toLatin1().data(), flags);
 
  774       if (!detachedStream) {
 
  775         QString message = 
"Unable to open data file [" +
 
  776                           blobFileName.expanded() + 
"]";
 
  784       blob.
Write(*m_label, detachedStream, blobFileName.name());
 
  795   void Cube::write(
Buffer &bufferToWrite) {
 
  797       string msg = 
"Tried to write to a cube before opening/creating it";
 
  802       QString msg = 
"Cannot write to the cube [" + (QString)QFileInfo(fileName()).fileName() +
 
  803           "] because it is opened read-only";
 
  807     if (!m_storesDnData) {
 
  808       QString msg = 
"The cube [" + QFileInfo(fileName()).fileName() +
 
  809           "] does not support storing DN data because it is using an external file for DNs";
 
  813     QMutexLocker locker(m_mutex);
 
  814     m_ioHandler->write(bufferToWrite);
 
  828   void Cube::setBaseMultiplier(
double base, 
double mult) {
 
  845   void Cube::setMinMax(
double min, 
double max) {
 
  852     if (m_pixelType == UnsignedByte) {
 
  855       m_multiplier = (max - min) / (x2 - x1);
 
  856       m_base = min - m_multiplier * x1;
 
  858     else if (m_pixelType == SignedWord) {
 
  861       m_multiplier = (max - min) / (x2 - x1);
 
  862       m_base = min - m_multiplier * x1;
 
  864     else if (m_pixelType == UnsignedWord) {
 
  867       m_multiplier = (max - min) / (x2 - x1);
 
  868       m_base = min - m_multiplier * x1;
 
  881     m_byteOrder = byteOrder;
 
  894   void Cube::setDimensions(
int ns, 
int nl, 
int nb) {
 
  896     if ((ns < 1) || (nl < 1) || (nb < 1)) {
 
  897       string msg = 
"SetDimensions:  Invalid number of sample, lines or bands";
 
  906   void Cube::setExternalDnData(
FileName cubeFileWithDnData) {
 
  908       initLabelFromFile(cubeFileWithDnData, 
false);
 
  909       initCoreFromLabel(*m_label);
 
  914     catch (IException &) {
 
  920     m_storesDnData = 
false;
 
  921     m_dataFileName = 
new FileName(cubeFileWithDnData);
 
  926     delete m_labelFileName;
 
  927     m_labelFileName = NULL;
 
  950   void Cube::setLabelsAttached(
bool attach) {
 
  963   void Cube::setLabelSize(
int labelBytes) {
 
  965     m_labelBytes = labelBytes;
 
  978     m_pixelType = pixelType;
 
  995     if (m_virtualBandList)
 
  996       m_virtualBandList->clear();
 
 1000     if (vbands.size() > 0) {
 
 1001       QListIterator<QString> it(vbands);
 
 1002       while (it.hasNext()) {
 
 1003         m_virtualBandList->append(
toInt(it.next()));
 
 1007       delete m_virtualBandList;
 
 1008       m_virtualBandList = NULL;
 
 1012       m_ioHandler->setVirtualBands(m_virtualBandList);
 
 1023   void Cube::setVirtualBands(
const std::vector<QString> &vbands) {
 
 1026     for(
unsigned int i = 0; i < vbands.size(); i++)
 
 1027       realVBands << vbands[i];
 
 1029     setVirtualBands(realVBands);
 
 1033   void Cube::relocateDnData(
FileName dnDataFile) {
 
 1036                        QString(
"Cannot relocate the DN data to [%1] for an external cube label " 
 1037                                "file which is not open.")
 
 1038                          .arg(dnDataFile.original()),
 
 1043     if (m_storesDnData) {
 
 1044       throw IException(IException::Unknown,
 
 1045                        QString(
"The cube [%1] stores DN data. It cannot be relocated to [%2] - " 
 1046                                "this is only supported for external cube label files.")
 
 1047                          .arg(m_labelFileName->original()).arg(dnDataFile.original()),
 
 1051     m_label->findObject(
"IsisCube").findObject(
"Core").findKeyword(
"^DnFile")[0] =
 
 1052         dnDataFile.original();
 
 1053     reopen(m_labelFile->isWritable()? 
"rw" : 
"r");
 
 1077   int Cube::bandCount()
 const {
 
 1078     int numBands = m_bands;
 
 1079     if (m_virtualBandList)
 
 1080       numBands = m_virtualBandList->size();
 
 1094   double Cube::base()
 const {
 
 1119     if (m_camera == NULL && isOpen()) {
 
 1120       m_camera = CameraFactory::Create(*
this);
 
 1135                        "An external cube label file must be opened in order to use " 
 1136                          "Cube::getExternalCubeFileName",
 
 1140     if (storesDnData()) {
 
 1142                        "Cube::getExternalCubeFileName can only be called on an external cube label " 
 1150     return core[
"^DnFile"][0];
 
 1160   QString Cube::fileName()
 const {
 
 1162       return m_labelFileName->expanded();
 
 1226   Histogram *Cube::histogram(
const int &band, 
const double &validMin,
 
 1227                                 const double &validMax, QString msg) {
 
 1230       QString msg = 
"Cannot create histogram object for an unopened cube";
 
 1235     if ((band < 0) || (band > bandCount())) {
 
 1236       QString msg = 
"Invalid band in [CubeInfo::Histogram]";
 
 1240     int bandStart = band;
 
 1241     int bandStop = band;
 
 1242     int maxSteps = lineCount();
 
 1245       bandStop = bandCount();
 
 1246       maxSteps = lineCount() * bandCount();
 
 1258     double binMin = validMin;
 
 1259     double binMax = validMax;
 
 1261       binMin = hist->BinRangeStart();
 
 1265       binMax = hist->BinRangeEnd();
 
 1276     for(
int useBand = bandStart ; useBand <= bandStop ; useBand++) {
 
 1277       for(
int i = 1; i <= lineCount(); i++) {
 
 1310   int Cube::labelSize(
bool actual)
 const {
 
 1311     int labelSize = m_labelBytes;
 
 1313     if (actual && m_label) {
 
 1315       s << *m_label << endl;
 
 1316       labelSize = s.tellp();
 
 1331   int Cube::lineCount()
 const {
 
 1345   double Cube::multiplier()
 const {
 
 1346     return m_multiplier;
 
 1370   int Cube::physicalBand(
const int &virtualBand)
 const {
 
 1371     int physicalBand = virtualBand;
 
 1373     if (m_virtualBandList) {
 
 1374       if ((virtualBand < 1) ||
 
 1375           (virtualBand > m_virtualBandList->size())) {
 
 1376         QString msg = 
"Out of array bounds [" + 
toString(virtualBand) + 
"]";
 
 1379       physicalBand = m_virtualBandList->at(virtualBand - 1);
 
 1382     return physicalBand;
 
 1392     if (m_projection == NULL && isOpen()) {
 
 1393       m_projection =  ProjectionFactory::CreateFromCube(*label());
 
 1395     return m_projection;
 
 1404   int Cube::sampleCount()
 const {
 
 1448   Statistics *Cube::statistics(
const int &band, 
const double &validMin,
 
 1449                                      const double &validMax, QString msg) {
 
 1452       QString msg = 
"Cannot create statistics object for an unopened cube";
 
 1457     if ((band < 0) || (band > bandCount())) {
 
 1458       string msg = 
"Invalid band in [CubeInfo::Statistics]";
 
 1466     stats->SetValidRange(validMin, validMax);
 
 1468     int bandStart = band;
 
 1469     int bandStop = band;
 
 1470     int maxSteps = lineCount();
 
 1473       bandStop = bandCount();
 
 1474       maxSteps = lineCount() * bandCount();
 
 1483     for(
int useBand = bandStart ; useBand <= bandStop ; useBand++) {
 
 1484       for(
int i = 1; i <= lineCount(); i++) {
 
 1496   bool Cube::storesDnData()
 const {
 
 1497     return m_storesDnData;
 
 1516     if (isOpen() && m_ioHandler) {
 
 1517       m_ioHandler->addCachingAlgorithm(algorithm);
 
 1519     else if (!isOpen()) {
 
 1520       QString msg = 
"Cannot add a caching algorithm until the cube is open";
 
 1530   void Cube::clearIoCache() {
 
 1532       QMutexLocker locker(m_mutex);
 
 1533       m_ioHandler->clearCache();
 
 1547   bool Cube::deleteBlob(QString BlobType, QString BlobName) {
 
 1548     for(
int i = 0; i < m_label->objects(); i++) {
 
 1550       if (obj.
name().compare(BlobType) == 0) {
 
 1569   void Cube::deleteGroup(
const QString &group) {
 
 1571     if (!isiscube.
hasGroup(group)) 
return;
 
 1596   bool Cube::hasGroup(
const QString &group)
 const {
 
 1598     if (isiscube.
hasGroup(group)) 
return true;
 
 1610   bool Cube::hasTable(
const QString &name) {
 
 1611     for(
int o = 0; o < label()->objects(); o++) {
 
 1615           QString temp = (QString) obj[
"Name"];
 
 1616           temp = temp.toUpper();
 
 1617           QString temp2 = name;
 
 1618           temp2 = temp2.toUpper();
 
 1619           if (temp == temp2) 
return true;
 
 1637       QString msg = 
"Cannot add a group to the label of cube [" + (QString)QFileInfo(fileName()).fileName() +
 
 1638           "] because it is opened read-only";
 
 1653   void Cube::applyVirtualBandsToLabel() {
 
 1657     if (m_label->findObject(
"IsisCube").hasGroup(
"BandBin")) {
 
 1658       PvlGroup &bandBin = m_label->findObject(
"IsisCube").findGroup(
"BandBin");
 
 1659       for (
int k = 0;k < bandBin.
keywords();k++) {
 
 1660         if (bandBin[k].size() == m_bands && m_virtualBandList) {
 
 1663           for (
int i = 0;i < m_virtualBandList->size();i++) {
 
 1664             int physicalBand = m_virtualBandList->at(i) - 1;
 
 1665             bandBin[k].addValue(temp[physicalBand], temp.
unit(physicalBand));
 
 1672     if (m_virtualBandList && core.
hasGroup(
"Dimensions")) core.
findGroup(
"Dimensions")[
"Bands"] = 
toString(m_virtualBandList->size());
 
 1681   void Cube::cleanUp(
bool removeIt) {
 
 1689       QFile::remove(m_tempCube->expanded());
 
 1697       QFile::remove(m_labelFileName->expanded());
 
 1699       if (*m_labelFileName != *m_dataFileName)
 
 1700         QFile::remove(m_dataFileName->expanded());
 
 1709     delete m_labelFileName;
 
 1710     m_labelFileName = NULL;
 
 1712     delete m_dataFileName;
 
 1713     m_dataFileName = NULL;
 
 1718     delete m_virtualBandList;
 
 1719     m_virtualBandList = NULL;
 
 1729   void Cube::construct() {
 
 1736     m_projection = NULL;
 
 1738     m_labelFileName = NULL;
 
 1739     m_dataFileName = NULL;
 
 1741     m_formatTemplateFile = NULL;
 
 1744     m_virtualBandList = NULL;
 
 1746     m_mutex = 
new QMutex();
 
 1747     m_formatTemplateFile =
 
 1748          new FileName(
"$base/templates/labels/CubeFormatTemplate.pft");
 
 1760   QFile *Cube::dataFile()
 const {
 
 1777     if (m_attached && m_storesDnData) {
 
 1778       ASSERT(m_labelFileName);
 
 1779       result = *m_labelFileName;
 
 1782     else if (!m_attached && m_storesDnData) {
 
 1783       ASSERT(m_dataFileName);
 
 1784       result = *m_dataFileName;
 
 1787     else if (!m_storesDnData) {
 
 1788       ASSERT(m_dataFileName);
 
 1792         Pvl guessLabel(guess.expanded());
 
 1796         if (core.hasKeyword(
"^DnFile")) {
 
 1798           guess = core[
"^DnFile"][0];
 
 1800           if (!guess.
path().startsWith(
"/")) {
 
 1801             guess = currentGuess.
path() + 
"/" + guess.original();
 
 1804         else if (core.hasKeyword(
"^Core")) {
 
 1805           result = core[
"^Core"][0];
 
 1811       while (result.name() == 
"");
 
 1829   void Cube::initialize() {
 
 1837     m_storesDnData = 
true;
 
 1838     m_labelBytes = 65536;
 
 1849   void Cube::initCoreFromLabel(
const Pvl &label) {
 
 1855       m_samples = dims[
"Samples"];
 
 1856       m_lines = dims[
"Lines"];
 
 1857       m_bands = dims[
"Bands"];
 
 1861       m_byteOrder = ByteOrderEnumeration(pixelsGroup[
"ByteOrder"]);
 
 1862       m_base = pixelsGroup[
"Base"];
 
 1863       m_multiplier = pixelsGroup[
"Multiplier"];
 
 1867       if ((QString) core[
"Format"] == 
"BandSequential") {
 
 1875       FileName temp(core[
"^DnFile"][0]);
 
 1876       if (!temp.expanded().startsWith(
"/")) {
 
 1877         temp = FileName(m_labelFileName->path() + 
"/" + temp.original());
 
 1880       initCoreFromLabel(Pvl(temp.toString()));
 
 1885   void Cube::initLabelFromFile(FileName labelFileName, 
bool readWrite) {
 
 1886     ASSERT(!m_labelFileName);
 
 1889       if (labelFileName.fileExists()) {
 
 1890         m_label = 
new Pvl(labelFileName.expanded());
 
 1891         if (!m_label->objects()) {
 
 1896     catch(IException &) {
 
 1905         FileName tmp(labelFileName);
 
 1906         tmp = tmp.addExtension(
"cub");
 
 1907         if (tmp.fileExists()) {
 
 1908           m_label = 
new Pvl(tmp.expanded());
 
 1909           if (!m_label->objects()) {
 
 1912           labelFileName = tmp;
 
 1916     catch(IException &e) {
 
 1925         FileName tmp(labelFileName);
 
 1926         tmp = tmp.setExtension(
"lbl");
 
 1927         if (tmp.fileExists()) {
 
 1928           m_label = 
new Pvl(tmp.expanded());
 
 1929           if (!m_label->objects()) {
 
 1932           labelFileName = tmp;
 
 1936     catch(IException &e) {
 
 1945         FileName tmp(labelFileName);
 
 1946         tmp = tmp.addExtension(
"ecub");
 
 1947         if (tmp.fileExists()) {
 
 1948           m_label = 
new Pvl(tmp.expanded());
 
 1949           if (!m_label->objects()) {
 
 1952           labelFileName = tmp;
 
 1956     catch(IException &e) {
 
 1965       throw IException(IException::Io, msg, 
_FILEINFO_);
 
 1968     m_labelFileName = 
new FileName(labelFileName);
 
 1972     if (m_label->hasKeyword(
"CCSD3ZF0000100000001NJPL3IF0PDS200000001")) {
 
 1974         reformatOldIsisLabel(m_labelFileName->expanded());
 
 1977         QString msg = 
"Can not open [" + m_labelFileName->original() + 
"]" 
 1978                       " because it is an ISIS2 cube.";
 
 1980         throw IException(IException::Io, msg, 
_FILEINFO_);
 
 1984       m_labelFile = 
new QFile(m_labelFileName->expanded());
 
 1992   void Cube::openCheck() {
 
 1994       string msg = 
"Sorry you can't do a SetMethod after the cube is opened";
 
 1999   Pvl Cube::realDataFileLabel()
 const {
 
 2000     Pvl label = *m_label;
 
 2004       core = &label.
findObject(
"IsisCube").findObject(
"Core");
 
 2008         FileName temp((*core)[
"^DnFile"][0]);
 
 2009         if (!temp.expanded().startsWith(
"/")) {
 
 2013         label = Pvl(temp.toString());
 
 2029   void Cube::reformatOldIsisLabel(
const QString &oldCube) {
 
 2030     QString parameters = 
"from=" + oldCube;
 
 2032     FileName tempCube = FileName::createTempFile(
"Temporary_" + oldName.name() + 
".cub");
 
 2033     parameters += 
" to=" + tempCube.expanded();
 
 2036       QString command = 
"$ISISROOT/bin/pds2isis " + parameters;
 
 2037       ProgramLauncher::RunSystemCommand(command);
 
 2040       QString prog = 
"pds2isis";
 
 2041       ProgramLauncher::RunIsisProgram(prog, parameters);
 
 2044     m_tempCube = 
new FileName(tempCube);
 
 2045     *m_label = 
Pvl(m_tempCube->toString());
 
 2046     m_labelFile = 
new QFile(m_tempCube->expanded());
 
 2054   void Cube::writeLabels() {
 
 2056       string msg = 
"Cube must be opened first before writing labels";
 
 2061     m_label->setFormatTemplate(m_formatTemplateFile->original());
 
 2065       QMutexLocker locker(m_mutex);
 
 2066       QMutexLocker locker2(m_ioHandler->dataFileMutex());
 
 2069       temp << *m_label << endl;
 
 2070       string tempstr = temp.str();
 
 2071       if ((
int) tempstr.length() < m_labelBytes) {
 
 2072         QByteArray labelArea(m_labelBytes, 
'\0');
 
 2073         QByteArray labelUnpaddedContents(tempstr.c_str(), tempstr.length());
 
 2074         labelArea.replace(0, labelUnpaddedContents.size(), labelUnpaddedContents);
 
 2076         m_labelFile->seek(0);
 
 2077         m_labelFile->write(labelArea);
 
 2081         QString msg = 
"Label space is full in [" +
 
 2082             (QString)
FileName(*m_labelFileName).name() +
 
 2083                      "] unable to write labels";
 
 2091       m_label->write(m_labelFileName->expanded());
 
PvlObject & object(const int index)
Return the object at the specified index. 
 
bool SetLine(const int line, const int band=1)
Positions the buffer at the requested line and returns a status indicator if the set was succesful or...
 
Buffer for reading and writing cube data. 
 
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the histogram counters. 
 
The label is pointing to an external DN file - the label is also external to the data. 
 
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process. 
 
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes. 
 
bool propagateMinimumMaximum() const 
Return true if the min/max are to be propagated from an input cube. 
 
const double ValidMinimum
The minimum valid double value for Isis pixels. 
 
double maximum() const 
Return the output cube attribute maximum. 
 
bool propagatePixelType() const 
Return true if the pixel type is to be propagated from an input cube. 
 
File name manipulation and expansion. 
 
IO Handler for Isis Cubes using the BSQ format. 
 
void Read(const QString &file)
This method reads Pvl values from a specified file. 
 
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes. 
 
int keywords() const 
Returns the number of keywords contained in the PvlContainer. 
 
int SizeOf(Isis::PixelType pixelType)
Returns the number of bytes of the specified PixelType. 
 
void addGroup(const Isis::PvlGroup &group)
Add a group to the object. 
 
void Write(const QString &file)
Write the blob data out to a file. 
 
int toInt(const QString &string)
Global function to convert from a string to an integer. 
 
QString PixelTypeName(Isis::PixelType pixelType)
Returns string name of PixelType enumeration entered as input parameter. 
 
ByteOrder
Tests the current architecture for byte order. 
 
double * DoubleBuffer() const 
Returns the value of the shape buffer. 
 
QString fileName() const 
Returns the filename used to initialise the Pvl object. 
 
QString toString(bool boolToConvert)
Global function to convert a boolean to a string. 
 
void deleteGroup(const QString &name)
Remove a group from the current PvlObject. 
 
void CheckStatus()
Checks and updates the status. 
 
PixelType
Enumerations for Isis Pixel Types. 
 
void addObject(const PvlObject &object)
Add a PvlObject. 
 
Buffer manager, for moving through a cube in lines. 
 
This class is used to accumulate statistics on double arrays. 
 
bool hasKeyword(const QString &kname, FindOptions opts) const 
See if a keyword is in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within ...
 
void SetValidRange(const double minimum=Isis::ValidMinimum, const double maximum=Isis::ValidMaximum)
Changes the range of the bins. 
 
The input label is in a separate data file from the image. 
 
Isis::PixelType PixelTypeEnumeration(const QString &type)
Returns PixelType enumeration given a string. 
 
Base class for Map Projections. 
 
Program progress reporter. 
 
Container of a cube histogram. 
 
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed. 
 
PvlKeyword & findKeyword(const QString &kname, FindOptions opts)
Finds a keyword in the current PvlObject, or deeper inside other PvlObjects and Pvlgroups within this...
 
Contains multiple PvlContainers. 
 
#define _FILEINFO_
Macro for the filename and line number. 
 
Manipulate and parse attributes of output cube filenames. 
 
A single keyword-value pair. 
 
QString unit(const int index=0) const 
Returns the units of measurement of the element of the array of values for the object at the specifie...
 
Cube::Format fileFormat() const 
Return the file format an Cube::Format. 
 
QString Type() const 
Accessor method that returns a string containing the Blob type. 
 
The input label is embedded in the image file. 
 
IO Handler for Isis Cubes using the tile format. 
 
double minimum() const 
Return the output cube attribute minimum. 
 
Container for cube-like labels. 
 
void deleteObject(const QString &name)
Remove an object from the current PvlObject. 
 
const double ValidMaximum
The maximum valid double value for Isis pixels. 
 
int size() const 
Returns the total number of pixels in the shape buffer. 
 
QString Name() const 
Accessor method that returns a string containing the Blob name. 
 
QString FileOpen(const QString &filename)
This error should be used when a file could not be opened. 
 
ByteOrder byteOrder() const 
Return the byte order as an Isis::ByteOrder. 
 
bool isNamed(const QString &match) const 
Returns whether the given string is equal to the container name or not. 
 
bool hasGroup(const QString &name) const 
Returns a boolean value based on whether the object has the specified group or not. 
 
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters. 
 
Contains Pvl Groups and Pvl Objects. 
 
QString path() const 
Returns the path. 
 
Format
These are the possible storage formats of Isis3 cubes. 
 
This is the parent of the caching algorithms. 
 
void clear()
Clears PvlKeywords. 
 
QString name() const 
Returns the container name. 
 
IO Handler for Isis Cubes. 
 
PixelType pixelType() const 
Return the pixel type as an Isis::PixelType.