⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waveleted.m

📁 基于matlab的反演程序,用于地球物理勘探中射线追踪及偏移成像程序.
💻 M
📖 第 1 页 / 共 3 页
字号:
 return;
end
%
% change the setting on a boolean flag menu item.
%
if( strcmp(action,'boolean') )
        %hthis = get(gcf,'currentmenu');
			hthis=gcbo;
        % get the current flag setting
        flag = get(hthis,'checked');
        % toggle it the other way
        if( strcmp(flag,'on') )
                set(hthis,'checked','off');
        else
                set(hthis,'checked','on');
        end

        return;

end

%
% set save options
%
if(strcmp(action,'saveopts'))
	h=get(gcf,'userdata');
 hsaveascii=h(6);
 hsaveobject=h(7);
 hsavecurrent=h(19);
 hsaveall=h(20);

 %hmenu= get(gcf,'currentmenu');
 hmenu=gcbo;
 state=get(hmenu,'checked');

	if( hmenu==hsaveascii)
		if(strcmp(state,'off')) %we turn it on
			set(hsaveascii,'checked','on');
			set(hsaveobject,'checked','off');
			set(hsaveall,'checked','off');
			set(hsavecurrent,'checked','on');
		else % turn it off
			set(hsaveascii,'checked','off');
			set(hsaveobject,'checked','on');
		end
 elseif( hmenu==hsaveobject )
		if(strcmp(state,'off')) %we turn it on
			set(hsaveascii,'checked','off');
			set(hsaveobject,'checked','on');
		else % turn it off
			set(hsaveascii,'checked','on');
			set(hsaveobject,'checked','off');
			set(hsaveall,'checked','off');
		end
 elseif(hmenu==hsavecurrent)
		if(strcmp(state,'off')) %we turn it on
			set(hsavecurrent,'checked','on');
			set(hsaveall,'checked','off');
		else %turn it off
			set(hsavecurrent,'checked','off');
			set(hsaveall,'checked','on');
			set(hsaveascii,'checked','off');
			set(hsaveobject,'checked','on');
		end
	elseif(hmenu==hsaveall)
		if(strcmp(state,'off')) %we turn it on
			set(hsavecurrent,'checked','off');
			set(hsaveall,'checked','on');
			set(hsaveascii,'checked','off');
			set(hsaveobject,'checked','on');
		else %turn it off
			set(hsavecurrent,'checked','on');
			set(hsaveall,'checked','off');
		end
	end

	return;

end

if(strcmp(action,'showsave'))
	h=get(gcf,'userdata');
    hquit=h(8);
    hmsg=h(14);

	%get the fileobj
	wlet=get(hquit,'userdata');
    fileobj=objget(wlet,'file');

	if( ~isempty(fileobj) )
		filename=objget(fileobj,'filename');
		pathname=objget(fileobj,'pathname');
	else
		filename= 'undefined';
		pathname='';
	end
	set(hmsg,'string',['Save file: ' pathname filename]);
	return;
end

