www.pudn.com > wavelets.rar > waveletchange.m, change:2004-08-13,size:15753b


function waveletchange(action,htestfig)  % The WAVELETCHANGE dialog is initiated by calling WAVELETCHANGEINIT which % then calls WAVELETCHANGE. With one exception, WAVELETCHANGE is never called % directly from another program. Tha exception is when another program has % a figure handle that may be a legitimate WAVELETCHANGE window or not. % Calling waveletchange('test',figurehandle) will return 1 if it is a legit % change window and zero otherwise. % % G.F. Margrave, March 1994 % % NOTE: It is illegal for you to use this software for a purpose other % than non-profit education or research UNLESS you are employed by a CREWES % Project sponsor. By using this software, you are agreeing to the terms % detailed in this software's Matlab source file.   % BEGIN TERMS OF USE LICENSE % % This SOFTWARE is maintained by the CREWES Project at the Department % of Geology and Geophysics of the University of Calgary, Calgary, % Alberta, Canada.  The copyright and ownership is jointly held by  % its author (identified above) and the CREWES Project.  The CREWES  % project may be contacted via email at:  crewesinfo@crewes.org %  % The term 'SOFTWARE' refers to the Matlab source code, translations to % any other computer language, or object code % % Terms of use of this SOFTWARE % % 1) Use of this SOFTWARE by any for-profit commercial organization is %    expressly forbidden unless said organization is a CREWES Project %    Sponsor. % % 2) A CREWES Project sponsor may use this SOFTWARE under the terms of the  %    CREWES Project Sponsorship agreement. % % 3) A student or employee of a non-profit educational institution may  %    use this SOFTWARE subject to the following terms and conditions: %    - this SOFTWARE is for teaching or research purposes only. %    - this SOFTWARE may be distributed to other students or researchers  %      provided that these license terms are included. %    - reselling the SOFTWARE, or including it or any portion of it, in any %      software that will be resold is expressly forbidden. %    - transfering the SOFTWARE in any form to a commercial firm or any  %      other for-profit organization is expressly forbidden. % % END TERMS OF USE LICENSE  figflag=[];  % userdata assignments % % Figure userdata: %		set(gcf,'userdata',[htitle himpname houtlabel  houtname hchangelabel ... %			hchangeaction hstablabel hstab hphslabel hphs ... %			hsurflbl hsurf htminlabel htmin htmaxlabel ... %			htmax hinvlenlbl hinvlen  hwinlabel hwindow ... %			hdelaylbl hghost hdone hcancel]); % % all unused except: % htitle ... [w nan tw] % himpname ... the rowvec flag % hdone ... the transfer function % hcancel ... the handle of the master figure % if(strcmp(action,'init'))  		% get the input information 		stuff=get(gca,'userdata'); 		ind=find(isnan(stuff)); 		if( isempty(ind) ) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 			transfer=[]; 			name=''; 			rowvec=[]; 			w=[]; 			tw=[]; 			hfigmaster=[]; 			 		else	 		 			transfer=stuff(1:ind(1)-1); 			name=setstr( stuff(ind(1)+1:ind(2)-1) ); 			rowvec=stuff(ind(2)+1); 			w=stuff(ind(3)+1:ind(4)-1); 			tw=stuff(ind(4)+1:ind(5)-1); 			hfigmaster=stuff(ind(5)+1); 		end  		%get the new figure 		hfig=gcf; 		set(gca,'visible','off'); 		geom=get(hfig,'position'); 		figwidth=402; 		figheight=160; 		geom=[geom(1:2) figwidth figheight];  		% the title/msg bar  		sep=1; 		xnow=sep; 		width=figwidth-2*sep; 		height=20; 		ynow=figheight-height-sep; 		htitle=uicontrol('style','text','string','Wavelet Change Panel',... 			'position',[xnow,ynow,width,height],'userdata',[w nan tw]);  		ynow=ynow-height-sep; 		if(isempty(name)) 			str='Input wavelet name not given'; 		else 			str=['Input wavelet name: ' name]; 		end 		himpname=uicontrol('style','text','string',str,'position',... 			[xnow,ynow,width,height],'userdata',rowvec);  		ynow=ynow-height-sep;  		width=150; 		houtlabel=uicontrol('style','text','string','Output wavelet name:',... 			'position',[xnow,ynow,width,height]);  		xnow=xnow+width+sep; 		width=figwidth-width-3*sep; 		houtname=uicontrol('style','edit','string',name,'position',... 			[xnow,ynow,width,height]);  		ynow=ynow-height-sep; 		xnow=sep; 		width=150; 		hchangelabel=uicontrol('style','text','string','Change Action->',... 			'position',[xnow,ynow,width,height]);  		xnow=xnow+width+sep; 		width=figwidth-width-3*sep; 		chgstr='To minimum phase|To zero phase|To all pass|To causal inverse|'; 		chgstr=[chgstr 'To general inverse|Time reverse|Window|Phase rotate|Ghost']; 		chgstr=[chgstr '|Normalize']; 		hchangeaction=uicontrol('style','popupmenu','string',chgstr,... 			'position',[xnow,ynow,width,height],'callback',... 			'waveletchange(''setaction'')');  		xnow=sep; 		ynow=ynow-sep-height; 		width=100; 		hstablabel=uicontrol('style','text','string','Stab factor:',... 			'position',[xnow,ynow,width,height],'visible','on');  		xnow=xnow+width+sep; 		hstab=uicontrol('style','edit','string','.0001','position',... 			[xnow,ynow,width,height],'visible','on');  		xnow=sep; 		width=200; 		hphslabel=uicontrol('style','text','string','Phase angle (degrees):',... 			'position',[xnow,ynow,width,height],'visible','off'); 		xnow=xnow+width+sep; 		hphs=uicontrol('style','edit','string','-90','position',... 			[xnow,ynow,width,height],'visible','off');  		xnow=sep; 		width=150; 		hsurflbl=uicontrol('style','text','string','Surface rc:',... 			'position',[xnow,ynow,width,height],'visible','off'); 		xnow=xnow+width+sep; 		hsurf=uicontrol('style','edit','string','-1','position',... 			[xnow,ynow,width,height],'visible','off');  		xnow=sep; 		width=99; 	   htminlabel=uicontrol('style','text','string','Tmin (sec):','position',... 			[xnow,ynow,width,height],'visible','off'); 		xnow=xnow+width+sep; 		htmin=1;htmax=1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 		if( ~isempty(tw) ) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 		htmin=uicontrol('style','edit','string',num2str(tw(1)),'position',... 			[xnow,ynow,width,height],'visible','off'); 		end  		xnow=xnow+width+sep; 		width=99; 	   htmaxlabel=uicontrol('style','text','string','Tmax (sec):','position',... 			[xnow,ynow,width,height],'visible','off'); 		xnow=xnow+width+sep; 		if( ~isempty(tw) ) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 		htmax=uicontrol('style','edit','string',num2str(tw(length(tw))),... 			'position',[xnow,ynow,width,height],'visible','off'); 		end 		xnow=sep; 		ynow=ynow-height-sep; 		width=200; 		hinvlenlbl=uicontrol('style','text','string','Inverse wavelet length (sec)',... 			'position',[xnow,ynow,width,height],'visible','off');  		xnow=xnow+width+sep; 		width=80; 		hinvlen=uicontrol('style','edit','string','.2','position',... 			[xnow,ynow,width,height],'visible','off');  		xnow=sep; 		width=120; 		hwinlabel=uicontrol('style','text','string','Window Type->',... 			'position',[xnow,ynow,width,height],'visible','off'); 		xnow=xnow+width+sep; 		width=150; 		hwindow=uicontrol('style','popupmenu','string',... 			'Cosine-box|Hanning|Hamming|Boxcar','position',[xnow,ynow,width,height],... 			'visible','off');  		xnow=sep; 		width=200; 		hdelaylbl=uicontrol('style','text','string','Ghost delay (2-way in sec)',... 			'position',[xnow,ynow,width,height],'visible','off');  		xnow=xnow+width+sep; 		width=100; 		hghost=uicontrol('style','edit','string','.010','position',... 			[xnow,ynow,width,height],'visible','off');  		% now a done and cancel button 		xnow=sep; 		width=80; 		ynow=ynow-height-sep; 		hdone=uicontrol('style','pushbutton','string','Done','position',... 			[xnow,ynow,width,height],'callback','waveletchange(''done'')',... 			'userdata',transfer); 		xnow=xnow+width+sep; 		hcancel=uicontrol('style','pushbutton','string','Cancel','position',... 			[xnow,ynow,width,height],'callback','waveletchange(''cancel'')',... 			'userdata',hfigmaster);  		set(gcf,'userdata',[htitle himpname houtlabel  houtname hchangelabel ... 			hchangeaction hstablabel hstab hphslabel hphs ... 			hsurflbl hsurf htminlabel htmin htmaxlabel ... 			htmax hinvlenlbl hinvlen  hwinlabel hwindow ... 			hdelaylbl hghost hdone hcancel]);  		ind=find(geom<0); 		if(~isempty(ind)) 			geom(ind)=zeros(size(ind)); 		end 		set(gcf,'position',geom); 		set(gcf,'visible','on'); 		return  	end  if(strcmp(action,'setaction')) 	h=get(gcf,'userdata'); 	htitle=h(1); 	himpname=h(2); 	houtlabel=h(3); 	houtname=h(4); 	hchangelabel=h(5); 	hchangeaction=h(6); 	hstablabel=h(7); 	hstab=h(8); 	hphslabel=h(9); 	hphs=h(10); 	hsurflbl=h(11); 	hsurf=h(12); 	htminlabel=h(13); 	htmin=h(14); 	htmaxlabel=h(15); 	htmax=h(16); 	hinvlenlbl=h(17); 	hinvlen=h(18); 	hwinlbl=h(19); 	hwindow=h(20); 	hdelaylbl=h(21); 	hghost=h(22); 		 	%determine which action has been selected 	flag=get(hchangeaction,'value');  	% set everything off 	set(hstablabel,'visible','off'); 	set(hstab,'visible','off'); 	set(hphslabel,'visible','off'); 	set(hphs,'visible','off'); 	set(hsurflbl,'visible','off'); 	set(hsurf,'visible','off'); 	set(htminlabel,'visible','off'); 	set(htmin,'visible','off'); 	set(htmaxlabel,'visible','off'); 	set(htmax,'visible','off'); 	set(hinvlenlbl,'visible','off'); 	set(hinvlen,'visible','off'); 	set(hwinlbl,'visible','off'); 	set(hwindow,'visible','off'); 	set(hdelaylbl,'visible','off'); 	set(hghost,'visible','off');  % turn on stuff for min phase 	if(flag==1 | flag == 3 | flag==4 |flag==5) 		set(hstablabel,'visible','on'); 		set(hstab,'visible','on'); 	end  	if( flag == 8) 		set(hphslabel,'visible','on'); 		set(hphs,'visible','on'); 	end  	if(flag == 9) 		set(hsurflbl,'visible','on'); 		set(hsurf,'visible','on'); 		set(hdelaylbl,'visible','on'); 		set(hghost,'visible','on'); 	end  	if(flag == 7) 		set(htminlabel,'visible','on'); 		set(htmin,'visible','on'); 		set(htmaxlabel,'visible','on'); 		set(htmax,'visible','on'); 		set(hwinlbl,'visible','on'); 		set(hwindow,'visible','on'); 	end  	if(flag==4|flag==5) 		set(hinvlenlbl,'visible','on'); 		set(hinvlen,'visible','on'); 	end  	return;  end 		 if(strcmp(action,'done')) 	h=get(gcf,'userdata'); 	htitle=h(1); 	himpname=h(2); 	houtlabel=h(3); 	houtname=h(4); 	hchangelabel=h(5); 	hchangeaction=h(6); 	hstablabel=h(7); 	hstab=h(8); 	hphslabel=h(9); 	hphs=h(10); 	hsurflbl=h(11); 	hsurf=h(12); 	htminlabel=h(13); 	htmin=h(14); 	htmaxlabel=h(15); 	htmax=h(16); 	hinvlenlbl=h(17); 	hinvlen=h(18); 	hwinlbl=h(19); 	hwindow=h(20); 	hdelaylbl=h(21); 	hghost=h(22); 	hdone=h(23); 	hcancel=h(24);  	%make sure a name has been provided 	name=get(houtname,'string'); 	if(~isempty(name)) 		inotblank=find(abs(name)~=32); 		if(isempty(name(inotblank))) 			set(htitle,'string','Please provide an output wavelet name'); 			return; 		end 	else 			set(htitle,'string','Please provide an output wavelet name'); 			return; 	end  	%get the wavelet and tw 	ww=get(htitle,'userdata'); 	ind=find(isnan(ww)); 	w=ww(1:ind(1)-1); 	tw=ww(ind(1)+1:length(ww));  	%see what the action is 	flag=get(hchangeaction,'value');  	%get the stab factor 	if( flag==1 | flag==3 | flag ==4 | flag ==5 ) 		stab=get(hstab,'string'); 		stab=sscanf(stab,'%f'); 		if(isempty(stab)) 			set(htitle,'string','Invalid stab factor. Must be NUMERIC between 0 & 1'); 			return; 		end 		if(stab<0 | stab > 1.0) 			set(htitle,'string','Invalid stab factor. Must be between 0 & 1'); 			return; 		end 	end  	% get the inverse wavelet length 	if( flag==4 | flag ==5 ) 		tinv=get(hinvlen,'string'); 		tinv=sscanf(tinv,'%f'); 		if(isempty(tinv)) 			set(htitle,'string',... 				'Invalid inverse wavelet length. Must be NUMERIC between 0 & 2'); 			return; 		end 		if( tinv<0 | tinv > 2.0) 			set(htitle,'string',... 				'Invalid inverse wavelet length. Must be between 0 & 2'); 			return; 		end 	end  	% get tmin and tmax 	if(flag==7) 		tmin=get(htmin,'string'); 		tmin=sscanf(tmin,'%f'); 		tmax=get(htmax,'string'); 		tmax=sscanf(tmax,'%f'); 		if(isempty(tmin) | isempty(tmax)) 			set(htitle,'string',... 				'Tmin and Tmax must be NUMERIC'); 			return; 		end 		if(tmin>=tmax) 			set(htitle,'string',... 				'Tmin must be less than Tmax'); 			return; 		end 	end  	%get the constant phase 	if( flag==8 ) 		phs=get(hphs,'string'); 		phs=sscanf(phs,'%f'); 		if( phs<-180 | phs>180) 			set(htitle,'string',... 				'Invalid phase rotation. Must be NUMERIC between -180 & +180'); 			return; 		end 		if(phs<-180 | phs>180) 			set(htitle,'string',... 				'Invalid phase rotation. Must be between -180 & +180'); 			return; 		end 	end  	%get the near surface rc 	if( flag==9 ) 		rc=get(hsurf,'string'); 		rc=sscanf(rc,'%f'); 		if(rc<-1 | rc>1) 			set(htitle,'string',... 				'Invalid reflection coeficient. Must be between -1 & +1'); 			return; 		end 		if(isempty(rc)) 			set(htitle,'string',... 				'Invalid reflection coeficient. Must be NUMERIC between -1 & +1'); 			return; 		end 	end  	%get the near delay rc 	if( flag==9 ) 		tdelay=get(hghost,'string'); 		tdelay=sscanf(tdelay,'%f'); 		if( tdelay<0 | tdelay>2.0) 			set(htitle,'string',... 				'Invalid ghost delay. Must be between 0 & +2'); 			return; 		end 		if(isempty(tdelay)) 			set(htitle,'string',... 				'Invalid ghost delay. Must be NUMERIC between 0 & +2'); 			return; 		end 	end  	%ok now make the new wavelet 	if( flag==1) 		wnew=tomin(w,stab); 		twnew=xcoord(0.,tw(2)-tw(1),wnew); 	elseif(flag==2) 		[wnew,twnew]=tozero(w,tw); 	elseif(flag==3) 		[wnew,twnew]=toall(w,tw,stab); 	elseif(flag==4) 		n=tinv/(tw(2)-tw(1))+1; 		wnew=toinv(w,stab,n); 		twnew=xcoord(0,tw(2)-tw(1),wnew); 	elseif(flag==5) 		n=tinv/(tw(2)-tw(1))+1; 		wnew=toinvf(w,stab,n); 		twnew=xcoord(-tw(length(tw))/2,tw(2)-tw(1),wnew); 	elseif(flag==6) 		wnew=tr(w,1); 		twnew=tw; 	elseif(flag==7) 		% use tmin & tmax to window &/or pad 		dt=tw(2)-tw(1); 		if(tmin<tw(1)) 			n=round((tmin-tw(1))/dt); 			w=[zeros(1,n) w]; 			tw=xcoord(tw(1)-n*dt,dt,w); 		else 			n=near(tw,tmin); 			w=w(n:length(w)); 			tw=tw(n:length(tw)); 		end 		if(tmax>tw(length(tw))) 			n=round((tmax-tw(length(tw)))/dt); 			w=[w zeros(1,n)]; 			tw=xcoord(tw(1),dt,w); 		else 			n=near(tw,tmax); 			w=w(1:n); 			tw=tw(1:n); 		end 		% determine the window 		winflag=get(hwindow,'value'); 		if(winflag==1) 			win=mwindow(w,20); 		elseif(winflag==2) 			win=hanning(length(w)); 		elseif(winflag==3) 			win=hamming(length(w)); 		elseif(winflag==4) 			win=ones(size(w)); 		end 			 		wnew=(w(:).*win(:))'; 		twnew=tw; 	elseif(flag==8) 		wnew=phsrot(w,phs); 		twnew=tw; 	elseif(flag==9) 		if(tdelay>0) 			%make the ghost rc series 			dt=tw(2)-tw(1); 			n=round(tdelay/dt)+1; 			dtg=tdelay/(n-1); 			rcg=zeros(1,length(tw)+n+1); 			rcg(1)=1; 			rcg(n)=rc; 			tg=xcoord(0,dtg,rcg); 			%resample 			[rcg,tg]=resamp(rcg,tg,dt); 		else 			rcg=zeros(1,length(tw)+1); 			rcg(1)=1; 		end  		%convolve 		nzero=near(tw,0.); 		wnew=convz(rcg,w,nzero); 		twnew=xcoord(tw(1),dt,wnew); 	elseif(flag==10) 		wnew=wavenorm(w,1); 		twnew=tw; 	end  % % htitle ... [w nan tw] % himpname ... the rowvec flag % hdone ... the transfer function % hcancel ... the handle of the master figure % % get the other things 	transfer=setstr(get(hdone,'userdata')); 	hmasterfig=get(hcancel,'userdata'); 	rowvec=get(himpname,'userdata'); 		 	% put the answer in the userdata of the axes of the master figure 	if(~isempty(hmasterfig)) 		hax=get(hmasterfig,'currentaxes'); 	else 		hax=gca; 	end  	set(hax,'userdata',[wnew nan twnew nan abs(name) nan rowvec]);  	close(gcf);  	%call the transfer function  	eval(transfer);  	return;  end  if(strcmp(action,'cancel')) 	h=get(gcf,'userdata'); 	hdone=h(23); 	hcancel=h(24); 	transfer=setstr(get(hdone,'userdata')); 	hmasterfig=get(hcancel,'userdata'); 	% put the answer in the userdata of the axes of the master figure 	if(~isempty(hmasterfig)) 		hax=get(hmasterfig,'currentaxes'); 	else 		hax=gca; 	end  	set(hax,'userdata',-1); 	close(gcf);  	%call the transfer function  	eval(transfer);  	return; end