function [h,l] = readUPC(fname,limit) % function [h,l] = readUPC(fname,limit) % opens a UPC format file, reads the header and limit # of data lines % it returns two structures. % The default for limit is 10,000, which takes 90 seconds. % You may use Inf to read all points. if nargin < 2 limit = 1e5; end if nargout < 2 % save time: don't read points if there is no returning them. limit = 0; end fid = fopen(fname); if fid == -1 error(['Could not open ' fname]) end h = readUPChead(fid); n = min(double(h.numOfPts), limit); l.gpsTimeOfWeek=zeros(n,1); % The GPS time of week of the point l.sensorNum=char(zeros(n,2)); % The laser sensor number used for the point l.julianDay=char(zeros(n,3)); % The day the point was collected l.flightLine=char(zeros(n,3)); % The flight line number of the point l.xyz=zeros(n, 3); % The recorded x-coord of the point l.intensity=zeros(n,1); % The intensity of the point l.rgb=zeros(n,3); % The red component of the point l.returnNum=zeros(n,1); % The return number of the point for i = 1:n l.gpsTimeOfWeek(i)=fread(fid,1,'double'); % The GPS time of week of the point l.sensorNum(i,:)=fread(fid,[1 2],'*char'); % The laser sensor number used for the point l.julianDay(i,:)=fread(fid,[1 3],'*char'); % The day the point was collected l.flightLine(i,:)=fread(fid,[1 3],'*char'); % The flight line number of the point l.xyz(i,:)=fread(fid,[1 3],'int'); % The recorded x-coord of the point l.intensity(i)=fread(fid,1,'uchar'); % The intensity of the point l.rgb(i,:)=fread(fid,[1 3],'ushort'); % The red component of the point l.returnNum(i)=fread(fid,1,'*char'); % The return number of the point end fclose(fid);