% browsehydraburst - browse ADV burst file data by burst (works for PCADP too) % % browsehydraburst('file',filename) opens the file given by filename for browsing % % % Written by Marinna Martini for the U.S. Geological Survey % Coastal & Marine Program Woods Hole Field Center, Woods Hole, MA % http://woodshole.er.usgs.gov/ Please report bugs to mmartini@usgs.gov % 16 Nov 2005 % -- call gregorian instead of gregoria % 14 Sep 2005 % -- fix the problem of missing bursts (in the case of multiple samplign % scenarios) now handled gracefully % Version 2.5 % 15 Mar 2005 There is a java bug in version R14 (no SP) and lower that % limits how far numerically a slider will go. To turn off java so this % works, use feature('javafigures',0) or upgrade to R14 SP2 % Last Modified by GUIDE v2.5 26-Apr-2005 13:34:29 function varargout = browsehydraburst(varargin) % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @browsehydraburst_OpeningFcn, ... 'gui_OutputFcn', @browsehydraburst_OutputFcn, ... 'gui_LayoutFcn', [], ... 'gui_Callback', []); if nargin & isstr(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before browsehydraburst is made visible. function browsehydraburst_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to browsehydraburst (see VARARGIN) % Choose default command line output for browsehydraburst handles.output = hObject; % figure1: 1.000034179687500e+002 % slider1: 1.060206298828125e+002 % axes1: 1.010040283203125e+002 % output: 1.000034179687500e+002 % slider 1 controls time shift % slider 2 controls which burst % slider 3 controls which profiles % look for a filename in the varargin handles.mydata.burstfile = []; for i = 1:length(varargin), if strcmp(varargin{i},'file'), handles.mydata.burstfile = varargin{i+1}; end end if isempty(handles.mydata.burstfile), [filename, pathname, filterindex] = uigetfile('*.*','Open a netCDF file containing burst Hydra data'); if ~filename, return; end handles.mydata.burstfile = fullfile(pathname, filename); end % open the netCDF file and do the basic checks cdf = netcdf(handles.mydata.burstfile); % for passing to other methods handles.mydata.cdf = cdf; set(handles.figure1,'UserData',cdf); % store the netCDF file pointer here so I can close it later set(handles.figure1,'DeleteFcn','if ~isempty(get(gcf,''UserData'')), close(get(gcf,''UserData'')); end'); % and this is the code that will close it if isempty(cdf), disp(['Unable to open netCDF file ',handles.mydata.burstfile]); return; end dimnames = ncnames(dim(cdf)); flag = 0; for i=1:length(dimnames), % make sure this is a burst data file if strcmp(dimnames{i},'sample') || strcmp(dimnames{i},'profile'), flag = 1; end end if ~flag, close(cdf); return; end handles.mydata.ispcadp = 0; if findstr(cdf.INST_TYPE(:),'PCADP'), % find out if this is a PCADP % PCADP raw data file shape is handles.mydata.ispcadp = 1; handles.mydata.ncells = length(cdf{'depth'}); for n=1:handles.mydata.ncells, handles.mydata.lstrings{n} = sprintf('%d',n); end else handles.mydata.ncells = 1; handles.mydata.ispcadp = 0; end set(handles.text7,'string',sprintf('Now browsing file %s',handles.mydata.burstfile)) n=1; varnames = ncnames(var(cdf)); for i=1:length(varnames), % remove burstnum and time if strcmp(varnames{i},'burst') || strcmp(varnames{i},'profile') || ... strcmp(varnames{i},'depth') || strcmp(varnames{i},'lat') || strcmp(varnames{i},'lon') ||... strcmp(varnames{i},'time') || strcmp(varnames{i},'time2') || strcmp(varnames{i},'burstNum'), % do nothing else handles.mydata.varnames{n} = varnames{i}; n=n+1; end end handles.mydata.vartoplot = handles.mydata.varnames{1}; handles.mydata.iburst = 1; handles.mydata.icell = 1; s = size(cdf{'time'}); handles.mydata.nbursts = s(1); handles.mydata.nsamples = s(2); handles.mydata.nsamplesinview = handles.mydata.nsamples; handles.mydata.samples = [1 handles.mydata.nsamplesinview]; if handles.mydata.nsamples < 500, handles.mydata.minsamplesinview = 1; else handles.mydata.minsamplesinview = 500; end disp('Loading the burst numbers, one moment...') handles.mydata.burstNum = cdf{'burst'}(:); % need these for a lookup table if isempty(handles.mydata.burstNum), handles.mydata.burstNum = cdf{'burstNum'}(:); end % slider 1 - zoom within a burst set(handles.text1,'string',sprintf('%3.0f',handles.mydata.minsamplesinview)); set(handles.text4,'string',sprintf('%3.0f in view',handles.mydata.nsamples)); % slider 1 limits -- maybe change the view zoom for the number of samples set(handles.slider1,'Value',handles.mydata.nsamples,'Min',handles.mydata.minsamplesinview,... 'Max',handles.mydata.nsamples,'SliderStep',[1/handles.mydata.nsamples 5/handles.mydata.nsamples]); set(handles.slider1,'Tooltipstring','Restrict the number of samples in view (zoom)') % slider 2 - burst selector - labels %set(handles.text2,'string',sprintf('%d',cdf{'burst'}(1))); set(handles.text2,'string',sprintf('%d',handles.mydata.burstNum(1))); %set(handles.text6,'string',sprintf('%d bursts',cdf{'burst'}(end))); set(handles.text6,'string',sprintf('%d bursts',handles.mydata.burstNum(end))); % slider 2 limits (burstnumber in view) set(handles.slider2,'Value',handles.mydata.burstNum(1),'Min',handles.mydata.burstNum(1),... 'Max',handles.mydata.burstNum(handles.mydata.nbursts),... 'SliderStep',[1/handles.mydata.nbursts 100/handles.mydata.nbursts]) set(handles.slider2,'Tooltipstring','Select burst number to display') % slider 3 - sample selector - labels set(handles.text3,'string',sprintf('%d',1)); if ~handles.mydata.ispcadp, set(handles.text5,'string',sprintf('%d samples in burst',length(cdf('sample')))); else set(handles.text5,'string',sprintf('%d samples in burst',length(cdf('profile')))); end %set slider 3 limits set(handles.slider3,'Value',1,'Min',handles.mydata.samples(1),'Max',handles.mydata.samples(2)) set(handles.slider3,'Tooltipstring','Select which part of burst to display (if zoomed)') % put varnames into listbox here set(handles.listbox1,'string',handles.mydata.varnames,'Value',1); set(handles.listbox1,'Tooltipstring','Select data to display') % set the goto box to the first burst set(handles.edit1,'String',sprintf('%d',handles.mydata.burstNum(handles.mydata.iburst))); set(handles.edit1,'Tooltipstring','enter a burst number to jump to') % Update handles structure guidata(hObject, handles); % This sets up the initial plot - only do when we are invisible % so window can get raised using example. if strcmp(get(hObject,'Visible'),'off') updateplot(hObject, handles) end % UIWAIT makes browsehydraburst wait for user response (see UIRESUME) % uiwait(handles.figure1); % ------------------ updates the plot - this is a user function function updateplot(hObject, handles) cdf = handles.mydata.cdf; vartoplot = handles.mydata.vartoplot; % this will be the selection samples = handles.mydata.samples; %disp(sprintf('updateplot: iburst = %d',handles.mydata.iburst)) tm1 = datenum(gregorian(cdf{'time'}(handles.mydata.iburst,samples(1)))); tm1 = tm1+cdf{'time2'}(handles.mydata.iburst,samples(1))./(24*3600*1000); cburst = cdf{'burst'}(handles.mydata.iburst); axes(handles.axes1); cla; data = cdf{vartoplot}(handles.mydata.iburst,samples(1):samples(2),:); plot(samples(1):samples(2),data); ylabel(cdf{vartoplot}.units(:)); text(0.05,0.05,sprintf('%s at %s, burst #%d, samples #%d to %d',cdf{vartoplot}.long_name(:),... datestr(tm1), cburst, samples(1), samples(2)),'units','normalized'); if handles.mydata.ispcadp, if ~isvector(data), legend(handles.mydata.lstrings,'Location','EastOutside'); end end % Update handles structure guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = browsehydraburst_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure % --- Executes during object creation, after setting all properties. function slider1_CreateFcn(hObject, eventdata, handles) % hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background, change % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER. usewhitebg = 1; if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % The actual step size is a function of the specified SliderStep and the % total slider range (Max - Min). The default, [0.01 0.10], provides % a 1 percent change for clicks on the arrow button and a 10 percent % change for clicks in the trough. % --- Executes on slider movement. function slider1_Callback(hObject, eventdata, handles) % hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider handles.mydata.nsamplesinview = round(get(hObject,'Value')); % now reset the view limits accordingly, use the first point as the anchor handles.mydata.samples(2) = handles.mydata.samples(1)+handles.mydata.nsamplesinview-1; if handles.mydata.samples(2) > handles.mydata.nsamples, handles.mydata.samples(2) = handles.mydata.nsamples; handles.mydata.samples(1) = handles.mydata.nsamples-handles.mydata.nsamplesinview; end if handles.mydata.samples(1) <= 0, handles.mydata.samples(1) = 1; end % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function slider2_CreateFcn(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background, change % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER. usewhitebg = 1; if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on slider movement. function slider2_Callback(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider cburst = round(get(hObject,'Value')); handles.mydata.iburst = find(handles.mydata.burstNum == cburst); if isempty(handles.mydata.iburst), disp('selected burst number not found, using the next in sequence') handles.mydata.iburst = find(handles.mydata.burstNum > cburst,1,'first'); end %disp(sprintf('slider2: cburst = %d; iburst = %d',cburst,handles.mydata.iburst)) set(handles.edit1,'String',sprintf('%d',cburst)); % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function slider3_CreateFcn(hObject, eventdata, handles) % hObject handle to slider3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background, change % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER. usewhitebg = 1; if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on slider movement. function slider3_Callback(hObject, eventdata, handles) % hObject handle to slider3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider %disp(handles.mydata.pcprof) handles.mydata.samples(1) = round(get(hObject,'Value')); % now reset the view limits accordingly, use middle as the anchor handles.mydata.samples(2) = handles.mydata.samples(1)+handles.mydata.nsamplesinview-1; if handles.mydata.samples(2) > handles.mydata.nsamples, handles.mydata.samples(2) = handles.mydata.nsamples; handles.mydata.samples(1) = handles.mydata.nsamples-handles.mydata.nsamplesinview; end if handles.mydata.samples(1) <= 0, handles.mydata.samples(1) = 1; end % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 list = get(hObject,'String'); handles.mydata.vartoplot = list{get(hObject,'Value')}; guidata(hObject, handles); updateplot(hObject, handles); function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double cburst = str2num(get(hObject,'String')); cburst = round(cburst); % just in case the user doesn't enter an integer handles.mydata.iburst = find(handles.mydata.burstNum == cburst); % should be one value... if isempty(handles.mydata.iburst), % figure out if we are too high or too low if handles.mydata.iburst < handles.mydata.burstNum(1), handles.mydata.iburst = 1; disp('selected burst number is less than the smallest burst number in the file,') disp('using the smallest...') elseif handles.mydata.iburst > handles.mydata.nbursts; handles.mydata.iburst = handles.mydata.burstNum(end); disp('selected burst number is greater than the greatest burst number in the file,') disp('using the largest...') else, disp('selected burst number not found, using the next in sequence') handles.mydata.iburst = find(handles.mydata.burstNum > cburst,1,'first'); end elseif length(handles.mydata.iburst) > 1, disp('There are repetetive burst numbers in this cdf file!') disp('using the smallest...') handles.mydata.iburst = min(handles.mydata.iburst); end set(handles.slider2,'Value',cburst); % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in export_button. function export_button_Callback(hObject, eventdata, handles) % hObject handle to export_button (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % % create a netCDF file with just the burst cburst = handles.mydata.burstNum(handles.mydata.iburst); [pname, fname] = fileparts(name(handles.mydata.cdf)); newname = fullfile(pname,[fname '_' num2str(cburst) '.cdf']); if exist(newname,'file'), button = questdlg(sprintf('Do you want to overwrite %s?', newname),... 'Wanring!','No'); if strcmp(button,'No') | strcmp(button, 'Cancel'), return end end % create the file cdfe = netcdf(newname,'clobber'); % let the user add a comment answer = inputdlg('Enter a comment about this burst','Add metadata',1,{''}); cdfe.forensic_comment = answer{1}; % copy the global objects ncobj = att(handles.mydata.cdf); for n = 1:length(ncobj), copy(ncobj{n},cdfe); end % set up the dimensions ncobj = dim(handles.mydata.cdf); rdim = recdim(handles.mydata.cdf); for n = 1:length(ncobj), if strcmp(name(rdim),name(ncobj{n})), cdfe(name(rdim)) = 0; % make the record dimension else copy(ncobj{n},cdfe); end end % make empty variables ncobj = var(handles.mydata.cdf); for n = 1:length(ncobj), copy(ncobj{n},cdfe,0,1); % copy atts only end % populate variables with data ncobje = var(cdfe); for n = 1:length(ncobj), ncobje{n}(1,:,:) = ncobj{n}(handles.mydata.iburst,:,:); end % (handles.mydata.iburst,:,:) disp(sprintf('Burst %d copied to %s',cburst,newname)) close(cdfe)