-
Notifications
You must be signed in to change notification settings - Fork 57
/
LoadSensorType.m
74 lines (67 loc) · 2.46 KB
/
LoadSensorType.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function [sensor,num_Lst,InputFile,main_meta] = LoadSensorType(path_data)
%LOADSENSORTYPE Basic metadata should be loaded first to see which sensor
%here.
% Add Landsat 9 , Feb., 17, 2022
%% Search metadate file for Landsat 4-8
main_meta=dir(fullfile(path_data,'L*MTL.txt'));
existMTL=size(main_meta);
InputFile=[];
if existMTL(1)==0
main_meta=dir(fullfile(path_data, 'S*MTD*TL*.xml'));
if isempty(main_meta)
main_meta=dir(fullfile(path_data, 'MTD*TL*.xml'));
end
if ~isempty(main_meta)
txtstart = strfind(path_data,'S2A') ;
num_Lst='2A';
if isempty(txtstart)
txtstart = strfind(path_data,'S2B') ; % S2A or S2B by Shi 10/18/2017
num_Lst='2B';
end
txtend = strfind(path_data,'.SAFE')-1 ;
InputFile.DataStrip = path_data(txtstart:txtend) ;
InputFile.Dmain = path_data(1:txtstart-1) ;
txtstart = strfind(path_data,'GRANULE')+8 ;
InputFile.InspireXML=path_data(1:txtstart-10); % extra add to read inspire xml.
txtend = length(path_data);
InputFile.Granule = path_data(txtstart:txtend) ;
InputFile.pathh = path_data ;
main_meta.name=InputFile.Granule;% return file name fro Fmask results.
else
% fprintf('No available data in the current folder!\n');
sensor=[]; % no supported image.
num_Lst=[];
InputFile=[];
main_meta=[];
return;
end
else
% determine sensor type
% open and read hdr file
fid_in=fopen(fullfile(path_data,main_meta.name),'r');
geo_char=fscanf(fid_in,'%c',inf);
fclose(fid_in);
geo_char=geo_char';
geo_str=strread(geo_char,'%s');
% Identify Landsat Number (Lnum = 4, 5, 7, or 8)
LID=char(geo_str(strmatch('SPACECRAFT_ID',geo_str)+2));
% num_Lst=str2double(LID(end-1));
num_Lst=(LID(end-1));
end
% define Landsat sensor.
sensor='';
if strcmp(num_Lst,'8') | strcmp(num_Lst,'9')
sensor='L_OLI_TIRS';
else
if strcmp(num_Lst,'4')||strcmp(num_Lst,'5')||strcmp(num_Lst,'6')
sensor='L_TM';
else
if strcmp(num_Lst,'7')
sensor='L_ETM_PLUS';
end
end
end
if strcmp(num_Lst,'2A')||strcmp(num_Lst,'2B')
sensor='S_MSI';
end
end