if(strcmp(action,'save'))
    
    h=get(gcf,'userdata');
    hquit=h(8);
    hactive=h(13);
    hmsg=h(14);
    hsaveascii=h(6);
    hsaveobject=h(7);
    hsavecurrent=h(19);
    hsaveall=h(20);

    %get the savefile name

    wlet=get(hquit,'userdata');
    if isempty(wlet) 
       msgbox('No wavelets to save','Save error');
       return;
    end     
    fileobj=objget(wlet,'file');
		if( isempty(fileobj) )
				fileobj=contobj('file','prvt');
				filename='undefined';
				pathname=' ';
				fileobj=objset(fileobj,'filename',filename);
				fileobj=objset(fileobj,'pathname',pathname);
				wlet=objset(wlet,'file',fileobj);
				set(hquit,'userdata',wlet);
		end
    filename=objget(fileobj,'filename');
    pathname=objget(fileobj,'pathname');
    
    %determine the save options in effect
    saveobj=get(hsaveobject,'checked');
    if(strcmp(saveobj,'on'))
			saveobj=1;
    else
			saveobj=0;
	end
	
	saveall=get(hsaveall,'checked');
	if(strcmp(saveall,'on'))
		saveall=1;
	else
		saveall=0;
	end
	
	%see whether the save file is for ascii or object
	ind=findstr(filename,'.mat');
	if( isempty(ind) )
		asciifile=1;
	else
		asciifile=0;
	end

	%put up a file dialog if needed
	if (strcmp(filename,'undefined') || (saveobj && asciifile) ...
		| ~saveall | (~saveobj&~asciifile) )
        try
            % Next line can cause an error if we have never run this before
            lastOutputFile = getpref('waveleted','lastOutputFile');
        catch
            lastOutputFile = '';
        end
	    if( saveobj )
		    [filename,path]=myuifile(gcf,'*.mat','Output File Selection','put',lastOutputFile);
	    else
		    [filename,path]=myuifile(gcf,'*.dat','Output File Selection','put',lastOutputFile);
	    end

		if( isempty(filename) )
			set(hmsg,'string','Waveleted: Save aborted: no file name given');
			return;
		end
		if( filename==0)
			set(hmsg,'string','Waveleted: Save aborted');
			return;
		end

		%don't do this unles saving the entir object
		%update the fileobj
		if(saveall)
			fileobj=objset(fileobj,'filename',filename);
			fileobj=objset(fileobj,'pathname',pathname);

			wlet=objset(wlet,'file',fileobj);
			set(hquit,'userdata',wlet);
		end
        setpref('waveleted','lastOutputFile',fullfile(pathname,filename));
	end
 
	%active wavelet output
	if(~saveall)
		%get the current wavelet
		hmenu=get(hactive,'userdata');
		if( isempty(hmenu) )
			set(hmsg,'string','Save aborted: no active wavelet');
			return;
		end
		dat=get(hmenu,'userdata');
		t=get(dat(1),'xdata');
		t=t(:);
		w=get(dat(1),'ydata');
		w=w(:);
		name=get(hmenu,'label');

		ilive=find(~isnan(w));
		ilive2=find(~isnan(t(ilive)));
		w=w(ilive(ilive2));
		t=t(ilive(ilive2));

		%ascii file output
		if( ~saveobj )
			%form the full filename
			ind=findstr(filename,'.mat');
			if( ~isempty(ind) )
				set(hmsg,'string','ASCII Save aborted: filename cannot end in .mat');
				return;
			end

			ind=findstr(filename,'.dat');
			if(strcmp(computer,'MAC2'))
				fullfilename=filename(1:ind(1)-1);
			else
				fullfilename=[path filename(1:ind(1)-1)];
			end

			%write it out - t appears first, then (with no warning) w
			%appears below
			saveascii(fullfilename,t,w);

			set(hmsg,'string',['Save successful to ' fullfilename]);

			return;
		else
			%form the full filename
			%ind=findstr(filename,'.mat');
			%if( isempty(ind) )
			%	set(hmsg,'string','Object Save aborted: filename must end in .mat');
			%	return;
			%end
            ind=findstr(filename,'.mat');
		    if( isempty(ind) )
			    ind=length(filename)+1;
		    end
            
			if(strcmp(computer,'MAC2'))
				fullfilename=filename(1:ind(1)-1);
			else
				fullfilename=[path filename(1:ind(1)-1)];
			end

			%make a new wavelet object and put the current wavelet in it
			wavelets=contobj('Waveleted Output','wlet');
			fmw=fmset([],1,t,w);
			wavelets=objset(wavelets,'wavelets',fmw);
			wavelets=objset(wavelets,'wavelet_names',name);
			fileobj=contobj('file','prvt');
			fileobj=objset(fileobj,'filename',filename);
			fileobj=objset(fileobj,'pathname',pathname);
			wavelets=objset(wavelets,'file',fileobj);

			%write it out
			%eval([filename(1:ind(1)-1) '=newobj;']);

			%eval(['save ' fullfilename ' ' filename(1:ind(1)-1)]);
			save(fullfilename,'wavelets');

			set(hmsg,'string',['Save successful to ' fullfilename]);

			return;
		end
    else %output the entire wavelet object
		%form the full filename
		ind=findstr(filename,'.mat');
		if( isempty(ind) )
			ind=length(filename)+1;
		end

		if(strcmp(computer,'MAC2'))
			fullfilename=filename(1:ind(1)-1);
		else
			fullfilename=[path filename(1:ind(1)-1)];
		end

		%get the object
		obj=get(hquit,'userdata');


		%write it out
		%eval([filename(1:ind(1)-1) '=obj;']);
		wavelets=obj;

		%eval(['save ' fullfilename ' ' filename(1:ind(1)-1)]);
		%eval(['save ' fullfilename '  wavelets']);
		save(fullfilename,'wavelets');

		set(hmsg,'string',['Save successful to ' fullfilename '.mat']);

		return;
	
	end

	return;

