% CHECKSONAR SCRIPT TO INSPECT USGS IMAGENEX FILES % % -- to use this file, put a separate copy of the imagenex data directories (I#####) % containing all the images you want to inspect under a single root directory, % then point to that directory when prompted by this program % -- look through the image files and delete files that are 0-5kb, I'm not % sure why these duds appear, but they will hang this movie script % -- You will need to set, manually, in this script, the values of the settings % struct in this script too, where it % says 'get metadata from user' simply set % the correct values in 'def' % -- frame images are written to the local directory and also saved to % Fanmovie or Pencilmovie in the workspace, so if you like MATLAB movies, % save the workspace when this script is done. % -- the best results so far have been by digitizing frames using VideoMach % Microsoft Video 1 codec, 75% compression quality % turn keep duration off % turn automatic off % 5 frames per second % parse imagenex data file names to get the time stamps % analyze time % make movies % % Written by Marinna Martini 7/16/04 % % U.S. Geological Survey, Woods Hole Field Center close all clear % things you need to set by hand to make this work, maybe I'll make it all % gui some day... % for Eurostrat first deployment 2002-2003 %RootDataDir = 'E:\EuroStrat\701im\test_images_for_movies_single\'; % don't delete these %RootDataDir = 'E:\EuroStrat\701im\test_images_for_movies\'; % don't delete these %RootDataDir = 'E:\EuroStrat\701im\images_for_movies\'; % don't delete these %RootDataDir = 'C:\projects\euro\701im\images_for_movies\'; %RootDataDir = 'C:\projects\euro\701im\test_images_for_movies_single\'; %RootDataDir = 'G:\Feb03EuroStrat\701-Particle\701im\'; %RootDataDir = 'C:\crs\data\EuroStrat_0203\701-Particle\701im\'; RootDataDir = 'C:\instment\imagenex\test160704\'; FanSettings = {'348','0','1','500','0.55','2002'}; PencilSettings = {'132','0','1','500','1.06','2002'}; % choose one %SonartoAnimate = 'Fan'; SonartoAnimate = 'Pencil'; % ask user to point to a directory of files %RootDataDir = uigetdir('c:\projects\euro\701im','Select the root directory with all the Imagenex files'); %RootDataDir = uigetdir('c:\instment\imagenex','Select the root directory with all the Imagenex files'); SubDataDir = dir(RootDataDir); % get the metadata from the user RootDataDir = uigetdir(pwd,'Choose a directory of snar files'); SonartoAnimate = questdlg('Which sonar to inspect?','Choose a sonar','Fan','Pencil','Fan'); prompt = {'Enter the sector that was swept:',... 'Enter the center to sweep around:',... 'Enter the Step size used:',... 'Enter the data points setting (points/10):',... 'Enter the sonar''s height off the bottom, m:',... 'Enter the year the instrument was deployed:',... }; if(strcmp(SonartoAnimate,'Fan')), def = FanSettings; elseif(strcmp(SonartoAnimate,'Pencil')), def = PencilSettings; else error('Pencil or Fan?') end dlgtitle = 'Sonar input metadata for the setup'; lineNo = 1; dlgresult = inputdlg(prompt,dlgtitle,lineNo,def); settings.SectorSweep = str2num(dlgresult{1}); settings.AngleSweepAround = str2num(dlgresult{2}); settings.StepSize = str2num(dlgresult{3}); settings.DataPoints = str2num(dlgresult{4}); % number of 'ranges' recorded in each ping settings.Height = str2num(dlgresult{5}); settings.datayear = str2num(dlgresult{6}); % RootMovieDir = uigetdir(pwd,'Select or create a directory to place the image files'); % prompt = {'Enter a root file name:'}; % def = {'frame'}; % dlgtitle = 'Enter a file name for the images'; % lineNo = 1; % dlgresult = inputdlg(prompt,dlgtitle,lineNo,def); % outfile = dlgresult{1}; outfile = 'frame'; outdir = 'frame'; [success,message,messageid] = mkdir(outdir); outfile = fullfile(outdir,outfile); clear FanTime PencilTime Fanidx = 1; Pencilidx = 1; imfig = figure; set(gcf,'Position',[9 37 827 659]) % go through each and parse for d=3:length(SubDataDir), % the first two are always . and .. disp(SubDataDir(d).name) % act only on directories if exist(fullfile(RootDataDir,SubDataDir(d).name)) == 7, DataFiles = dir(fullfile(RootDataDir,SubDataDir(d).name)); for f = 3:length(DataFiles), % disp(DataFiles(f).name) % name convention is S1111020.F50 = S1MMDDHH.?MM % where ? = F for fan or P for pencil a = sscanf(DataFiles(f).name,'S1%c%c%c%c%c%c.%c%c%c') mon = str2num(a(1:2)); day = str2num(a(3:4)); hr = str2num(a(5:6)); min = str2num(a(8:9)); datenum_sonar = datenum(2002,mon,day,hr,min,0); WhichSonar = a(7); if WhichSonar == 'F', % first, display the sonar image FanTime(Fanidx) = julian([settings.datayear mon day hr min 0]); FanDatenum=datenum([settings.datayear mon day hr min 0]); if strcmp(SonartoAnimate,'Fan'), subplot(3,1,1) showfan(fullfile(RootDataDir,SubDataDir(d).name,DataFiles(f).name),... 'polar',settings); ylabel('Fan Beam Sonar, range in meters') % put the plots where we want them for a pretty picture kids = get(gcf,'children'); % get the pointer to the images set(kids(1),'position',[0.13 0.238 0.75 0.75]) %set(kids(2),'position',[0.22 0.123 0.58 0.067]) %set(kids(1),'position',[0.22 0.032 0.58 0.067]) %FanMovie(Fanidx) = getframe(gcf); %imfile = sprintf('%s%03d.png',outfile,Fanidx); %set(gcf,'paperunits','normalized','renderer','zbuffer') %print(imfig,'-dpng',imfile); % best for videomach %set(gcf,'paperunits','inches','renderer','painters') end Fanidx = Fanidx+1; elseif WhichSonar == 'P', % first, display the sonar image PencilTime(Pencilidx) = julian([settings.datayear mon day hr min 0]); if strcmp(SonartoAnimate,'Pencil'), subplot(2,1,1) showpencil(fullfile(RootDataDir,SubDataDir(d).name,DataFiles(f).name),... 'polar',settings); %PencilMovie(Pencilidx) = getframe(gcf); %imfile = sprintf('%s%03d.png',outfile,Pencilidx); %print(imfig,'-djpeg90',imfile); % image was a bit muddy, text looked OK %print(imfig,'-dpng',imfile); % best for videomach end Pencilidx = Pencilidx+1; end pause (3) end end % clf; end