% CHECKFANPOS a diagnostic script for sonar logger development % check all the fan beam header angle files in a directory % run this from within the directory of sonar files that you want to check if ~exist('Fheadang','var') fnames = dir; nfiles = length(fnames); Ffound = 0; Pfound = 0; nFfiles = 0; nPfiles = 0; for ifile = 3:nfiles, %disp(sprintf('reading %s for nangles',fnames(ifile).name)) [path, fname, ext] = fileparts(fnames(ifile).name); if length(ext) >= 2, switch ext(1:2), case '.F' nFfiles = nFfiles + 1; if ~Ffound, [FanData, FanHeader, FanSwitches] = readfan(fnames(ifile).name,0); Fnangles = length(FanHeader.HeadAngle); Ffound = 1; end % case '.P' % nPfiles = nPfiles + 1; % if ~Pfound, % [PencilData, PencilHeader, PencilSwitches] = readpencil(fname, 0); % Pfound = 1; % end end end end Fheadang = ones(nFfiles,Fnangles).*NaN; FstepdirH = Fheadang; Fflags = zeros(nFfiles,2); Ptimes = zeros(nPfiles,1); iFfile = 1; iPfile = 1; for ifile = 3:nfiles, if fnames(ifile).name(1) == 'S', %disp(sprintf('reading %s',fnames(ifile).name)) [path, fname, ext] = fileparts(fnames(ifile).name); if length(ext) >= 2, switch ext(1:2), case '.F' [FanData, FanHeader, FanSwitches] = readfan(fnames(ifile).name,0); if isfield(FanHeader,'HeadAngle'), if length(FanHeader.HeadAngle) == Fnangles, Fheadang(iFfile,:) = FanHeader.HeadAngle; FstepdirH(iFfile,:) = FanHeader.StepDirection; elseif length(FanHeader.HeadAngle) < Fnangles, Fheadang(iFfile,1:length(FanHeader.HeadAngle)) = FanHeader.HeadAngle; FstepdirH(iFfile,1:length(FanHeader.HeadAngle)) = FanHeader.StepDirection; else disp('length(FanHeader.HeadAngle) > Fnangles'); pad = ones(nFfiles,length(FanHeader.HeadAngle)-Fnangles).*NaN; Fnangles = length(FanHeader.HeadAngle); Fheadang = [Fheadang, pad]; % expand the matrix Fheadang(iFfile,1:length(FanHeader.HeadAngle)) = FanHeader.HeadAngle; FstepdirH = [FstepdirH, pad]; FstepdirH(iFfile,1:length(FanHeader.HeadAngle)) = FanHeader.StepDirection; end FstepdirSW(iFfile) = FanSwitches.StepDirection; Fmoverel(iFfile) = FanSwitches.MoveRelative; else disp('No header data found') end Fname{iFfile} = fnames(ifile).name; iFfile = iFfile+1; % case '.P' % if ~Pfound, % [PencilData, PencilHeader, PencilSwitches] = readpencil(fname, 0); % Pname{iPfile} = fnames(ifile).name; % Ptimes(iPfile) = PencilHeader.PencilTime; % iPfile = iPfile+1; % end end end end end end Fflags = zeros(nfiles,4); % look for bads for ifile = 1:nFfiles, % set flags if ~isnan(Fheadang(ifile,:)) & ~(Fheadang(ifile,:)), % first is for all zero headangle Fflags(ifile,1) = 1; elseif Fheadang(ifile,2300) < 0, % look specifcally for that funky pattern Fflags(ifile,2) = 1; elseif gmax(diff(Fheadang(ifile,:)')) > 2, Fflags(ifile,3) = 1; % this one has jitter else % it's a good one! Fflags(ifile,4) = 1; %plot(Fheadang(ifile,:)) %title(sprintf('#%d: %s',ifile,char(Fname(ifile)))) %pause end end Fgood = find(Fflags(:,end)); disp(sprintf('# Fan files = %d',nFfiles)) Fbadstart = find(Fflags(:,2)); % indeces to files witht he weird pattern disp(sprintf('# wrong start angle = %d',length(Fbadstart))) Fjitter = find(Fflags(:,3)); disp(sprintf('# jittery = %d',length(Fjitter))) save headerdata fid = fopen('checkfanpos.log','a'); fprintf(fid,'%s %s\n',pwd, datestr(now)); fprintf(fid,'# Fan files = %d\n',nFfiles); fprintf(fid,'# wrong start angle = %d\n',length(Fbadstart)); fprintf(fid,'# jittery = %d\n',length(Fjitter)); fclose(fid);