过冷水诚挚邀请你加入Matlab仿真秀官方交流群进行Matlab学习、问题咨询、 Matlab相关资料下载,群号:927550334
function varargout = open_file(varargin) % OPEN_FILE M-file for open_file.fig % OPEN_FILE, by itself, creates a new OPEN_FILE or raises the existing % singleton*. % % H = OPEN_FILE returns the handle to a new OPEN_FILE or the handle to % the existing singleton*. % % OPEN_FILE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in OPEN_FILE.M with the given input arguments. % % OPEN_FILE('Property','Value',...) creates a new OPEN_FILE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before open_file_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to open_file_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help open_file % Last Modified by GUIDE v2.5 11-Jul-2005 11:24:39 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @open_file_OpeningFcn, ... 'gui_OutputFcn', @open_file_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(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 open_file is made visible --- %% function open_file_OpeningFcn(hObject, eventdata, handles, varargin) % initialize flags and pathnames global ParsecData WFNData PguiData global datFlag outFlag outfilename outpathname datfilename datpathname rsdft_flag; if(strcmp(PguiData.workingDir,' ')) datFlag = 0; outFlag = 0; else datFlag = 1; outFlag = 1; end outfilename = ' '; outpathname = PguiData.workingDir; datfilename = ' '; datpathname = PguiData.workingDir; ParsecData.valid = false; WFNData.valid = false; % Choose default command line output for open_file handles.output = hObject; % Update handles structure guidata(hObject, handles); global pvoxView; pvoxView.open = handles; %% --- Outputs from this function are returned to the command line --- %% function varargout = open_file_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % Get default command line output from handles structure varargout{1} = handles.output; %% --- Executes on button press in pushbutton_out --- %% function pushbutton_out_Callback(hObject, eventdata, handles) global outfilename outpathname outFlag datFlag datpathname datfilename PguiData rsdft_flag; % Open uigetfile window %[filename,pathname, filter] = uigetfile([PguiData.dir '*.out']); if (datFlag == 1) [filename,pathname, filter] = uigetfile([datpathname '*.out']); else [filename,pathname, filter] = uigetfile('*.out'); end rsdft_flag = 0; % If valid set path variable if (filter ~= 0) outfilename = filename; outpathname = pathname; set(handles.out, 'String', [outpathname outfilename]); outFlag = 1; rsdft_string = outfilename(1:5); if(rsdft_string == 'rsdft') rsdft_flag = 1; end if(rsdft_flag == 1) % Attempt to guess rsdft .dat file try guess = outfilename(6:length(outfilename)); guess = guess(1:length(guess)-3); guess = ['wfn' guess 'dat']; test = dir([outpathname guess]); if(strcmp(test.name,guess)) datpathname = outpathname; datfilename = guess; set(handles.dat, 'String', [datpathname datfilename]); datFlag = 1; elseif(strcmp(test.name,[outpathname guess])) datpathname = outpathname; datfilename = guess; set(handles.dat, 'String', [datpathname datfilename]); datFlag = 1; end end else % Attempt to guess parsec .dat file try guess = outfilename(7:length(outfilename)); guess = guess(1:length(guess)-3); guess = ['wfn' guess 'dat']; test = dir([outpathname guess]); if(strcmp(test.name,guess)) datpathname = outpathname; datfilename = guess; set(handles.dat, 'String', [datpathname datfilename]); datFlag = 1; elseif(strcmp(test.name,[outpathname guess])) datpathname = outpathname; datfilename = guess; set(handles.dat, 'String', [datpathname datfilename]); datFlag = 1; end end end end function out_Callback(hObject, eventdata, handles) %% --- Executes during object creation, after setting all properties --- %% function out_CreateFcn(hObject, eventdata, handles) % Set color of edit box if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end %% --- Executes on button press in pushbutton_dat --- %% function pushbutton_dat_Callback(hObject, eventdata, handles) global datfilename datpathname datFlag outFlag outpathname rsdft_flag; % Open uigetfile window if (outFlag == 1) [filename,pathname, filter] = uigetfile([outpathname '*.dat']); else [filename,pathname, filter] = uigetfile('*.dat'); end % If valid set path variable if ( filter ~= 0 ) datfilename = filename; datpathname = pathname; set(handles.dat, 'String', [datpathname datfilename]); datFlag = 1; end function dat_Callback(hObject, eventdata, handles) %% --- Executes during object creation, after setting all properties --- %% function dat_CreateFcn(hObject, eventdata, handles) % Set color of edit box if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end %% --- Executes on button press in OK --- %% function OK_Callback(hObject, eventdata, handles) global datFlag outFlag; global outfilename outpathname; global datfilename datpathname; global rsdft_flag; % Open data if pathnames are valid if ((datFlag == 1) & (outFlag == 1)) % Set GUI objects inactive set(hObject,'Enable','inactive'); set(handles.out,'Enable','off'); set(handles.dat,'Enable','off'); set(handles.pushbutton_out,'Enable','off'); set(handles.pushbutton_dat,'Enable','off'); set(hObject,'String','Please Wait...'); drawnow; if(rsdft_flag == 0) [newParsecData, newWFNData, D_valid, W_valid] = readOutput([outpathname outfilename], [datpathname datfilename]); if (~D_valid || ~min(W_valid)) [newParsecData, newWFNData, D_valid, W_valid] = readOutput_rsdft([outpathname outfilename], [datpathname datfilename]); end else [newParsecData, newWFNData, D_valid, W_valid] = readOutput_rsdft([outpathname outfilename], [datpathname datfilename]); if (~D_valid || ~min(W_valid)) [newParsecData, newWFNData, D_valid, W_valid] = readOutput([outpathname outfilename], [datpathname datfilename]); end end %if pvox is closed exit gracefully global pvoxView; if pvoxView.closed return; end % If valid input, Initialize pvox if (D_valid && min(W_valid) ) global PguiData Phandles Ptoolbar ParsecData WFNData; % If a data set is open if PguiData.open_dataset % Clear open data set clear global ParsecData WFNData global ParsecData WFNData pvoxM1d pvoxM2d pvoxM3d pvoxMslice pvoxMdos pvoxView try atom = pvoxView.atom; close(atom.figure1); %drawnow; %ParsecAtomView; end try iter = pvoxView.iter; close(iter.figure1); %drawnow; %ParsecIterationView; end % Reset view specific variables pvoxM1d.init=0; pvoxM2d.init=0; pvoxM3d.init=0; pvoxMdos.init=0; pvoxMslice.init=0; ParsecData = newParsecData; WFNData = newWFNData; % Redraw current view switch PguiData.mode case 'M1d' M1d_init; update_M1d('everything'); case 'M2d' M2d_init; update_M2d('everything'); case 'M3d' M3d_init; update_M3d('everything'); case 'Mdos' Mdos_init; update_Mdos('everything'); case 'Mslice' Mslice_init; update_Mslice('everything'); end click_reset; else ParsecData = newParsecData; WFNData = newWFNData; PguiData.open_dataset=1; % Enable menus and toolbar set(Phandles.menu_1d,'Enable','on'); set(Phandles.menu_2d,'Enable','on'); set(Phandles.menu_3d,'Enable','on'); set(Phandles.menu_dos,'Enable','on'); set(Phandles.menu_preferences,'Enable','on'); set(Phandles.menu_slice,'Enable','on'); set(Phandles.menu_print,'Enable','on'); set(Phandles.menu_capture,'Enable','on'); set(Phandles.axes1,'Visible','on'); set(Ptoolbar.print,'Enable','on'); set(Ptoolbar.capture,'Enable','on'); set(Ptoolbar.zoomin,'Enable','on'); set(Ptoolbar.reset,'Enable','on'); set(Ptoolbar.rotate,'Enable','on'); set(Ptoolbar.colorbar,'Enable','on'); set(Ptoolbar.AtomView,'Enable','on'); set(Ptoolbar.IterationView,'Enable','on'); set(Ptoolbar.M1d,'Enable','on'); set(Ptoolbar.M2d,'Enable','on'); set(Ptoolbar.M3d,'Enable','on'); set(Ptoolbar.Mdos,'Enable','on'); set(Ptoolbar.Mslice,'Enable','on'); % Load 2D view of potential - default PguiData.graph='pot'; modeswitch_M2d(Phandles); end % Determine Window Title n=size(ParsecData.typeNum); string='pvox _'; for m=(1: (n(2)) ) string = strcat( string, mat2str(ParsecData.typeNum(m)), ParsecData.typeName(m,:), '_' ); end set(Phandles.figure1,'Name',string); % Save to open recent list; PguiData.recent_out = {}; PguiData.recent_dat = {}; % Read in recent file list try recent = fopen('pTemp/recent.dat','r'); i = 1; file_name = fgetl(recent); while (file_name ~= -1) PguiData.recent_out{i} = file_name; file_name = fgetl(recent); PguiData.recent_dat{i} = file_name; file_name = fgetl(recent); if (strcmp(PguiData.recent_out{i},[outpathname outfilename]) && strcmp(PguiData.recent_dat{i},[datpathname datfilename])) PguiData.recent_out{i} = 'ERASE'; PguiData.recent_dat{i} = 'ERASE'; end i = i 1; end fclose(recent); end % Add escape character to forward slashes outname = [outpathname outfilename]; datname = [datpathname datfilename]; i = 1; while (i < size(outname,2)) if (outname(i) == '\') outname = [outname(1:i) '\' outname(i 1:size(outname,2))]; i = i 1; end i = i 1; end i = 1; while (i < size(datname,2)) if (datname(i) == '\') datname = [datname(1:i) '\' datname(i 1:size(datname,2))]; i = i 1; end i = i 1; end % Write new list back to file recent = fopen('pTemp/recent.dat','w'); fprintf(recent,[outname '\n']); fprintf(recent,[datname '\n']); list_size = size(PguiData.recent_out,2); if (list_size > 10) list_size = 10; end for i = 1:list_size if (~strcmp(PguiData.recent_out{i},'ERASE')) fprintf(recent,[PguiData.recent_out{i} '\n']); fprintf(recent,[PguiData.recent_dat{i} '\n']); end end % Change permissions on file fclose(recent); [str,maxsize,endian] = computer; if (~strcmp(str,'PCWIN')) [s,w] = unix('chmod 660 pTemp/*'); end %change current directory PguiData.workingDir = outpathname; else % Error reading input if (~D_valid) uiwait(errordlg('Error opening parsec/rsdft.out','ERROR')); end if (~W_valid(1)) uiwait(errordlg('Error in wfn.dat: Cannot read format','ERROR')); elseif (~W_valid(2)) uiwait(errordlg('Error in wfn.dat: Unkown Symmetry Found','ERROR')); elseif (~W_valid(3)) uiwait(errordlg('Error in wfn.dat: error reading potential and charge density','ERROR')); elseif (~W_valid(4)) uiwait(errordlg('Error in wfn.dat: error reading wavefunctions','ERROR')); elseif (~W_valid(5)) uiwait(errordlg('Error in wfn.dat: error creating mesh grid','ERROR')); end end close(handles.figure1); end
过冷水发表于 仿真秀 平台原创文章,未经授权禁止私自转载,如需转载请需要和作者沟通表明授权声明,未授权文章皆视为侵权行为,必将追责。如果您希望加入Matlab仿真秀官方交流群进行Matlab学习、问题咨询、 Matlab相关资料下载均可加群:927550334。
精品回顾
过冷水和你分享 matlab读取存储各种文件的方法 文末有独家金曲分享