-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathenvi_write.m
45 lines (39 loc) · 1.23 KB
/
envi_write.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
function envi_write(data,R)
% envi_write(data,R,filename)
%
% Function to save the gridded data in ENVI format.
% data is the grided data which we want to write and R is the Refernce
% Matrix (see help makerefmat). filename is the string which is the name of output file .
%
%
% Written By
% Faisal Shahzad
% Remote Sensing Group
% TU Bergakademie Freiberg,
% Germany
% www.rsg.tu-freiberg.de
info = evalin('base','info');
[filename, pathname] = uiputfile(strcat(info.path,'*.hdr'),'Save as ENIV Header');
files = strcat(pathname,filename);
if isempty(files)
return
end
[r c]=size(data);
data = single(data);
data(isnan(data)) = -9999;
fid = fopen(files(1:end-4),'w');
fwrite(fid,data,'single');
fclose(fid);
fid = fopen(strcat(files),'w');
fprintf(fid,'%s \n','ENVI');
fprintf(fid,'%s \n','description = {');
fprintf(fid,'%s \n','TecDEM: 1.0}');
fprintf(fid,'%s %i \n','samples =',r);
fprintf(fid,'%s %i \n','lines =',c);
fprintf(fid,'%s %i \n', 'bands =',1);
fprintf(fid,'%s %i \n', 'data type =',4);
fprintf(fid,'%s \n','interleave = bsq');
fprintf(fid,'%s \n','map info = {Geographic Lat/Lon, 1.0000, 1.0000,',num2str(R(3,1)),','...
,num2str(R(3,2)),',',num2str(R(2,1)),',' ,num2str(-R(1,2)),' WGS-84,units=Degrees}');
fclose(fid);
end