end

if(strcmp(action,'open')|strcmp(action,'open2'))
	h=get(gcf,'userdata');
	hxmit=h(4);
 hquit=h(8);
 hactive=h(13);
 hmsg=h(14);
 hsaveascii=h(6);
 hsaveobject=h(7);
 hsavecurrent=h(19);
 hsaveall=h(20);

 %see is we have an object on the go
 obj=get(hquit,'userdata');
 if( ~isempty(obj) & strcmp(action,'open') )
		yesnoinit('waveleted(''open2'')','Save first?');
		return;
	end

	a=yesnofini;
	if( ~isempty(a) )
	   if(a==-1) %cancel
		set(hmsg,'string','Open cancelled');
		return;
	   elseif(a==1) %save
		%hsaveall=get(gcf,'currentmenu');
		hsaveall=gcbo;
		waveleted('saveopts');
		waveleted('save');
	   end
	end

	%put up the load file dialog
	[filename,path] = uigetfile('*.mat','Select Saved Wavelet File');

		if( isempty(filename) )
			set(hmsg,'string','Open failed: no file name given');
			error('no file name given');
		end
		if( filename==0 )
			set(hmsg,'string','Open failed: no file name given');
			error(' no file name given');
		end

		ind=findstr(filename,'.mat');
		if( length(ind)>0 )
			 filename=filename(1:ind-1);
		else
			set(hmsg,'string','Open failed: invalid file extension');
			disp('Selected file must be a wavelets file saved by WAVELETED');
			disp('and it must have a .mat extension on the file name');
			disp('To import a wavelet in GMA or SEGY formats, use the ''New Wavelet''');
			disp('command and select wavelet type to indicate the appropriate');
			disp('import file');
			error(' invalid file extension');
		end

		fullfilename = [path filename];

		% load the file

		if( strcmp(computer,'MAC2') )
			%eval(['load ' filename]);
			load(filename);
		else
			%eval(['load ' fullfilename]);
			load(fullfilename);
		end

		%re below: The wavelets structure is supposed to be in a variable with the same name as the file name
		% This is stupid, because if the user renames the file, the system is broken. I will modify Waveleted to put
		% the variable name as wavelets but leave the old code intact for legacy purposes

