23 #include "IsisDebug.h"
68 Cube::Cube(
const FileName &fileName, QString access) {
70 open(fileName.toString(), access);
87 delete m_formatTemplateFile;
88 m_formatTemplateFile = NULL;
97 bool Cube::isOpen()
const {
98 bool open = (m_ioHandler != NULL);
100 ASSERT(open == (
bool)m_labelFile);
101 ASSERT(open == (
bool)m_labelFileName);
102 ASSERT(open == (
bool)m_label);
116 bool Cube::isProjected()
const {
117 return label()->findObject(
"IsisCube").hasGroup(
"Mapping");
127 bool Cube::isReadOnly()
const {
128 bool readOnly =
false;
131 QString msg =
"No cube opened";
135 if ((m_labelFile->openMode() & QIODevice::ReadWrite) != QIODevice::ReadWrite)
149 bool Cube::isReadWrite()
const {
150 return !isReadOnly();
162 bool Cube::labelsAttached()
const {
174 void Cube::close(
bool removeIt) {
175 if (isOpen() && isReadWrite())
185 QObject::tr(
"Cube::copy requires the originating cube to be open"),
190 Cube *result =
new Cube;
193 result->setDimensions(sampleCount(), lineCount(), bandCount());
194 result->setByteOrder(newFileAttributes.
byteOrder());
195 result->setFormat(newFileAttributes.
fileFormat());
198 result->setLabelsAttached(
false);
202 result->setPixelType(pixelType());
205 result->setPixelType(newFileAttributes.
pixelType());
209 if(result->pixelType() == Isis::Real) {
210 result->setBaseMultiplier(0.0, 1.0);
212 else if(result->pixelType() >= pixelType()) {
213 result->setBaseMultiplier(base(), multiplier());
217 QObject::tr(
"Cannot reduce the output PixelType for [%1] from [%2] without output "
218 "pixel range").arg(newFile.original()).arg(fileName());
219 throw IException(IException::User, msg,
_FILEINFO_);
224 result->setMinMax(newFileAttributes.
minimum(), newFileAttributes.
maximum());
227 result->setLabelSize(labelSize(
true) + (1024 * 6));
232 m_ioHandler->clearCache(
true);
235 result->setExternalDnData(fileName());
239 result->create(newFile.expanded());
241 PvlObject &isisCube = label()->findObject(
"IsisCube");
242 PvlObject &outIsisCube = result->label()->findObject(
"IsisCube");
243 for(
int i = 0; i < isisCube.groups(); i++) {
244 outIsisCube.addGroup(isisCube.group(i));
247 if (label()->hasObject(
"NaifKeywords")) {
248 result->label()->addObject(
249 label()->findObject(
"NaifKeywords"));
252 for (
int i = 0; i < m_label->objects(); i++) {
253 PvlObject &obj = m_label->object(i);
254 if (obj.isNamed(
"Table") || obj.isNamed(
"Polygon") || obj.isNamed(
"OriginalLabel") ||
255 obj.isNamed(
"History")) {
256 Isis::Blob t((QString)obj[
"Name"], obj.name());
263 BufferManager input(sampleCount(), lineCount(), bandCount(),
266 BufferManager output(sampleCount(), lineCount(), bandCount(),
268 result->pixelType());
273 while (!input.end()) {
275 output.Copy(input,
false);
277 result->write(output);
320 void Cube::create(
const QString &cubeFileName) {
323 string msg =
"You already have a cube opened";
327 if (m_samples < 1 || m_lines < 1 || m_bands < 1) {
328 QString msg =
"Number of samples [" +
toString(m_samples) +
330 "] cannot be less than 1";
334 if (m_pixelType == None) {
336 QString(
"Cannot create the cube [%1] with a pixel type set to None")
341 if (m_storesDnData) {
343 BigInt size = (BigInt)m_samples * m_lines *
344 (BigInt)m_bands * (BigInt)
SizeOf(m_pixelType);
350 int maxSizePreference = 0;
353 Preference::Preferences().findGroup(
"CubeCustomization")[
"MaximumSize"];
355 if (size > maxSizePreference) {
357 msg +=
"The cube you are attempting to create [" + cubeFileName +
"] is ["
358 +
toString(size) +
"GB]. This is larger than the current allowed "
359 "size of [" +
toString(maxSizePreference) +
"GB]. The cube "
360 "dimensions were (S,L,B) [" +
toString(m_samples) +
", " +
362 toString(
SizeOf(m_pixelType)) +
"] bytes per pixel. If you still "
363 "wish to create this cube, the maximum value can be changed in the"
364 " file [~/.Isis/IsisPreferences] within the group "
365 "CubeCustomization, keyword MaximumSize.";
375 if (m_storesDnData) {
376 cubFile = cubFile.addExtension(
"cub");
382 m_labelFileName =
new FileName(cubFile);
383 m_dataFileName =
new FileName(cubFile);
384 m_labelFile =
new QFile(m_labelFileName->expanded());
389 m_dataFileName =
new FileName(cubFile);
390 m_dataFile =
new QFile(realDataFileName().expanded());
393 labelFileName = labelFileName.setExtension(
"lbl");
394 m_labelFileName =
new FileName(labelFileName);
395 m_labelFile =
new QFile(m_labelFileName->expanded());
410 ptype +=
PvlKeyword(
"ByteOrder", ByteOrderName(m_byteOrder));
416 cubFile = cubFile.addExtension(
"ecub");
418 ASSERT(m_dataFileName);
420 core +=
PvlKeyword(
"^DnFile", m_dataFileName->original());
422 m_dataFile =
new QFile(realDataFileName().expanded());
424 m_labelFileName =
new FileName(cubFile);
425 m_labelFile =
new QFile(cubFile.expanded());
436 m_label->addObject(lbl);
439 Preference::Preferences().findGroup(
"CubeCustomization");
440 bool overwrite = pref[
"Overwrite"][0].toUpper() ==
"ALLOW";
441 if (!overwrite && m_labelFile->exists() && m_labelFile->size()) {
442 QString msg =
"Cube file [" + m_labelFileName->original() +
"] exists, " +
443 "user preference does not allow overwrite";
447 if (!m_labelFile->open(QIODevice::Truncate | QIODevice::ReadWrite)) {
448 QString msg =
"Failed to create [" + m_labelFile->fileName() +
"]";
454 if (m_storesDnData && !m_dataFile->open(QIODevice::Truncate | QIODevice::ReadWrite)) {
455 QString msg =
"Failed to create [" + m_dataFile->fileName() +
"]";
459 else if (!m_storesDnData && !m_dataFile->open(QIODevice::ReadOnly)) {
460 QString msg =
"Failed to open [" + m_dataFile->fileName() +
"] for reading";
466 bool dataAlreadyOnDisk = m_storesDnData ?
false :
true;
468 if (m_format == Bsq) {
469 m_ioHandler =
new CubeBsqHandler(dataFile(), m_virtualBandList, realDataFileLabel(),
473 m_ioHandler =
new CubeTileHandler(dataFile(), m_virtualBandList, realDataFileLabel(),
478 m_ioHandler->updateLabels(*m_label);
496 create(cubeFileName);
508 void Cube::open(
const QString &cubeFileName, QString access) {
512 string msg =
"You already have a cube opened";
516 initLabelFromFile(cubeFileName, (access ==
"rw"));
524 if (!temp.originalPath().startsWith(
"/")) {
525 m_dataFileName =
new FileName(m_labelFileName->path() +
"/" + temp.original());
528 m_dataFileName =
new FileName(temp);
532 m_storesDnData =
true;
534 m_dataFile =
new QFile(realDataFileName().expanded());
537 FileName dataFileName(core[
"^DnFile"][0]);
539 if (dataFileName.originalPath() ==
".") {
540 m_dataFileName =
new FileName(m_labelFileName->path() +
"/" + dataFileName.name());
543 m_dataFileName =
new FileName(dataFileName);
547 m_storesDnData =
false;
549 m_dataFile =
new QFile(realDataFileName().expanded());
552 m_dataFileName =
new FileName(*m_labelFileName);
554 m_storesDnData =
true;
563 if (!m_labelFile->open(QIODevice::ReadOnly)) {
564 QString msg =
"Failed to open [" + m_labelFile->fileName() +
"] with "
571 if (!m_dataFile->open(QIODevice::ReadOnly)) {
572 QString msg =
"Failed to open [" + m_dataFile->fileName() +
"] with "
579 else if (access ==
"rw") {
580 if (!m_labelFile->open(QIODevice::ReadWrite)) {
581 QString msg =
"Failed to open [" + m_labelFile->fileName() +
"] with "
588 if (m_storesDnData && !m_dataFile->open(QIODevice::ReadWrite)) {
589 QString msg =
"Failed to open [" + m_dataFile->fileName() +
"] with "
594 else if (!m_storesDnData && !m_dataFile->open(QIODevice::ReadOnly)) {
595 QString msg =
"Failed to open [" + m_dataFile->fileName() +
"] with "
603 QString msg =
"Unknown value for access [" + access +
"]. Expected 'r' "
609 initCoreFromLabel(*m_label);
613 m_labelBytes = m_label->findObject(
"Label")[
"Bytes"];
616 m_labelBytes = labelSize(
true);
620 if (!m_storesDnData) {
621 dataLabel = qMakePair(
true,
new Pvl(m_dataFileName->expanded()));
625 if (m_format == Bsq) {
627 realDataFileLabel(),
true);
631 realDataFileLabel(),
true);
634 if (dataLabel.first) {
635 delete dataLabel.second;
636 dataLabel.second = NULL;
639 applyVirtualBandsToLabel();
651 void Cube::reopen(QString access) {
653 QString msg =
"Cube has not been opened yet. The filename to re-open is "
659 FileName filename = *m_labelFileName;
662 if (m_virtualBandList)
663 virtualBandList = *m_virtualBandList;
666 open(filename.expanded(), access);
668 if (virtualBandList.size()) {
669 if (m_virtualBandList)
670 *m_virtualBandList = virtualBandList;
672 m_virtualBandList =
new QList<int>(virtualBandList);
684 void Cube::read(
Blob &blob)
const {
686 string msg =
"The cube is not opened so you can't read a blob from it";
690 FileName cubeFile = *m_labelFileName;
692 cubeFile = *m_tempCube;
694 QMutexLocker locker(m_mutex);
695 QMutexLocker locker2(m_ioHandler->dataFileMutex());
696 blob.
Read(cubeFile.toString(), *label());
706 void Cube::read(
Buffer &bufferToFill)
const {
708 string msg =
"Try opening a file before you read it";
712 QMutexLocker locker(m_mutex);
713 m_ioHandler->read(bufferToFill);
725 string msg =
"The cube is not opened so you can't write a blob to it";
729 if (!m_labelFile->isWritable()) {
730 string msg =
"The cube must be opened in read/write mode, not readOnly";
736 QMutexLocker locker(m_mutex);
737 QMutexLocker locker2(m_ioHandler->dataFileMutex());
741 fstream stream(m_labelFileName->expanded().toAscii().data(),
742 ios::in | ios::out | ios::binary);
743 stream.seekp(0, ios::end);
746 streampos endByte = stream.tellp();
748 streampos maxbyte = (streampos) m_labelBytes;
750 if (m_storesDnData) {
751 maxbyte += (streampos) m_ioHandler->getDataSize();
755 if (endByte < maxbyte) {
756 stream.seekp(maxbyte, ios::beg);
759 blob.
Write(*m_label, stream);
765 blobFileName = blobFileName.removeExtension();
766 blobFileName = blobFileName.addExtension(blob.
Type());
767 blobFileName = blobFileName.addExtension(blob.
Name());
768 QString blobFile(blobFileName.expanded());
769 ios::openmode flags = ios::in | ios::binary | ios::out | ios::trunc;
770 fstream detachedStream;
771 detachedStream.open(blobFile.toAscii().data(), flags);
772 if (!detachedStream) {
773 QString message =
"Unable to open data file [" +
774 blobFileName.expanded() +
"]";
782 blob.
Write(*m_label, detachedStream, blobFileName.name());
793 void Cube::write(
Buffer &bufferToWrite) {
795 string msg =
"Tried to write to a cube before opening/creating it";
800 QString msg =
"Cannot write to the cube [" + (QString)QFileInfo(fileName()).fileName() +
801 "] because it is opened read-only";
805 if (!m_storesDnData) {
806 QString msg =
"The cube [" + QFileInfo(fileName()).fileName() +
807 "] does not support storing DN data because it is using an external file for DNs";
811 QMutexLocker locker(m_mutex);
812 m_ioHandler->write(bufferToWrite);
826 void Cube::setBaseMultiplier(
double base,
double mult) {
843 void Cube::setMinMax(
double min,
double max) {
850 if (m_pixelType == UnsignedByte) {
853 m_multiplier = (max - min) / (x2 - x1);
854 m_base = min - m_multiplier * x1;
856 else if (m_pixelType == SignedWord) {
859 m_multiplier = (max - min) / (x2 - x1);
860 m_base = min - m_multiplier * x1;
873 m_byteOrder = byteOrder;
886 void Cube::setDimensions(
int ns,
int nl,
int nb) {
888 if ((ns < 1) || (nl < 1) || (nb < 1)) {
889 string msg =
"SetDimensions: Invalid number of sample, lines or bands";
898 void Cube::setExternalDnData(
FileName cubeFileWithDnData) {
900 initLabelFromFile(cubeFileWithDnData,
false);
901 initCoreFromLabel(*m_label);
906 catch (IException &) {
912 m_storesDnData =
false;
913 m_dataFileName =
new FileName(cubeFileWithDnData);
918 delete m_labelFileName;
919 m_labelFileName = NULL;
942 void Cube::setLabelsAttached(
bool attach) {
955 void Cube::setLabelSize(
int labelBytes) {
957 m_labelBytes = labelBytes;
970 m_pixelType = pixelType;
987 if (m_virtualBandList)
988 m_virtualBandList->clear();
992 if (vbands.size() > 0) {
993 QListIterator<QString> it(vbands);
994 while (it.hasNext()) {
995 m_virtualBandList->append(
toInt(it.next()));
999 delete m_virtualBandList;
1000 m_virtualBandList = NULL;
1004 m_ioHandler->setVirtualBands(m_virtualBandList);
1015 void Cube::setVirtualBands(
const std::vector<QString> &vbands) {
1018 for(
unsigned int i = 0; i < vbands.size(); i++)
1019 realVBands << vbands[i];
1021 setVirtualBands(realVBands);
1025 void Cube::relocateDnData(
FileName dnDataFile) {
1028 QString(
"Cannot relocate the DN data to [%1] for an external cube label "
1029 "file which is not open.")
1030 .arg(dnDataFile.original()),
1035 if (m_storesDnData) {
1036 throw IException(IException::Unknown,
1037 QString(
"The cube [%1] stores DN data. It cannot be relocated to [%2] - "
1038 "this is only supported for external cube label files.")
1039 .arg(m_labelFileName->original()).arg(dnDataFile.original()),
1043 m_label->findObject(
"IsisCube").findObject(
"Core").findKeyword(
"^DnFile")[0] =
1044 dnDataFile.original();
1045 reopen(m_labelFile->isWritable()?
"rw" :
"r");
1069 int Cube::bandCount()
const {
1070 int numBands = m_bands;
1071 if (m_virtualBandList)
1072 numBands = m_virtualBandList->size();
1086 double Cube::base()
const {
1111 if (m_camera == NULL && isOpen()) {
1112 m_camera = CameraFactory::Create(*
this);
1127 "An external cube label file must be opened in order to use "
1128 "Cube::getExternalCubeFileName",
1132 if (storesDnData()) {
1134 "Cube::getExternalCubeFileName can only be called on an external cube label "
1142 return core[
"^DnFile"][0];
1152 QString Cube::fileName()
const {
1154 return m_labelFileName->expanded();
1218 Histogram *Cube::histogram(
const int &band,
const double &validMin,
1219 const double &validMax, QString msg) {
1222 QString msg =
"Cannot create histogram object for an unopened cube";
1227 if ((band < 0) || (band > bandCount())) {
1228 QString msg =
"Invalid band in [CubeInfo::Histogram]";
1232 int bandStart = band;
1233 int bandStop = band;
1234 int maxSteps = lineCount();
1237 bandStop = bandCount();
1238 maxSteps = lineCount() * bandCount();
1246 hist->SetValidRange(validMin, validMax);
1250 double binMin = validMin;
1251 double binMax = validMax;
1253 binMin = hist->BinRangeStart();
1257 binMax = hist->BinRangeEnd();
1260 hist->SetBinRange(binMin, binMax);
1267 for(
int useBand = bandStart ; useBand <= bandStop ; useBand++) {
1268 for(
int i = 1; i <= lineCount(); i++) {
1301 int Cube::labelSize(
bool actual)
const {
1302 int labelSize = m_labelBytes;
1304 if (actual && m_label) {
1306 s << *m_label << endl;
1307 labelSize = s.tellp();
1322 int Cube::lineCount()
const {
1336 double Cube::multiplier()
const {
1337 return m_multiplier;
1361 int Cube::physicalBand(
const int &virtualBand)
const {
1362 int physicalBand = virtualBand;
1364 if (m_virtualBandList) {
1365 if ((virtualBand < 1) ||
1366 (virtualBand > m_virtualBandList->size())) {
1367 QString msg =
"Out of array bounds [" +
toString(virtualBand) +
"]";
1370 physicalBand = m_virtualBandList->at(virtualBand - 1);
1373 return physicalBand;
1383 if (m_projection == NULL && isOpen()) {
1384 m_projection = ProjectionFactory::CreateFromCube(*label());
1386 return m_projection;
1395 int Cube::sampleCount()
const {
1439 Statistics *Cube::statistics(
const int &band,
const double &validMin,
1440 const double &validMax, QString msg) {
1443 QString msg =
"Cannot create statistics object for an unopened cube";
1448 if ((band < 0) || (band > bandCount())) {
1449 string msg =
"Invalid band in [CubeInfo::Statistics]";
1457 stats->SetValidRange(validMin, validMax);
1459 int bandStart = band;
1460 int bandStop = band;
1461 int maxSteps = lineCount();
1464 bandStop = bandCount();
1465 maxSteps = lineCount() * bandCount();
1474 for(
int useBand = bandStart ; useBand <= bandStop ; useBand++) {
1475 for(
int i = 1; i <= lineCount(); i++) {
1487 bool Cube::storesDnData()
const {
1488 return m_storesDnData;
1507 if (isOpen() && m_ioHandler) {
1508 m_ioHandler->addCachingAlgorithm(algorithm);
1510 else if (!isOpen()) {
1511 QString msg =
"Cannot add a caching algorithm until the cube is open";
1521 void Cube::clearIoCache() {
1523 QMutexLocker locker(m_mutex);
1524 m_ioHandler->clearCache();
1538 bool Cube::deleteBlob(QString BlobType, QString BlobName) {
1539 for(
int i = 0; i < m_label->objects(); i++) {
1541 if (obj.
name().compare(BlobType) == 0) {
1560 void Cube::deleteGroup(
const QString &group) {
1562 if (!isiscube.
hasGroup(group))
return;
1587 bool Cube::hasGroup(
const QString &group)
const {
1589 if (isiscube.
hasGroup(group))
return true;
1601 bool Cube::hasTable(
const QString &name) {
1602 for(
int o = 0; o < label()->objects(); o++) {
1606 QString temp = (QString) obj[
"Name"];
1607 temp = temp.toUpper();
1608 QString temp2 = name;
1609 temp2 = temp2.toUpper();
1610 if (temp == temp2)
return true;
1637 void Cube::applyVirtualBandsToLabel() {
1641 if (m_label->findObject(
"IsisCube").hasGroup(
"BandBin")) {
1642 PvlGroup &bandBin = m_label->findObject(
"IsisCube").findGroup(
"BandBin");
1643 for (
int k = 0;k < bandBin.
keywords();k++) {
1644 if (bandBin[k].size() == m_bands && m_virtualBandList) {
1647 for (
int i = 0;i < m_virtualBandList->size();i++) {
1648 int physicalBand = m_virtualBandList->at(i) - 1;
1649 bandBin[k].addValue(temp[physicalBand], temp.
unit(physicalBand));
1656 if (m_virtualBandList && core.
hasGroup(
"Dimensions")) core.
findGroup(
"Dimensions")[
"Bands"] =
toString(m_virtualBandList->size());
1665 void Cube::cleanUp(
bool removeIt) {
1673 QFile::remove(m_tempCube->expanded());
1681 QFile::remove(m_labelFileName->expanded());
1683 if (*m_labelFileName != *m_dataFileName)
1684 QFile::remove(m_dataFileName->expanded());
1693 delete m_labelFileName;
1694 m_labelFileName = NULL;
1696 delete m_dataFileName;
1697 m_dataFileName = NULL;
1702 delete m_virtualBandList;
1703 m_virtualBandList = NULL;
1713 void Cube::construct() {
1720 m_projection = NULL;
1722 m_labelFileName = NULL;
1723 m_dataFileName = NULL;
1725 m_formatTemplateFile = NULL;
1728 m_virtualBandList = NULL;
1730 m_mutex =
new QMutex();
1731 m_formatTemplateFile =
1732 new FileName(
"$base/templates/labels/CubeFormatTemplate.pft");
1744 QFile *Cube::dataFile()
const {
1761 if (m_attached && m_storesDnData) {
1762 ASSERT(m_labelFileName);
1763 result = *m_labelFileName;
1766 else if (!m_attached && m_storesDnData) {
1767 ASSERT(m_dataFileName);
1768 result = *m_dataFileName;
1771 else if (!m_storesDnData) {
1772 ASSERT(m_dataFileName);
1776 Pvl guessLabel(guess.expanded());
1780 if (core.hasKeyword(
"^DnFile")) {
1782 guess = core[
"^DnFile"][0];
1784 if (!guess.
path().startsWith(
"/")) {
1785 guess = currentGuess.
path() +
"/" + guess.original();
1788 else if (core.hasKeyword(
"^Core")) {
1789 result = core[
"^Core"][0];
1795 while (result.name() ==
"");
1813 void Cube::initialize() {
1821 m_storesDnData =
true;
1822 m_labelBytes = 65536;
1833 void Cube::initCoreFromLabel(
const Pvl &label) {
1839 m_samples = dims[
"Samples"];
1840 m_lines = dims[
"Lines"];
1841 m_bands = dims[
"Bands"];
1845 m_byteOrder = ByteOrderEnumeration(pixelsGroup[
"ByteOrder"]);
1846 m_base = pixelsGroup[
"Base"];
1847 m_multiplier = pixelsGroup[
"Multiplier"];
1851 if ((QString) core[
"Format"] ==
"BandSequential") {
1859 FileName temp(core[
"^DnFile"][0]);
1860 if (!temp.expanded().startsWith(
"/")) {
1861 temp = FileName(m_labelFileName->path() +
"/" + temp.original());
1864 initCoreFromLabel(Pvl(temp.toString()));
1869 void Cube::initLabelFromFile(FileName labelFileName,
bool readWrite) {
1870 ASSERT(!m_labelFileName);
1873 if (labelFileName.fileExists()) {
1874 m_label =
new Pvl(labelFileName.expanded());
1875 if (!m_label->objects()) {
1880 catch(IException &) {
1889 FileName tmp(labelFileName);
1890 tmp = tmp.addExtension(
"cub");
1891 if (tmp.fileExists()) {
1892 m_label =
new Pvl(tmp.expanded());
1893 if (!m_label->objects()) {
1896 labelFileName = tmp;
1900 catch(IException &e) {
1909 FileName tmp(labelFileName);
1910 tmp = tmp.setExtension(
"lbl");
1911 if (tmp.fileExists()) {
1912 m_label =
new Pvl(tmp.expanded());
1913 if (!m_label->objects()) {
1916 labelFileName = tmp;
1920 catch(IException &e) {
1929 FileName tmp(labelFileName);
1930 tmp = tmp.addExtension(
"ecub");
1931 if (tmp.fileExists()) {
1932 m_label =
new Pvl(tmp.expanded());
1933 if (!m_label->objects()) {
1936 labelFileName = tmp;
1940 catch(IException &e) {
1949 throw IException(IException::Io, msg,
_FILEINFO_);
1952 m_labelFileName =
new FileName(labelFileName);
1956 if (m_label->hasKeyword(
"CCSD3ZF0000100000001NJPL3IF0PDS200000001")) {
1958 reformatOldIsisLabel(m_labelFileName->expanded());
1962 QString msg =
"Can not open old cube file format with write access [" +
1963 m_labelFileName->original() +
"]";
1964 throw IException(IException::Io, msg,
_FILEINFO_);
1968 m_labelFile =
new QFile(m_labelFileName->expanded());
1976 void Cube::openCheck() {
1978 string msg =
"Sorry you can't do a SetMethod after the cube is opened";
1983 Pvl Cube::realDataFileLabel()
const {
1984 Pvl label = *m_label;
1988 core = &label.
findObject(
"IsisCube").findObject(
"Core");
1992 FileName temp((*core)[
"^DnFile"][0]);
1993 if (!temp.expanded().startsWith(
"/")) {
1997 label = Pvl(temp.toString());
2013 void Cube::reformatOldIsisLabel(
const QString &oldCube) {
2014 QString parameters =
"from=" + oldCube;
2016 FileName tempCube = FileName::createTempFile(
"Temporary_" + oldName.name() +
".cub");
2017 parameters +=
" to=" + tempCube.expanded();
2020 QString command =
"$ISISROOT/bin/pds2isis " + parameters;
2021 ProgramLauncher::RunSystemCommand(command);
2024 QString prog =
"pds2isis";
2025 ProgramLauncher::RunIsisProgram(prog, parameters);
2028 m_tempCube =
new FileName(tempCube);
2029 *m_label =
Pvl(m_tempCube->toString());
2030 m_labelFile =
new QFile(m_tempCube->expanded());
2038 void Cube::writeLabels() {
2040 string msg =
"Cube must be opened first before writing labels";
2045 m_label->setFormatTemplate(m_formatTemplateFile->original());
2049 QMutexLocker locker(m_mutex);
2050 QMutexLocker locker2(m_ioHandler->dataFileMutex());
2053 temp << *m_label << endl;
2054 string tempstr = temp.str();
2055 if ((
int) tempstr.length() < m_labelBytes) {
2056 QByteArray labelArea(m_labelBytes,
'\0');
2057 QByteArray labelUnpaddedContents(tempstr.c_str(), tempstr.length());
2058 labelArea.replace(0, labelUnpaddedContents.size(), labelUnpaddedContents);
2060 m_labelFile->seek(0);
2061 m_labelFile->write(labelArea);
2065 QString msg =
"Label space is full in [" +
2066 (QString)
FileName(*m_labelFileName).name() +
2067 "] unable to write labels";
2075 m_label->write(m_labelFileName->expanded());