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

📄 matinterogator.m

📁 基于matlab的反演程序,用于地球物理勘探中射线追踪及偏移成像程序.
💻 M
📖 第 1 页 / 共 2 页
字号:
function DataOut=matinterogator(OpenFile,n,arg3)
%----------------------------------------
%--------- Mat File Interogator --------- 
%----------------------------------------
%
% DataOut=matinerogator;
% DataOut=matinerogator(OpenFile);
% DataOut=matinerogator(OpenFile,n);
%           - arg3 is for program use only
%
% MATINTEROGATOR will display the initial arrays in a .mat file (maximum of
% 40).  Initializing MATINTEROGATOR in the command window will simply pop
% up a selection window for users to choose the .mat file they want to
% interogate.  DataOut will be released when at least one array is choosen
% for export or if MATINTEROGATOR is canceled or closed.  
%
% OpenFile  - The desired file that the user wants to interogate.
%    n      - User specified maximum number of arrays to be choosen and
%           exported.  Defaulted to max 40.
% 
% C.B. Harrison 2002
%
% 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.

if(nargin<1)
    action='init';
    n=[40];
    OpenFile='';
    arg3='';
elseif(nargin==1)
    action='init';
    n=[40];
    arg3='';
elseif(nargin==2)
    action='init';
    n=round(n);
    if(n>=41)
        n=40;
    end
    arg3='';
elseif(nargin==3)
    action='init';
    if(~isnumeric(n))
        n=[40];
    else
        n=round(n);
        if(n>=41)
            n=40;
        end
    end
end
if strcmp(action,'init')
    if(isempty(arg3))
        if(isempty(deblank(OpenFile)))
            [file,path]=myuifile(gcf,'.mat','Choose .mat file','get');
            if(isempty(file))
                return
            end
            OpenFile=[path file];
            if(size(OpenFile,2)<=3)|(~findstr(OpenFile(end-3:end),'.mat'))
                errordlg('Please Chose A .mat File To Interogate');
                return
            end        
        end
    end
    % must make names of number due to matinterogator using eval
    numnames={'One' 'Two' 'Three' 'Four' 'Five' 'Six' 'Seven' 'Eight',...
            'Nine' 'Ten' 'Eleven' 'Twelve' 'Thirteen' 'Fourteen' 'Fifteen',...
            'Sixteen' 'Seventeen' 'Eighteen' 'Nineteen' 'Twenty',...
            'TwentyOne' 'TwentyTwo' 'TwentyThree' 'TwentyFour' 'TwentyFive',...
            'TwentySix' 'TwentySeven' 'TwentyEight' 'TwentyNine' 'Thirty',...
            'ThirtyOne' 'ThirtyTwo' 'ThirtyThree' 'ThirtyFour' 'ThirtyFive',...
            'ThirtySix' 'ThirtySeven' 'ThirtyEight' 'ThirtyNine' 'Forty'};
    if(isempty(deblank(arg3)))
        try
            CheckFile=load(OpenFile);
        catch
            stringinfo=['Can Not Load: ' OpenFile];
            errordlg(stringinfo);
            return
        end
        FNames=fieldnames(CheckFile);
        nm=['Mat File Interogator ' OpenFile];
    else
        if(iscell(OpenFile))
            FNames=cell(1,size(OpenFile,1)*size(OpenFile,2));
            kk=1;
            for ii=1:size(OpenFile,1)
                for jj=1:size(OpenFile,2)
                    FNames{kk}=numnames{kk};
                    kk=kk+1;
                end
            end
            CheckFile=OpenFile;
        elseif(isstruct(OpenFile))
            if(size(OpenFile,2)>=2)
                % strucut has more then one field
                FNames=cell(1,size(OpenFile,2));
                for ii=1:size(OpenFile,2)
                    FNames{ii}=numnames{ii};
                end
            else
                FNames=fieldnames(OpenFile);
            end
            CheckFile=OpenFile;
        end
        nm=['Interogator'];
    end
    narray=length(FNames);
    nwidth=80;
    for ii=1:narray
        if(50*ceil(length(FNames{ii})/10)>=80)
            nwidth=50*ceil(length(FNames{ii})/10);
        end
    end
    FigYSize=narray*20+90;
    FigXSize=nwidth+230;
    milite=figcent(FigXSize,FigYSize,'pixels');
    set(milite,'menubar','none','Name',nm,...
        'closerequestfcn',@CloseMatInterogator,'tag','matinterogator',...
        'visible','on','numbertitle','off');
    set(gca,'position',[0 0 .0001 .00001],'visible','off');
    CUnits='Pixels';
    % Control Titles of info given out by matinterogator
    hmsg=uicontrol('style','text','units',CUnits,'position',[0 FigYSize-20 FigXSize 20],...
        'string','Choose or Export Desired Files','backgroundcolor',[1 1 1]);
    hm1=uicontrol('style','text','units',CUnits,'position',[40 FigYSize-40 nwidth 15],...
        'string','Name');
    hm1=uicontrol('style','text','units',CUnits,'position',[50+nwidth FigYSize-40 80 15],...
        'string','Size');
    hm1=uicontrol('style','text','units',CUnits,'position',[140+nwidth FigYSize-40 80 15],...
        'string','Class');
    % building controls for mat file selections
    AllCheck=[];
    for ii=1:narray
        col={[.7 .7 .7] [1 1 1]};
        if(((ii/2)-round(ii/2))==0)
            jj=1;
        else
            jj=2;
        end
        hname=uicontrol('string',FNames{ii},'position',[40 FigYSize-40-20*ii nwidth 15],...
            'backgroundcolor',col{jj},'style','pushbutton','callback',@renamearray,...
            'tooltipstring','Press To Rename Array');
        if(isstruct(CheckFile))
            if(size(CheckFile,2)>=2)
                dat=CheckFile(ii);
            else
                dat=getfield(CheckFile,FNames{ii});
            end
        else
            dat=CheckFile{ii};
        end
        sz=[num2str(size(dat,1)) 'x' num2str(size(dat,2))];
        hsize=uicontrol('string',sz,'position',[50+nwidth FigYSize-40-20*ii 80 15],...
            'backgroundcolor',col{jj},'style','text');
        cl=class(dat);
        hclass=uicontrol('string',cl,'position',[140+nwidth FigYSize-40-20*ii 80 15],...
            'backgroundcolor',col{jj},'style','pushbutton','callback',@inspectarray,...
            'tooltipstring','Press To Inspect Array');
        hclick=uicontrol('style','radiobutton','position',[0 FigYSize-40-20*ii 30 15],...
            'backgroundcolor',col{jj},'callback',@HighLightButton,...
            'tooltipstring','Press To Select Array For Export');
        set(hname,'userdata',{dat hname hsize hclass}); 
        set(hsize,'userdata',{dat hname hsize hclass});
        set(hclass,'userdata',{dat hname hsize hclass});
        set(hclick,'userdata',[hclick hname hsize hclass]);
        AllCheck=[AllCheck; hclick];
    end
    % Control Buttons
    hexport=uicontrol('string','Choose','callback',@ExportFiles,'position',[0 0 80 25],...
        'userdata',{gcf n 0 [] {}});
    hb=uicontrol('string','Close','callback',@CloseMatInterogator,'position',[90 0 80 25]);
    % holding till user has closed or continued
    hb=uicontrol('string','Save','callback',@ExportFiles,'position',[180 0 80 25]);
    set(gcf,'userdata',{hmsg AllCheck {} hexport});
end
uiwait(gcf);
if(~ishandle(gcf))
else
    h=get(milite,'userdata');
    hexport=h{end};
    dat=get(hexport,'userdata');
    dat=dat{end};
    if(isempty(dat))
        DataOut={};
    else
        ndat=dat{1};
        ddat=dat{2};
        for ii=1:size(ndat,1)
            makestruct=['DataOut.' ndat{ii} '=ddat{ii};'];
            eval(makestruct);
        end
    end
    delete(gcf);
end

% RENAMEING THE ARRAYS
%----------------------
function renamearray(hObject, eventdata, handles)
h=get(gcf,'userdata');
hmsg=h{1};
hhandles=h{2};
hbut=gco;
nm=get(hbut,'string');
masterfig=gcf;
qst={'Please Type A New Name'};
a={nm};
flags=[1];
set(hmsg,'string','Change Name Of Array','backgroundcolor',[1 1 1]);
titlestr=['Choose A New Name For The Array.  Name Can Not Be Numeric or Contain Special Characters'];
ttstr={'Press Cancel To Quit Renameing'};
ansfini=askthingsle(masterfig,qst,a,flags,titlestr,ttstr);
if(isempty(ansfini))
    set(hmsg,'string','Action Canceled','backgroundcolor',[1 1 1]);
    return
else
    nm=deblank(ansfini{1});
    % due to matinterogator using "eval" to save fils in strut format, the
    % following characters can no be used as or parts of names of Arrays
    checkchar={'[' ']' '(' ')' '{' '}' '=' '.'  ',' ';' '%' '!',...
            '+' '-' '*' '/' '\' '^' '<' '>' '=' '~' '&' '|' '@',...
            '#' '$' '`' ':' '"'};
    for ii=1:length(checkchar)
        if(~isempty(findstr(checkchar{ii},nm)))
            stringinfo=['Can Not Use "' checkchar{ii} '" In Name'];
            set(hmsg,'string',stringinfo,'backgroundcolor',[1 1 0]);
            return
        end
    end
    if(~isempty(str2num(deblank(ansfini{1}))))
        % will not allow user to change name to a number
        stringinfo='Name Can Not Be Numberic';
        set(hmsg,'string',stringinfo,'backgroundcolor',[1 1 0]);
    else
        % checking to make sure user has not already choosen a name that is
        % presently the name of another array
        nms=cell(1,length(hhandles));
        for ii=1:length(hhandles)
            hclick=hhandles(ii);
            dat=get(hclick,'userdata');
            hname=dat(2);
            if(hbut==hname)
                % skipping
            else
                nms{ii}=deblank(get(hname,'string'));
            end
        end
        % checking names
        for ii=1:length(nms)
            if(strcmp(nms{ii},nm))
                stringinfo='Duplicattion Of Array Names Not Allowed';
                set(hmsg,'string',stringinfo,'backgroundcolor',[1 1 0]);
                return
            end
        end

⌨️ 快捷键说明

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