%  		if( exist(filename) ==1) 
%  		   %copy it into wlet
% 		    eval(['wlet=' filename ';']);
% 		    eval([filename '=[];']);
% 		elseif( exist('wavelets')==1)
%		    wlet=wavelets;
% 		else
%  			set(hmsg,'string','Invalid wavelets file');
%  			disp('Selected file must be a wavelets file saved by WAVELETED');
%             disp('and it must have a .mat extension on the file name');
% 			disp('To import a wavelet in GMA or SEGY formats, use the ''New Wavelet''');
% 			disp('command and select wavelet type to indicate the appropriate');
% 			disp('import file');
% 			error('#1   invalid wavelet file ');
% 	    end


		%test for earth object
		if(~isearthobj(wavelets))
			set(hmsg,'string','Invalid wavelets file');
			disp('Selected file must be a wavelets file saved by WAVELETED');
			disp('and it must have a .mat extension on the file name');
			disp('To import a wavelet in GMA or SEGY formats, use the ''New Wavelet''');
			disp('command and select wavelet type to indicate the appropriate');
			disp('import file');
			error('#2  invalid wavelet file ');
		end
		wn=objget(wavelets,'wavelet_names');
		if( isempty(wn) )
			set(hmsg,'string','Invalid wavelets file');
			disp('Selected file must be a wavelets file saved by WAVELETED');
			disp('and it must have a .mat extension on the file name');
			disp('To import a wavelet in GMA or SEGY formats, use the ''New Wavelet''');
			disp('command and select wavelet type to indicate the appropriate');
			disp('import file');
			error('#3  invalid wavelet file ');
		end

		%see if we have a master figure in control
		dat=get(hxmit,'userdata');
		transfer=get(hsaveascii,'userdata');
		if(length(dat)>1)
			hmasterfig=dat(2);
		else
			hmasterfig=0;
		end

		%clear the figure
		close(gcf);

		%reinitialize
		if(hmasterfig)
			waveleted(wavelets,hmasterfig,transfer);
		else
			waveleted(wavelets); 
		end

		return;

	end

	if( strcmp(action,'xmit'))
		h=get(gcf,'userdata');
		hxmit=h(4);
        hsaveascii=h(6);
		hquit=h(8);
		hmsg=h(14);

		%get the wavelet object
		wlet=get(hquit,'userdata');

		%get the transfer function
		transfer=get(hsaveascii,'userdata');
		if( isempty(transfer) )
			set(hmsg,'string','XMIT failed: invalid transfer function');
			error('XMIT failed: invalid transfer function');
		end

		%get the master figure
		dat=get(hxmit,'userdata');
		hmasterfig=dat(2);

		hfigs=figs;
		ind=find(hfigs==hmasterfig);

		if( isempty(ind) )
			set(hmsg,'string','XMIT failed: invalid master figure');
			error('XMIT failed: invalid master figure');
		end

		set(hmsg,'string',['Wavelets transferred to ' transfer]);

		figure(hmasterfig);

		%form the transfer string and evaluate
		eval([transfer '(''wavelets'',wlet)']);

		return;

	end

function positionWindow(hfig,appname,windowname,xsize,ysize)
    % Attempt to use the last window size and position.
    % If the last window size and position are rediculous, just plonk the
    % window in the middle of the screen at the specified size in pixels.
    prevunits = get(0,'units');
    set(0,'units','pixels');
    s = get(0,'screensize');
    set(0,'units',prevunits);
    skipprefs = false;
    try 
        p = getpref(appname,[windowname  'windowposition']);
        beyondTopOrRight = any([p(1) p(2) + p(4)] > s(3:4));
        beyondBottomOrLeft = any(p(1:2) < s(1:2));
        tooSmall = any(p(3:4) < 100);
        if  beyondTopOrRight || beyondBottomOrLeft  || tooSmall
            skipprefs = true;
        end
    catch
        skipprefs = true;
    end
        
    if skipprefs
         p = [(s(3)-xsize)/2 (s(4)-ysize)/2 xsize ysize];    
    end

    prevunits = get(hfig,'units');   
    set(hfig,'position',p);
    set(0,'units',prevunits);

    
function saveWindowPosition(hfig,appname,windowname)
    prevunits = get(hfig,'units');
    set(hfig,'units','pixels');
    p = get(gcf,'position');
    setpref(appname,[windowname 'windowposition'],p);
    set(hfig,'units',prevunits);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -