Blame view

stim/envi/envi_header.h 15.3 KB
e8eb202f   David Mayerich   added a new ENVI ...
1
2
3
  #ifndef ENVI_HEADER_H

  #define ENVI_HEADER_H

  

6e257ab3   dmayerich   ENVI and colormap...
4
  #include <string>

e8eb202f   David Mayerich   added a new ENVI ...
5
  #include <iostream>

6e257ab3   dmayerich   ENVI and colormap...
6
  #include <fstream>

e8eb202f   David Mayerich   added a new ENVI ...
7
8
  #include <sstream>

  #include <vector>

dc8eb8aa   David Mayerich   added band trimmi...
9
  #include <algorithm>

e8eb202f   David Mayerich   added a new ENVI ...
10
  #include <stdlib.h>

2eefb035   Pavel Govyadinov   added debugging c...
11
  #include <cmath>

e8eb202f   David Mayerich   added a new ENVI ...
12
  

6e257ab3   dmayerich   ENVI and colormap...
13
  //information from an ENVI header file

e8eb202f   David Mayerich   added a new ENVI ...
14
15
  //A good resource can be found here: http://www.exelisvis.com/docs/enviheaderfiles.html

  

8a86bd56   David Mayerich   changed rts names...
16
  namespace stim{

e8eb202f   David Mayerich   added a new ENVI ...
17
18
  

  struct envi_header

6e257ab3   dmayerich   ENVI and colormap...
19
  {

e8eb202f   David Mayerich   added a new ENVI ...
20
21
22
23
  	enum dataType {dummy0, int8, int16, int32, float32, float64, complex32, dummy7, dummy8, complex64, dummy10, dummy11, uint16, uint32, int64, uint64};

  	enum interleaveType {BIP, BIL, BSQ};	//bip = Z,X,Y; bil = X,Z,Y; bsq = X,Y,Z

  	enum endianType {endianLittle, endianBig};

  

6e257ab3   dmayerich   ENVI and colormap...
24
25
26
27
  	std::string name;

  

  	std::string description;

  

d0ef98e3   David Mayerich   fixed a Linux com...
28
29
30
31
  	size_t samples;	//x-axis

  	size_t lines;		//y-axis

  	size_t bands;		//spectral axis

  	size_t header_offset;		//header offset for binary file (in bytes)

e8eb202f   David Mayerich   added a new ENVI ...
32
33
34
  	std::string file_type;			//should be "ENVI Standard"

  

  	envi_header::dataType data_type;			//data representation; common value is 4 (32-bit float)

6e257ab3   dmayerich   ENVI and colormap...
35
36
  

  

e8eb202f   David Mayerich   added a new ENVI ...
37
  	envi_header::interleaveType interleave;

6e257ab3   dmayerich   ENVI and colormap...
38
39
40
  

  	std::string sensor_type;		//not really used

  

e8eb202f   David Mayerich   added a new ENVI ...
41
  	envi_header::endianType byte_order;			//little = least significant bit first (most systems)

6e257ab3   dmayerich   ENVI and colormap...
42
43
44
45
46
47
48
49
50
51
  

  	double x_start, y_start;		//coordinates of the upper-left corner of the image

  	std::string wavelength_units;	//stored wavelength units

  	std::string z_plot_titles[2];

  

  	double pixel_size[2];			//pixel size along X and Y

  

  	std::vector<std::string> band_names;	//name for each band in the image

  	std::vector<double> wavelength;		//wavelength for each band

  

e8eb202f   David Mayerich   added a new ENVI ...
52
53
  	void init(){

          name = "";

6e257ab3   dmayerich   ENVI and colormap...
54
55
56
57
58
59
  

  		//specify default values for a new or empty ENVI file

  		samples = 0;

  		lines = 0;

  		bands = 0;

  		header_offset = 0;

e8eb202f   David Mayerich   added a new ENVI ...
60
61
62
  		data_type = float32;

  		interleave = BSQ;

  		byte_order = endianLittle;

6e257ab3   dmayerich   ENVI and colormap...
63
64
65
66
67
68
69
70
71
72
  		x_start = y_start = 0;

  		pixel_size[0] = pixel_size[1] = 1;

  

  		//strings

  		file_type = "ENVI Standard";

  		sensor_type = "Unknown";

  		wavelength_units = "Unknown";

  		z_plot_titles[0] = z_plot_titles[1] = "Unknown";

  	}

  

e8eb202f   David Mayerich   added a new ENVI ...
73
74
75
76
77
78
79
80
  	envi_header(){

  		init();

  	}

  	envi_header(std::string name){

  		init();

  		load(name);

  	}

  

9d34229e   David Mayerich   restructured the ...
81
82
83
84
85
86
87
88
  	//sets the wavelength vector given a starting value and uniform step size
  	void set_wavelengths(double start, double step){
  		size_t B = bands;						//get the number of bands
  		wavelength.resize(B);
  		for(size_t b = 0; b < B; b++)
  			wavelength[b] = start + b * step;
  	}

  

e8eb202f   David Mayerich   added a new ENVI ...
89
  	std::string trim(std::string line){

3d0b6243   David Mayerich   fixed hsiproc bug...
90
91
92
  

  		if(line.length() == 0)

  			return line;

6e257ab3   dmayerich   ENVI and colormap...
93
  		//trims whitespace from the beginning and end of line

9d3ba0b1   David Mayerich   added stim::hsi a...
94
  		size_t start_i, end_i;

6e257ab3   dmayerich   ENVI and colormap...
95
96
97
98
99
100
101
  		for(start_i=0; start_i < line.length(); start_i++)

  			if(line[start_i] != 32)

  			{

  				break;

  			}

  

  		for(end_i = line.length()-1; end_i >= start_i; end_i--)

f6aa45e7   David Mayerich   fixed Windows EOL...
102
  			if(line[end_i] != ' ' && line[end_i] != '\r')

6e257ab3   dmayerich   ENVI and colormap...
103
104
105
106
107
108
109
110
  			{

  				break;

  			}

  

  		return line.substr(start_i, end_i - start_i+1);

  	}

  

  

e8eb202f   David Mayerich   added a new ENVI ...
111
  	std::string get_token(std::string line){

6e257ab3   dmayerich   ENVI and colormap...
112
113
114
115
116
117
118
119
120
121
  		//returns a variable name; in this case we look for the '=' sign

  		size_t i = line.find_first_of('=');

  

  		std::string result;

  		if(i != std::string::npos)

  			result = trim(line.substr(0, i-1));

  

  		return result;

  	}

  

e8eb202f   David Mayerich   added a new ENVI ...
122
  	std::string get_data_str(std::string line){

6e257ab3   dmayerich   ENVI and colormap...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  		size_t i = line.find_first_of('=');

  

  		std::string result;

  		if(i != std::string::npos)

  			result = trim(line.substr(i+1));

  		else

  		{

  			std::cout<<"ENVI Header error - data not found for token: "<<get_token(line)<<std::endl;

  			exit(1);

  		}

  		return result;

  	}

  

  	std::string get_brace_str(std::string token, std::string line, std::ifstream &file)

  	{

  		//this function assembles all of the characters between curly braces

  		//this is how strings are defined within an ENVI file

  

  		std::string result;

  

  		//first, find the starting brace

  		size_t i;

  		do

  		{

  			i = line.find_first_of('{');

  			if(i != std::string::npos)

  				break;

  		}while(file);

  

  		//if i is still npos, we have reached the end of the file without a brace...something is wrong

  		if(i == std::string::npos)

  		{

  			std::cout<<"ENVI Header error - string token declared without being defined: "<<token<<std::endl;

  			exit(1);

  		}

  		line = line.substr(i+1);

  

  		//copy character data into the result string until we find a closing brace

  		while(file)

  		{

  			i = line.find_first_of('}');

  

  

  			if(i != std::string::npos)

  			{

  				result += line.substr(0, i);

  				break;

  			}

  			else

  				result += line;

  

  			getline(file, line);

  		}

  

  		if(i == std::string::npos)

  		{

  			std::cout<<"ENVI Header error - string token declared without a terminating '}': "<<token<<std::endl;

  			exit(1);

  		}

  

  		return trim(result);

  	}

  

  	std::vector<std::string> get_string_seq(std::string token, std::string sequence)

  	{

  		//this function returns a sequence of comma-delimited strings

  		std::vector<std::string> result;

  

  		std::string entry;

  		size_t i;

  		do

  		{

  			i = sequence.find_first_of(',');

  			entry = sequence.substr(0, i);

  			sequence = sequence.substr(i+1);

  			result.push_back(trim(entry));

  		}while(i != std::string::npos);

  

  		return result;

  	}

  

  	std::vector<double> get_double_seq(std::string token, std::string sequence)

  	{

  		//this function returns a sequence of comma-delimited strings

e8eb202f   David Mayerich   added a new ENVI ...
207
  		std::vector<double> result;

6e257ab3   dmayerich   ENVI and colormap...
208
209
210
211
212
  		std::string entry;

  		size_t i;

  		do

  		{

  			i = sequence.find_first_of(',');

e8eb202f   David Mayerich   added a new ENVI ...
213
  			entry = sequence.substr(0, i);

6e257ab3   dmayerich   ENVI and colormap...
214
  			sequence = sequence.substr(i+1);

e8eb202f   David Mayerich   added a new ENVI ...
215
  			result.push_back(atof(entry.c_str()));

0174d823   dmayerich   bug fixes and exits
216
  			//std::cout<<entry<<"   ";

6e257ab3   dmayerich   ENVI and colormap...
217
218
219
220
221
222
223
224
225
226
227
  		}while(i != std::string::npos);

  

  		return result;

  	}

  

  	bool load(std::string filename)

  	{

  		//open the header file

  		std::ifstream file(filename.c_str());

  

  		if(!file)

e8eb202f   David Mayerich   added a new ENVI ...
228
  		{

6708cc25   heziqi   Ziqi added envi c...
229
  			std::cout<<"ERROR: unable to open header file:   "<<filename<<std::endl;

6e257ab3   dmayerich   ENVI and colormap...
230
231
232
233
234
235
236
237
238
239
              return false;

  		}

  

  		//the first line should just be "ENVI"

  		std::string line;

  		file>>line;

  		if(line != "ENVI")

  		{

  			std::cout<<"ENVI Header Error: The header doesn't appear to be an ENVI file. The first line should be 'ENVI'."<<std::endl;

  			exit(1);

e8eb202f   David Mayerich   added a new ENVI ...
240
  		}

6e257ab3   dmayerich   ENVI and colormap...
241
242
  

  		//for each line in the file, get the token

e8eb202f   David Mayerich   added a new ENVI ...
243
244
  		std::string token;

  

0174d823   dmayerich   bug fixes and exits
245
246
          //get a line

          getline(file, line);

6e257ab3   dmayerich   ENVI and colormap...
247
248
249
  		while(file)

  		{

  

0174d823   dmayerich   bug fixes and exits
250
  

6e257ab3   dmayerich   ENVI and colormap...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
  

  			//get the token

  			token = get_token(line);

  

  			if(token == "description")

  				description = get_brace_str(token, line, file);

  			else if(token == "band names")

  			{

  				std::string string_sequence = get_brace_str(token, line, file);

  				band_names = get_string_seq(token, string_sequence);

  			}

  			else if(token == "wavelength")

  			{

  				std::string string_sequence = get_brace_str(token, line, file);

  				wavelength = get_double_seq(token, string_sequence);

  			}

  			else if(token == "pixel size")

  			{

  				std::string string_sequence = get_brace_str(token, line, file);

  				std::vector<double> pxsize = get_double_seq(token, string_sequence);

  				pixel_size[0] = pxsize[0];

  				pixel_size[1] = pxsize[1];

  			}

  			else if(token == "z plot titles")

  			{

  				std::string string_sequence = get_brace_str(token, line, file);

  				std::vector<std::string> titles = get_string_seq(token, string_sequence);

  				z_plot_titles[0] = titles[0];

  				z_plot_titles[1] = titles[1];

  			}

  

  			else if(token == "samples")

  				samples = atoi(get_data_str(line).c_str());

  			else if(token == "lines")

  				lines = atoi(get_data_str(line).c_str());

  			else if(token == "bands")

  				bands = atoi(get_data_str(line).c_str());

  			else if(token == "header offset")

  				header_offset = atoi(get_data_str(line).c_str());

  			else if(token == "file type")

  				file_type = get_data_str(line);

  			else if(token == "data type")

e8eb202f   David Mayerich   added a new ENVI ...
293
  				data_type = (dataType)atoi(get_data_str(line).c_str());

6e257ab3   dmayerich   ENVI and colormap...
294
295
296
297
  			else if(token == "interleave")

  			{

  				std::string interleave_str = get_data_str(line);

  				if(interleave_str == "bip")

e8eb202f   David Mayerich   added a new ENVI ...
298
  					interleave = BIP;

6e257ab3   dmayerich   ENVI and colormap...
299
  				else if(interleave_str == "bil")

e8eb202f   David Mayerich   added a new ENVI ...
300
  					interleave = BIL;

6e257ab3   dmayerich   ENVI and colormap...
301
  				else if(interleave_str == "bsq")

e8eb202f   David Mayerich   added a new ENVI ...
302
  					interleave = BSQ;

6e257ab3   dmayerich   ENVI and colormap...
303
304
305
306
  			}

  			else if(token == "sensor type")

  				sensor_type = get_data_str(line);

  			else if(token == "byte order")

e8eb202f   David Mayerich   added a new ENVI ...
307
  				byte_order = (endianType)atoi(get_data_str(line).c_str());

6e257ab3   dmayerich   ENVI and colormap...
308
309
310
311
312
  			else if(token == "x start")

  				x_start = atof(get_data_str(line).c_str());

  			else if(token == "y start")

  				y_start = atof(get_data_str(line).c_str());

  			else if(token == "wavelength units")

e8eb202f   David Mayerich   added a new ENVI ...
313
314
315
  				wavelength_units = get_data_str(line);

  

              //get the next line

0174d823   dmayerich   bug fixes and exits
316
              getline(file, line);

e8eb202f   David Mayerich   added a new ENVI ...
317
318
319
  		}

  

  		//make sure the number of bands matches the number of wavelengths

9d3ba0b1   David Mayerich   added stim::hsi a...
320
  		size_t wavelengths = wavelength.size();

ee4dea28   David Mayerich   fixed errors in c...
321
  		if(wavelengths && bands != wavelengths)

e8eb202f   David Mayerich   added a new ENVI ...
322
323
324
  		{

              std::cout<<"ENVI Header Error -- Number of wavelengths doesn't match the number of bands.  Bands = "<<bands<<", Wavelengths = "<<wavelength.size()<<std::endl;

              exit(1);

0174d823   dmayerich   bug fixes and exits
325
          }

6e257ab3   dmayerich   ENVI and colormap...
326
  

721fd9d1   David Mayerich   fixed problems wi...
327
328
329
330
331
332
  		if(wavelength.size() == 0){											//if no list of wavelengths is given, create one based on band numbers

  			wavelength.resize(bands);

  			for(size_t b = 0; b < bands; b++)

  				wavelength[b] = (double)b;

  		}

  

6e257ab3   dmayerich   ENVI and colormap...
333
  		//close the file

e8eb202f   David Mayerich   added a new ENVI ...
334
335
336
337
338
  		file.close();

  

  		//set the file name

  		name = filename;

  

6e257ab3   dmayerich   ENVI and colormap...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  		return true;

  	}

  

  	void save(std::string filename)

  	{

  		//open a file

  		std::ofstream outfile(filename.c_str());

  

  		//write the ENVI type identifier

  		outfile<<"ENVI"<<std::endl;

  

  		//output all of the data

  		outfile<<"description = {"<<std::endl;

  		outfile<<"  "<<description<<"}"<<std::endl;

  

  		outfile<<"samples = "<<samples<<std::endl;

  		outfile<<"lines = "<<lines<<std::endl;

  		outfile<<"bands = "<<bands<<std::endl;

  		outfile<<"header offset = "<<header_offset<<std::endl;

  		outfile<<"file type = "<<file_type<<std::endl;

  		outfile<<"data type = "<<data_type<<std::endl;

  		outfile<<"interleave = ";

e8eb202f   David Mayerich   added a new ENVI ...
361
  		if(interleave == BIP)

6e257ab3   dmayerich   ENVI and colormap...
362
  			outfile<<"bip";

e8eb202f   David Mayerich   added a new ENVI ...
363
  		if(interleave == BIL)

6e257ab3   dmayerich   ENVI and colormap...
364
  			outfile<<"bil";

e8eb202f   David Mayerich   added a new ENVI ...
365
  		if(interleave == BSQ)

6e257ab3   dmayerich   ENVI and colormap...
366
367
368
369
370
371
372
373
374
375
376
377
378
  			outfile<<"bsq";

  			outfile<<std::endl;

  		outfile<<"sensor type = "<<sensor_type<<std::endl;

  		outfile<<"byte order = "<<byte_order<<std::endl;

  		outfile<<"x start = "<<x_start<<std::endl;

  		outfile<<"y start = "<<y_start<<std::endl;

  		outfile<<"wavelength units = "<<wavelength_units<<std::endl;

  		outfile<<"z plot titles = {";

  			outfile<<z_plot_titles[0]<<", "<<z_plot_titles[1]<<"}"<<std::endl;

  		outfile<<"pixel size = {"<<pixel_size[0]<<", "<<pixel_size[1]<<", units=Meters}"<<std::endl;

  		if(band_names.size() > 0)

  		{

  			outfile<<"band names = {"<<std::endl;

7006df5f   David Mayerich   reformat of direc...
379
  			for(unsigned int i=0; i<band_names.size(); i++)

6e257ab3   dmayerich   ENVI and colormap...
380
381
382
383
384
385
386
  			{

  				outfile<<band_names[i];

  				if(i < band_names.size() - 1)

  					outfile<<", ";

  			}

  			outfile<<"}"<<std::endl;

  		}

ee4dea28   David Mayerich   fixed errors in c...
387
388
389
390
391
392
393
  		//if there is a list of wavelengths, output it

  		if(wavelength.size()){

  			outfile<<"wavelength = {"<<std::endl;

  				for(unsigned int i=0; i<wavelength.size()-1; i++)

  					outfile<<wavelength[i]<<", ";

  				outfile<<wavelength.back()<<"}"<<std::endl;

  		}

6e257ab3   dmayerich   ENVI and colormap...
394
395
396
397
398
  

  		outfile.close();

  	}

  

  	void save()

e8eb202f   David Mayerich   added a new ENVI ...
399
  	{

6e257ab3   dmayerich   ENVI and colormap...
400
401
402
403
404
405
406
407
408
          //std::cout<<"ENVI Header Name: "<<name<<std::endl;

  		save(name);

  	}

  

  	//returns the size of a single value (in bytes)

  	unsigned int valsize()

  	{

  		switch(data_type)

  		{

e8eb202f   David Mayerich   added a new ENVI ...
409
  		case int8:			//1 = 8-bit byte

6e257ab3   dmayerich   ENVI and colormap...
410
  			return 1;

e8eb202f   David Mayerich   added a new ENVI ...
411
412
  		case int16:			//16-bit signed integer

  		case uint16:		//16-bit unsigned integer

6e257ab3   dmayerich   ENVI and colormap...
413
  			return 2;

e8eb202f   David Mayerich   added a new ENVI ...
414
415
416
  		case int32:			//32-bit signed long integer

  		case float32:		//32-bit floating point

  		case uint32:		//32-bit unsigned long integer

6e257ab3   dmayerich   ENVI and colormap...
417
  			return 4;

e8eb202f   David Mayerich   added a new ENVI ...
418
419
420
421
  		case float64:		//64-bit double-precision floating point

  		case complex32:		//32-bit complex value

  		case int64:		    //64-bit signed long integer

  		case uint64:		//64-bit unsigned long integer

6e257ab3   dmayerich   ENVI and colormap...
422
  			return 8;

e8eb202f   David Mayerich   added a new ENVI ...
423
  		case complex64:		//64-bit complex value

6e257ab3   dmayerich   ENVI and colormap...
424
425
426
427
  			return 16;

  		default:

  			return 0;

  		}

9d34229e   David Mayerich   restructured the ...
428
  	}

6e257ab3   dmayerich   ENVI and colormap...
429
  

9d34229e   David Mayerich   restructured the ...
430
431
432
  	//return the number of bytes that SHOULD be in the data file

  	size_t data_bytes(){

  		return samples * lines * bands * valsize() + header_offset;

6e257ab3   dmayerich   ENVI and colormap...
433
  	}

9d34229e   David Mayerich   restructured the ...
434
  	

a2bf1d08   David Mayerich   general bug fixes...
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
  

  	/// Convert an interleave type to a string

  	static std::string interleave_str(interleaveType t){

  		switch(t){

  		case stim::envi_header::BSQ:

  			return std::string("BSQ");

  		case stim::envi_header::BIL:

  			return std::string("BIL");

  		case stim::envi_header::BIP:

  			return std::string("BIP");

  		default:

  			std::cout<<"ERROR in stim::envi_header::typestr() - unrecognized type"<<std::endl;

  			exit(1);

  		}

  	}

  

  	/// Convert the current interleave type to a string

  	std::string interleave_str(){

  		return interleave_str(interleave);

  	}

dc8eb8aa   David Mayerich   added band trimmi...
455
456
  

  	/// Convert a wavelength to a band index (or a pair of surrounding band indices)

48f356fa   David Mayerich   bug fixes for FFT...
457
  	///		if the file doesn't specify wavelengths, w is assumed to be a band index

dc8eb8aa   David Mayerich   added band trimmi...
458
459
  	std::vector<size_t> band_index(double w){

  		std::vector<size_t> idx;										//create an empty array of indices

48f356fa   David Mayerich   bug fixes for FFT...
460
461
462
  		if(wavelength.size() == 0){										//if a wavelength vector doesn't exist, assume the passed value is a band

  			if(w < 0 || w > bands-1) return idx;						//if the band is outside the given band range, return an empty vector

  			size_t low, high;											//allocate space for the floor and ceiling

58e55e6b   David Mayerich   fixed colormap.h ...
463
464
  			low = (size_t)std::floor(w);										//calculate the floor

  			high = (size_t)std::ceil(w);										//calculate the ceiling

48f356fa   David Mayerich   bug fixes for FFT...
465
466
467
468
469
470
471
472
473
474
  			if(low == high)												//if the floor and ceiling are the same

  				idx.push_back(low);										//return a vector with one element (the given w matches a band exactly)

  			else{

  				idx.resize(2);											//otherwise return the floor and ceiling

  				idx[0] = low;

  				idx[1] = high;

  			}

  			return idx;

  		}

  		else if(w < wavelength[0] || w > wavelength[bands-1]) return idx;	//if the wavelength range is outside of the file, return an empty array

dc8eb8aa   David Mayerich   added band trimmi...
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  

  		for(size_t b = 0; b < bands; b++){							//for each band in the wavelength vector

  			if(wavelength[b] == w){									//if an exact match is found

  				idx.push_back(b);										//add the band to the array and return it

  				return idx;

  			}

  			if(wavelength[b] >= w){ 								//if the current wavelength exceeds w

  				idx.resize(2);

  				idx[0] = b-1;										//push both the previous and current band index

  				idx[1] = b;

  				return idx;											//return the pair of indices

  			}

  		}

  		return idx;

  	}

  

  	/// Convert a wavelength range to a list of bands

  	std::vector<size_t> band_indices(double w0, double w1){

  

  		size_t idx0 = 0;

  		size_t idx1 = 0;									//declare the interval indices for the band range

  

  		//get the indices for the first wavelength

  		std::vector<size_t> r;

  

  		if(w0 > wavelength[bands-1] || w1 < wavelength[0]){

  			std::cout<<"ERROR in envi_header::band_indices - wavelengths are completely out of range: ["<<w0<<", "<<w1<<"]"<<std::endl;

  			exit(1);

  		}

  		if(w0 < wavelength[0])								//if the lower wavelength is outside the file range

  			idx0 = 0;										//just set it to zero

  		else{

  			r = band_index(w0);

  			if(r.size() == 1)								//if there is an exact match, set the first interval index

  				idx0 = r[0];

  			else

  				idx0 = r[1];								//otherwise save the highest band index (this is the first band with wavelength > w0)

  		}

  		//get the indices for the second wavelength

  		if(w1 > wavelength[bands-1])

  			idx1 = bands-1;

  		else{

  			r = band_index(w1);

  			if(r.size() == 0)

  				idx1 = bands - 1;

  			else

  				idx1 = r[0];									//take the lowest band index (this is the last band < w1)

  		}

  

  		size_t n = idx1 - idx0 + 1;							//calculate the number of bands in this interval

  		r.resize(n);										//resize the band index array

  		for(size_t b = 0; b < n; b++){						//for each band in the interval

  			r[b] = idx0 + b;								//	insert the band in the array

  		}

  

  		return r;											//return the index array

  	}

e8eb202f   David Mayerich   added a new ENVI ...
532
533
534
  };		//end EnviHeader

  }

  #endif