-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite_envi_header.pro
66 lines (56 loc) · 1.75 KB
/
write_envi_header.pro
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
55
56
57
58
59
60
61
62
63
64
65
66
; output the image
; OPENW, lun, outfile, /APPEND,/get_lun ;outfile is the directory
; WRITEU, lun, image ; image is the variable output
; CLOSE, lun
; free_lun, lun
; only write envi header
pro write_envi_header, infile, outfile, $
samples = samples, $
lines = lines, $
bands = bands, $
data_type = data_type, $
interleave = interleave, $
map_info = map_info
openr, in, infile+'.hdr', /get_lun ;打开模板文件的头文件
; Read one line at a time, saving the result into hdr
hdr = ''
line = ''
WHILE NOT EOF(in) DO BEGIN
READF, in, line
hdr = [hdr, line]
ENDWHILE
FREE_LUN, in
hdr=hdr[1:*]
index=where(STRMATCH(hdr, 'band names = *'), count)
if count gt 0 then hdr=hdr[0:index-1]
if KEYWORD_SET(samples) then begin
index=where(STRMATCH(hdr, 'samples = *'))
hdr[index]='samples = '+ strtrim(string(samples),2)
endif
if KEYWORD_SET(lines) then begin
index=where(STRMATCH(hdr, 'lines = *'))
hdr[index]='lines = '+ strtrim(string(lines),2)
endif
if KEYWORD_SET(bands) then begin
index=where(STRMATCH(hdr, 'bands = *'))
hdr[index]='bands = '+ strtrim(string(bands),2)
endif
if KEYWORD_SET(data_type) then begin
index=where(STRMATCH(hdr, 'data type = *'))
hdr[index]='data type = '+ strtrim(string(data_type),2)
endif
if KEYWORD_SET(interleave) then begin
index=where(STRMATCH(hdr, 'interleave = *'))
hdr[index]='interleave = '+ interleave
endif
if KEYWORD_SET(map_info) then begin
index=where(STRMATCH(hdr, 'map info = *'), count)
if count gt 0 then hdr[index]='map info = '+ map_info
endif
n=n_elements(hdr)
openw, out, outfile+'.hdr', /get_lun
for i=0, n-1 do begin
printf, out, hdr[i]
endfor
free_lun, out
end