48 void ProcessImportVicar::SetVicarFile(
const QString &vicarFile,
Pvl &vicarLab) {
50 ifstream vicFile(vicarFile.toAscii().data(), ios::in);
53 QString msg =
"Cannot open vicar file [" + vicarFile +
"]";
59 IString vicLabels = ExtractPvlLabel(0, vicFile);
63 lbl << vicLabels <<
" End" << endl;
69 SetFileHeaderBytes(vLab[
"LBLSIZE"]);
72 SetDataHeaderBytes((
int) vLab[
"NLB"] * (
int)vLab[
"RECSIZE"]);
75 SetDataPrefixBytes(vLab[
"NBB"]);
76 SetDataSuffixBytes(0);
78 SetDimensions(vLab[
"NS"], vLab[
"NL"], vLab[
"NB"]);
80 QString pixType = vLab[
"FORMAT"];
82 if(pixType ==
"BYTE") pixelType = UnsignedByte;
83 if(pixType ==
"HALF") pixelType = SignedWord;
84 if(pixType ==
"REAL") pixelType = Real;
85 if(pixelType == None) {
86 QString msg =
"Unsupported pixel type [FORMAT=" + pixType +
"]";
89 SetPixelType(pixelType);
91 QString order = vLab[
"INTFMT"];
99 QString organization = vLab[
"ORG"];
100 if(organization ==
"BSQ") {
101 SetOrganization(ProcessImport::BSQ);
103 else if(organization ==
"BIL") {
104 SetOrganization(ProcessImport::BIL);
106 else if(organization ==
"BIP") {
107 SetOrganization(ProcessImport::BIP);
110 QString msg =
"Unsupported file organization [" + organization +
"]";
116 if(vLab.hasKeyword(
"EOL")) {
117 if((
int) vLab[
"EOL"] == 1) {
118 int startByte = (int) vLab[
"LBLSIZE"] +
119 (
int) vLab[
"NLB"] * (int) vLab[
"RECSIZE"] +
120 (
int) vLab[
"NL"] * (int) vLab[
"NB"] *
121 (
int) vLab[
"RECSIZE"];
122 ifstream vicFile(vicarFile.toAscii().data(), ios::in);
124 QString endPvlLabel = ExtractPvlLabel(startByte, vicFile);
132 for(
int k = 0; k < endLab.keywords(); k++) {
133 vicarLab += endLab[k];
139 QString msg =
"Input file [" + vicarFile +
"] does not appear to be a vicar file";
143 SetInputFile(vicarFile);
154 QString ProcessImportVicar::ExtractPvlLabel(
int startPos, std::ifstream &vicarFile)
const {
155 vicarFile.seekg(startPos, ios::beg);
158 char *lblSizeValue =
new char [1024];
159 vicarFile.seekg(QString(
"LBLSIZE=").size(), ios_base::cur);
161 for(
int pos = 0; pos < 1024 - 1; pos++) {
162 if(!vicarFile.good())
165 if(vicarFile.peek() ==
' ')
168 lblSizeValue[pos] = vicarFile.get();
169 lblSizeValue[pos + 1] =
'\0';
173 QString msg =
"Cannot find label size in VICAR file";
179 delete [] lblSizeValue;
182 char *buf =
new char[lblSize+1];
185 vicarFile.seekg(startPos, ios::beg);
186 vicarFile.read(buf, lblSize);
191 QString vicLabels = buf;
193 bool inQuote =
false;
194 for(
int pos = 0; pos < vicLabels.size(); pos++) {
195 if(vicLabels[pos] ==
'\'' || vicLabels[pos] ==
'"') {
199 if(!inQuote && vicLabels[pos] ==
' ') {
200 vicLabels[pos] =
'\n';