Commit e933c14efac817f4542b6e10cfd18868a1ffb3c1

Authored by David Mayerich
1 parent 6708cc25

cleaned up the code

Showing 4 changed files with 23 additions and 24 deletions   Show diff stats
@@ -54,7 +54,7 @@ public: @@ -54,7 +54,7 @@ public:
54 return true; 54 return true;
55 } 55 }
56 56
57 - bool getBand( T * p, double wavelength){ 57 + bool band( T * p, double wavelength){
58 58
59 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band 59 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band
60 unsigned int S = XY * sizeof(T); //calculate the number of bytes of a band 60 unsigned int S = XY * sizeof(T); //calculate the number of bytes of a band
@@ -147,7 +147,7 @@ public: @@ -147,7 +147,7 @@ public:
147 } 147 }
148 148
149 //save one pixel of the BIP file into the memory, and return the pointer 149 //save one pixel of the BIP file into the memory, and return the pointer
150 - bool getSpectrum(T * p, unsigned x, unsigned y){ 150 + bool spectrum(T * p, unsigned x, unsigned y){
151 151
152 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right 152 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right
153 std::cout<<"ERROR: sample or line out of range"<<std::endl; 153 std::cout<<"ERROR: sample or line out of range"<<std::endl;
@@ -292,7 +292,7 @@ public: @@ -292,7 +292,7 @@ public:
292 } 292 }
293 293
294 // normalize the BIL file 294 // normalize the BIL file
295 - bool normalize(std::string outname, double band) 295 + bool normalize(std::string outname, double w)
296 { 296 {
297 unsigned int B = R[2]; //calculate the number of bands 297 unsigned int B = R[2]; //calculate the number of bands
298 unsigned int Y = R[1]; 298 unsigned int Y = R[1];
@@ -311,7 +311,7 @@ public: @@ -311,7 +311,7 @@ public:
311 b = (T*)malloc( S ); //memory allocation 311 b = (T*)malloc( S ); //memory allocation
312 c = (T*)malloc( L ); 312 c = (T*)malloc( L );
313 313
314 - getBand(b, band); //get the certain band into memory 314 + band(b, w); //get the certain band into memory
315 315
316 for(unsigned j = 0; j < Y; j++) 316 for(unsigned j = 0; j < Y; j++)
317 { 317 {
@@ -58,7 +58,7 @@ public: @@ -58,7 +58,7 @@ public:
58 return true; 58 return true;
59 } 59 }
60 60
61 - bool getBand( T * p, double wavelength){ 61 + bool band( T * p, double wavelength){
62 62
63 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band 63 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band
64 64
@@ -242,7 +242,7 @@ public: @@ -242,7 +242,7 @@ public:
242 } 242 }
243 243
244 //save one pixel of the BIP file into the memory, and return the pointer 244 //save one pixel of the BIP file into the memory, and return the pointer
245 - bool getSpectrum(T * p, unsigned x, unsigned y){ 245 + bool spectrum(T * p, unsigned x, unsigned y){
246 246
247 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right 247 if ( x >= R[0] || y >= R[1]){ //make sure the sample and line number is right
248 std::cout<<"ERROR: sample or line out of range"<<std::endl; 248 std::cout<<"ERROR: sample or line out of range"<<std::endl;
@@ -381,7 +381,7 @@ public: @@ -381,7 +381,7 @@ public:
381 } 381 }
382 382
383 // normalize the BIP file 383 // normalize the BIP file
384 - bool normalize(std::string outname, double band) 384 + bool normalize(std::string outname, double w)
385 { 385 {
386 unsigned int B = R[2]; //calculate the number of bands 386 unsigned int B = R[2]; //calculate the number of bands
387 unsigned int Y = R[1]; 387 unsigned int Y = R[1];
@@ -400,7 +400,7 @@ public: @@ -400,7 +400,7 @@ public:
400 b = (T*)malloc( S ); //memory allocation 400 b = (T*)malloc( S ); //memory allocation
401 c = (T*)malloc( L ); 401 c = (T*)malloc( L );
402 402
403 - getBand(b, band); //get the certain band into memory 403 + band(b, w); //get the certain band into memory
404 404
405 for(unsigned j = 0; j < Y; j++) 405 for(unsigned j = 0; j < Y; j++)
406 { 406 {
@@ -433,7 +433,7 @@ public: @@ -433,7 +433,7 @@ public:
433 bil(temp); 433 bil(temp);
434 434
435 rts::bil<T> n; 435 rts::bil<T> n;
436 - if(n.bil::open(temp, R[0], R[1], R[2], offset, w)==false){ //open infile 436 + if(n.open(temp, R[0], R[1], R[2], offset, w)==false){ //open infile
437 std::cout<<"ERROR: unable to open input file"<<std::endl; 437 std::cout<<"ERROR: unable to open input file"<<std::endl;
438 exit(1); 438 exit(1);
439 } 439 }
@@ -28,14 +28,9 @@ public: @@ -28,14 +28,9 @@ public:
28 using binary<T>::getSlice; 28 using binary<T>::getSlice;
29 using binary<T>::R; 29 using binary<T>::R;
30 30
31 - //open a file, given the file and its header's names 31 + //open a file, given the file name and dimensions
32 bool open(std::string filename, unsigned int X, unsigned int Y, unsigned int B, unsigned int header_offset, std::vector<double> wavelengths){ 32 bool open(std::string filename, unsigned int X, unsigned int Y, unsigned int B, unsigned int header_offset, std::vector<double> wavelengths){
33 33
34 - /*if (header.load(headername)==false){  
35 - std::cout<<"ERROR: unable to load header file: "<<headername<<std::endl;  
36 - return false;  
37 - }*/  
38 -  
39 //copy the wavelengths to the BSQ file structure 34 //copy the wavelengths to the BSQ file structure
40 w = wavelengths; 35 w = wavelengths;
41 //copy the wavelengths to the structure 36 //copy the wavelengths to the structure
@@ -47,7 +42,7 @@ public: @@ -47,7 +42,7 @@ public:
47 42
48 } 43 }
49 44
50 - //save one band of the file into the memory, and return the pointer 45 + //retrieve one band (specified by the band index)
51 bool band_index( T * p, unsigned int page){ 46 bool band_index( T * p, unsigned int page){
52 47
53 if (page >= R[2]){ //make sure the bank number is right 48 if (page >= R[2]){ //make sure the bank number is right
@@ -59,7 +54,8 @@ public: @@ -59,7 +54,8 @@ public:
59 return true; 54 return true;
60 } 55 }
61 56
62 - bool getBand( T * p, double wavelength){ 57 + //retrieve one band (specified by the wavelength)
  58 + bool band( T * p, double wavelength){
63 59
64 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band 60 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band
65 61
@@ -104,7 +100,7 @@ public: @@ -104,7 +100,7 @@ public:
104 } 100 }
105 101
106 //save one pixel of the file into the memory, and return the pointer 102 //save one pixel of the file into the memory, and return the pointer
107 - bool getSpectrum(T * p, unsigned x, unsigned y){ 103 + bool spectrum(T * p, unsigned x, unsigned y){
108 104
109 unsigned int i; 105 unsigned int i;
110 106
@@ -168,11 +164,11 @@ public: @@ -168,11 +164,11 @@ public:
168 //else get the low band 164 //else get the low band
169 else{ 165 else{
170 control += 1; 166 control += 1;
171 - getBand(a, ai); 167 + band(a, ai);
172 bi = wls[control]; 168 bi = wls[control];
173 } 169 }
174 //get the high band 170 //get the high band
175 - getBand(b, bi); 171 + band(b, bi);
176 172
177 //correct every band 173 //correct every band
178 for(unsigned cii = 0; cii < B; cii++){ 174 for(unsigned cii = 0; cii < B; cii++){
@@ -188,7 +184,7 @@ public: @@ -188,7 +184,7 @@ public:
188 184
189 ai = bi; 185 ai = bi;
190 bi = wls[control]; 186 bi = wls[control];
191 - getBand(b, bi); 187 + band(b, bi);
192 188
193 } 189 }
194 //if the last BL point on the last band of the file? 190 //if the last BL point on the last band of the file?
@@ -227,7 +223,7 @@ public: @@ -227,7 +223,7 @@ public:
227 } 223 }
228 224
229 // normalize the BSQ file 225 // normalize the BSQ file
230 - bool normalize(std::string outname, double band) 226 + bool normalize(std::string outname, double w)
231 { 227 {
232 unsigned int B = R[2]; //calculate the number of bands 228 unsigned int B = R[2]; //calculate the number of bands
233 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band 229 unsigned int XY = R[0] * R[1]; //calculate the number of pixels in a band
@@ -242,7 +238,7 @@ public: @@ -242,7 +238,7 @@ public:
242 b = (T*)malloc( S ); //memory allocation 238 b = (T*)malloc( S ); //memory allocation
243 c = (T*)malloc( S ); 239 c = (T*)malloc( S );
244 240
245 - getBand(b, band); //get the certain band into memory 241 + band(b, w); //get the certain band into memory
246 242
247 for(unsigned j = 0; j < B; j++) 243 for(unsigned j = 0; j < B; j++)
248 { 244 {
@@ -271,7 +267,7 @@ public: @@ -271,7 +267,7 @@ public:
271 bil(temp); 267 bil(temp);
272 268
273 rts::bil<T> n; 269 rts::bil<T> n;
274 - if(n.bil::open(temp, R[0], R[1], R[2], offset, w)==false){ //open infile 270 + if(n.open(temp, R[0], R[1], R[2], offset, w)==false){ //open infile
275 std::cout<<"ERROR: unable to open input file"<<std::endl; 271 std::cout<<"ERROR: unable to open input file"<<std::endl;
276 exit(1); 272 exit(1);
277 } 273 }
@@ -127,6 +127,7 @@ public: @@ -127,6 +127,7 @@ public:
127 std::cout<<"ERROR: unidentified file type"<<std::endl; 127 std::cout<<"ERROR: unidentified file type"<<std::endl;
128 exit(1); 128 exit(1);
129 } 129 }
  130 + return false;
130 } 131 }
131 132
132 //perform baseline correction 133 //perform baseline correction
@@ -268,6 +269,7 @@ public: @@ -268,6 +269,7 @@ public:
268 std::cout<<"ERROR: unidentified interleave type"<<std::endl; 269 std::cout<<"ERROR: unidentified interleave type"<<std::endl;
269 exit(1); 270 exit(1);
270 } 271 }
  272 + return false;
271 273
272 } 274 }
273 275
@@ -304,6 +306,7 @@ public: @@ -304,6 +306,7 @@ public:
304 exit(1); 306 exit(1);
305 } 307 }
306 } 308 }
  309 + return false;
307 } 310 }
308 311
309 bool save_header(std::string filename){ 312 bool save_header(std::string filename){