-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathread_envihdr.m
54 lines (53 loc) · 1.63 KB
/
read_envihdr.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function info = read_envihdr(hdrfile)
% READ_ENVIHDR read and return ENVI image file header information.
% INFO = READ_ENVIHDR('HDR_FILE') reads the ASCII ENVI-generated image
% header file and returns all the information in a structure of
% parameters.
%
% Example:
% >> info = read_envihdr('my_envi_image.hdr')
% info =
% description: [1x101 char]
% samples: 658
% lines: 749
% bands: 3
% header_offset: 0
% file_type: 'ENVI Standard'
% data_type: 4
% interleave: 'bsq'
% sensor_type: 'Unknown'
% byte_order: 0
% map_info: [1x1 struct]
% projection_info: [1x102 char]
% wavelength_units: 'Unknown'
% pixel_size: [1x1 struct]
% band_names: [1x154 char]
%
% NOTE: This function is used by ENVIREAD to import data.
fid = fopen(hdrfile);
while fid
line = fgetl(fid);
if line == -1
break
else
eqsn = findstr(line,'=');
if ~isempty(eqsn)
param = strtrim(line(1:eqsn-1));
param(findstr(param,' ')) = '_';
value = strtrim(line(eqsn+1:end));
if isempty(str2num(value))
if ~isempty(findstr(value,'{')) && isempty(findstr(value,'}'))
while isempty(findstr(value,'}'))
line = fgetl(fid);
value = [value,strtrim(line)];
end
end
eval(['info.',param,' = ''',value,''';'])
else
eval(['info.',param,' = ',value,';'])
end
end
end
end
fclose all;
end