1 function v = readl2data(prefix,file,file2,silent)
2 %v = readl2data(prefix,file,file2,silent)
3 %read L2 data and return v.lon v.lat v.data
5 % prefix - string, path to directory with data files
6 % file, file2 - strings, file names of geolocation and active fire dat,
8 % silent - character to print output, optional
11 % v - struct, contains geolocation dat and fire mask.
12 fprintf('Reading l2 data\n')
16 pfile2=[prefix,file2];
19 fprintf('Reading Modis data\n')
21 v.lon = hdfread(pfile, 'MODIS_Swath_Type_GEO', 'Fields', 'Longitude');
22 v.lat = hdfread(pfile, 'MODIS_Swath_Type_GEO', 'Fields', 'Latitude');
23 v.data = hdfread(pfile2, '/fire mask', 'Index', {[1 1],[1 1],[size(v.lon)]});
24 %v.frp = hdfread(pfile2, '/FP_power', 'Index', {[1 1],[1 1],[size(v.lon)]});
26 warning('read error somewhere')
29 fprintf('Reading VIIRS data\n')
30 fprintf('fires : %s \n',pfile2)
31 fprintf('geo : %s \n',pfile)
33 v.lon = h5read(pfile,'/HDFEOS/SWATHS/VNP_750M_GEOLOCATION/Geolocation Fields/Longitude');
34 v.lat = h5read(pfile,'/HDFEOS/SWATHS/VNP_750M_GEOLOCATION/Geolocation Fields/Latitude');
35 v.data = h5read(pfile2,'/fire mask');
37 warning('read error somewhere')
43 [v.time,v.timestr]=rsac2time(file);
44 if ~exist('silent','var'),
45 fprintf('file name w/prefix %s\n',pfile);
46 fprintf('file name %s\n',file);
47 fprintf('image time %s\n',datestr(v.time));
52 %[rows,cols]=size(v.data);
54 % Xpixel=[0:cols-1]+0.5;
55 % Ypixel=[0:rows-1]+0.5;
56 % v.lon = geo(1)+Xpixel*geo(2);
57 % v.lat = geo(4)+Ypixel*geo(6); %subtraction for camp
59 if any(v.data(:)<0 | v.data(:)>9),
60 warning('Value out of range 0 to 9 for MODIS14 data')
63 count(i+1)=sum(v.data(:)==i);
67 v.pixels.unknown= count(1)+count(2)+count(3)+count(7);
68 v.pixels.water = count(4);
69 v.pixels.cloud = count(5);
70 v.pixels.land = count(6);
71 v.pixels.fire = count(8:10);
74 if ~exist('silent','var'),
76 % fprintf('rows %i\n',rows)
77 % fprintf('cols %i\n',cols)
78 % fprintf('top left X %19.15f\n',geo(1))
79 % fprintf('W-E pixel resolution %19.15f\n',geo(2))
80 % fprintf('rotation, 0=North up %19.15f\n',geo(3))
81 % fprintf('top left Y %19.15f\n',geo(4))
82 % fprintf('rotation, 0=North up %19.15f\n',geo(5))
83 % fprintf('N-S pixel resolution %19.15f\n',geo(6))
84 fprintf('unprocessed/unknown %i\n',v.pixels.unknown)
85 fprintf('water %i\n',v.pixels.water)
86 fprintf('land %i\n',v.pixels.land)
87 fprintf('cloud %i\n',v.pixels.cloud)
88 fprintf('low-confidence fire %i\n',v.pixels.fire(1))
89 fprintf('nominal-confid fire %i\n',v.pixels.fire(2))
90 fprintf('high-confidence fire %i\n',v.pixels.fire(3))
92 % if geo(3)~=0 | geo(5)~=0,
93 % error('rotation not supported')