7 #include "ProcessImportVicar.h"
13 #include "Preference.h"
14 #include "IException.h"
15 #include "LineManager.h"
17 #include "PixelType.h"
18 #include "SpecialPixel.h"
20 #include "UserInterface.h"
32 void ProcessImportVicar::SetVicarFile(
const QString &vicarFile,
Pvl &vicarLab) {
34 ifstream vicFile(vicarFile.toLatin1().data(), ios::in);
37 QString msg =
"Cannot open vicar file [" + vicarFile +
"]";
38 throw IException(IException::User, msg, _FILEINFO_);
43 IString vicLabels = ExtractPvlLabel(0, vicFile);
47 lbl << vicLabels <<
" End" << endl;
53 SetFileHeaderBytes(vLab[
"LBLSIZE"]);
56 SetDataHeaderBytes((
int) vLab[
"NLB"] * (
int)vLab[
"RECSIZE"]);
59 SetDataPrefixBytes(vLab[
"NBB"]);
60 SetDataSuffixBytes(0);
62 SetDimensions(vLab[
"NS"], vLab[
"NL"], vLab[
"NB"]);
64 QString pixType = vLab[
"FORMAT"];
66 if(pixType ==
"BYTE") pixelType = UnsignedByte;
67 if(pixType ==
"WORD") pixelType = UnsignedWord;
68 if(pixType ==
"HALF") pixelType = SignedWord;
69 if(pixType ==
"REAL") pixelType = Real;
70 if(pixelType == None) {
71 QString msg =
"Unsupported pixel type [FORMAT=" + pixType +
"]";
72 throw IException(IException::Io, msg, _FILEINFO_);
74 SetPixelType(pixelType);
76 QString order = vLab[
"INTFMT"];
84 QString organization = vLab[
"ORG"];
85 if(organization ==
"BSQ") {
86 SetOrganization(ProcessImport::BSQ);
88 else if(organization ==
"BIL") {
89 SetOrganization(ProcessImport::BIL);
91 else if(organization ==
"BIP") {
92 SetOrganization(ProcessImport::BIP);
95 QString msg =
"Unsupported file organization [" + organization +
"]";
96 throw IException(IException::Io, msg, _FILEINFO_);
101 if(vLab.hasKeyword(
"EOL")) {
102 if((
int) vLab[
"EOL"] == 1) {
103 int startByte = (int) vLab[
"LBLSIZE"] +
104 (
int) vLab[
"NLB"] * (int) vLab[
"RECSIZE"] +
105 (
int) vLab[
"NL"] * (int) vLab[
"NB"] *
106 (
int) vLab[
"RECSIZE"];
107 ifstream vicFile(vicarFile.toLatin1().data(), ios::in);
109 QString endPvlLabel = ExtractPvlLabel(startByte, vicFile);
117 for(
int k = 0; k < endLab.keywords(); k++) {
118 vicarLab += endLab[k];
124 QString msg =
"Input file [" + vicarFile +
"] does not appear to be a vicar file";
125 throw IException(IException::User, msg, _FILEINFO_);
128 SetInputFile(vicarFile);
139 QString ProcessImportVicar::ExtractPvlLabel(
int startPos, std::ifstream &vicarFile)
const {
140 vicarFile.seekg(startPos, ios::beg);
143 char *lblSizeValue =
new char [1024];
144 vicarFile.seekg(QString(
"LBLSIZE=").size(), ios_base::cur);
146 for(
int pos = 0; pos < 1024 - 1; pos++) {
147 if(!vicarFile.good())
150 if(vicarFile.peek() ==
' ')
153 lblSizeValue[pos] = vicarFile.get();
154 lblSizeValue[pos + 1] =
'\0';
158 QString msg =
"Cannot find label size in VICAR file";
159 throw IException(IException::User, msg, _FILEINFO_);
164 delete [] lblSizeValue;
167 char *buf =
new char[lblSize+1];
170 vicarFile.seekg(startPos, ios::beg);
171 vicarFile.read(buf, lblSize);
176 QString vicLabels = buf;
178 bool inQuote =
false;
179 for(
int pos = 0; pos < vicLabels.size(); pos++) {
180 if(vicLabels[pos] ==
'\'' || vicLabels[pos] ==
'"') {
184 if(!inQuote && vicLabels[pos] ==
' ') {
185 vicLabels[pos] =
'\n';