tp@0: function setupmatfile = EDB1readsetup(EDsetupfile,cadgeofiletoopen) tp@0: % EDB1readsetup - Runs the EDsetup m-file and saves all the settings in a mat-file. tp@0: % If the sources and receivers should be taken from the tp@0: % CAD-file, they will be extracted and saved in the setupmatfile. tp@0: % tp@0: % Input parameters: tp@0: % EDsetupfile The name of the EDsetupfile (an m-file) that tp@0: % should be read. tp@0: % cadgeofiletoopen (optional) If the CAD file has already been read tp@0: % and stored as a cadgeofile, the cadgeofile could tp@0: % be used instead of the CAD-file. tp@0: % SHOWTEXT (global) Determines to what degree text will be printed out on the screen. tp@0: % tp@0: % Output parameters: tp@0: % setupmatfile The name of the output file. The name is created tp@0: % from the Filestem in the setupfile, with tp@0: % "_setup.mat" added. tp@0: % tp@0: % ---------------------------------------------------------------------------------------------- tp@0: % This file is part of the Edge Diffraction Toolbox by Peter Svensson. tp@0: % tp@0: % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify tp@0: % it under the terms of the GNU General Public License as published by the Free Software tp@0: % Foundation, either version 3 of the License, or (at your option) any later version. tp@0: % tp@0: % The Edge Diffraction Toolbox is distributed in the hope that it will be useful, tp@0: % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS tp@0: % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. tp@0: % tp@0: % You should have received a copy of the GNU General Public License along with the tp@0: % Edge Diffraction Toolbox. If not, see . tp@0: % ---------------------------------------------------------------------------------------------- tp@0: % Peter Svensson (svensson@iet.ntnu.no) 20100518 tp@0: % tp@0: % setupmatfile = EDB1readsetup(EDsetupfile,cadgeofile); tp@0: tp@0: global SHOWTEXT tp@0: tp@0: if nargin == 1 tp@0: cadgeofiletoopen = []; tp@0: end tp@0: luis@9: % keeping the original filename, will use it later --luisf. luis@9: setup_fname = EDsetupfile; luis@9: tp@0: [EDsetupfilepath,EDsetupfile,fileext] = fileparts(EDsetupfile); tp@0: EDsetupfilepath = [EDsetupfilepath,filesep]; tp@0: luis@9: % this is no longer necessary --luisf. luis@9: % eval(['cd ''',EDsetupfilepath,'''']) tp@0: tp@0: comptype = computer; tp@0: if length(comptype) == 3 tp@0: comptype = [comptype,'P']; tp@0: end tp@0: luis@9: % this doesn't work, need to read the file manually --luisf. luis@9: luis@9: % if comptype(1:4) == 'MACI' luis@9: % [temp1,tempfilestem,temp2] = fileparts(EDsetupfile); luis@9: % eval([tempfilestem]) luis@9: % else luis@9: % if comptype(1:3) == 'MAC', % | comptype(1:3) == 'PCW' luis@9: % eval([EDsetupfile]) luis@9: % else luis@9: % eval(['run ''',EDsetupfile,'''']) luis@9: % end luis@9: % end luis@9: luis@9: eval(char(textread(setup_fname, '%s', 'whitespace', ''))); luis@9: luis@9: % ~luisf tp@0: tp@0: if exist('Filestem') ~= 1 tp@0: error(['ERROR: The setup file does not specify the Filestem']) tp@0: else tp@0: Varlist = [' Filestem']; tp@0: end tp@0: tp@0: %----------------------------------------------------------------------------------------- tp@0: % Check if the EDsetupfile specified the needed parameters tp@0: tp@0: if isempty(FSAMP) tp@0: error(['ERROR: FSAMP was not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: Varlist = [Varlist,' FSAMP']; tp@0: end tp@0: tp@0: if isempty(RHOAIR) tp@0: error(['ERROR: RHOAIR was not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: Varlist = [Varlist,' RHOAIR']; tp@0: end tp@0: tp@0: if isempty(CAIR) tp@0: error(['ERROR: CAIR was not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: Varlist = [Varlist,' CAIR']; tp@0: end tp@0: tp@0: if exist('Filepath') ~= 1 tp@0: error(['ERROR: Filepath was not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: Varlist = [Varlist,' Filepath']; tp@0: end tp@0: tp@0: if exist('Filestem') ~= 1 tp@0: error(['ERROR: Filestem was not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: Varlist = [Varlist,' Filestem']; tp@0: end tp@0: tp@0: if (exist('CADfile') ~= 1) & isempty(cadgeofiletoopen) tp@0: error(['ERROR: CADfile or cadgeofile was not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: if exist('CADfile') == 1 tp@0: Varlist = [Varlist,' CADfile']; tp@0: else tp@0: if exist('cadgeofiletoopen') tp@0: cadgeofile = cadgeofiletoopen; tp@0: Varlist = [Varlist,' cadgeofile']; tp@0: end tp@0: end tp@0: end tp@0: tp@0: if exist('open_or_closed_model') ~= 1 tp@0: error(['ERROR: open_or_closed_model was not specified in ',EDsetupfile,'.m',' Valid values are ''open'' and ''closed''']) tp@0: else tp@0: Varlist = [Varlist,' open_or_closed_model']; tp@0: end tp@0: tp@0: if exist('int_or_ext_model') ~= 1 tp@0: error(['ERROR: int_or_ext_model was not specified in ',EDsetupfile,'.m',' Valid values are ''int'' and ''ext''']) tp@0: else tp@0: Varlist = [Varlist,' int_or_ext_model']; tp@0: end tp@0: tp@0: if lower(open_or_closed_model(1)) == 'o' & lower(int_or_ext_model(1)) == 'i' tp@0: error(['ERROR: When a model is open, it must be an external model. int_or_ext_model was set to ''int''']) tp@0: end tp@0: tp@0: if exist('EDcalcmethod') ~= 1 tp@0: error(['ERROR: EDcalcmethod was not specified in ',EDsetupfile,'.m',' Valid values are n,k,v']) tp@0: else tp@0: Varlist = [Varlist,' EDcalcmethod']; tp@0: end tp@0: tp@0: if exist('directsound') ~= 1 tp@0: error(['ERROR: directsound was not specified in ',EDsetupfile,'.m',' Valid values are 0 and 1']) tp@0: else tp@0: Varlist = [Varlist,' directsound']; tp@0: end tp@0: tp@0: if exist('specorder') ~= 1 tp@0: error(['ERROR: specorder was not specified in ',EDsetupfile,'.m',' Valid values are integers >= 0']) tp@0: else tp@0: Varlist = [Varlist,' specorder']; tp@0: end tp@0: tp@0: if exist('difforder') ~= 1 tp@0: error(['ERROR: difforder was not specified in ',EDsetupfile,'.m',' Valid values are integers >= 0']) tp@0: else tp@0: Varlist = [Varlist,' difforder']; tp@0: end tp@0: tp@0: if specorder < difforder tp@0: error(['ERROR: specorder must be the same as, or larger than, difforder in this version of EDtoolbox!']) tp@0: end tp@0: tp@0: if difforder >=2 tp@0: if exist('elemsize') ~= 1 tp@0: error(['ERROR: elemsize was not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: if min(elemsize) <= 0 tp@0: disp(['WARNING: elemsize was set smaller than zero']) tp@0: else tp@0: if length(elemsize) < difforder tp@0: error(['ERROR: elemsize must have one value for each diffraction order']) tp@0: else tp@0: Varlist = [Varlist,' elemsize']; tp@0: end tp@0: end tp@0: end tp@0: end tp@0: tp@0: if exist('sources') ~= 1 tp@0: error(['ERROR: sources were not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: Varlist = [Varlist,' sources']; tp@0: [nsou,slask] = size(sources); tp@0: end tp@0: tp@0: if exist('receivers') ~= 1 tp@0: error(['ERROR: receivers were not specified in ',EDsetupfile,'.m']) tp@0: else tp@0: Varlist = [Varlist,' receivers']; tp@0: end tp@0: tp@0: %--------------------------------------------------------------------- tp@0: % Optional parameters that should get a default value tp@0: tp@0: if isempty(SHOWTEXT) tp@0: disp([' The parameter SHOWTEXT was not set. It will get the default value 0.']) tp@0: SHOWTEXT = 0; tp@0: end tp@0: Varlist = [Varlist,' SHOWTEXT']; tp@0: tp@0: if exist('SUPPRESSFILES') ~= 1 tp@0: disp([' The parameter SUPPRESSFILES was not set. It will get the default value 0.']) tp@0: SUPPRESSFILES = 0; tp@0: end tp@0: Varlist = [Varlist,' SUPPRESSFILES']; tp@0: tp@0: if exist('nedgesubs') ~= 1 tp@0: if SHOWTEXT > 0 tp@0: disp([' The parameter nedgesubs was not set. It will get the default value 2.']) tp@0: end tp@0: nedgesubs = 2; tp@0: else tp@0: if nedgesubs == 1 tp@0: nedgesubs = 2; tp@0: if SHOWTEXT > 0 tp@0: disp('WARNING! nedgesubs was set to 1 in the setup file but it is forced to 2') tp@0: end tp@0: end tp@0: end tp@0: Varlist = [Varlist,' nedgesubs']; tp@0: tp@0: if exist('saveindividualdiffirs') ~= 1 tp@0: if SHOWTEXT > 0 tp@0: disp([' The parameter saveindividualdiffirs was not set. It will get the default value [0 0].']) tp@0: end tp@0: saveindividualdiffirs = [0 0]; tp@0: else tp@0: if length(saveindividualdiffirs) == 1 tp@0: if SHOWTEXT > 0 tp@0: disp([' The parameter saveindividualdiffirs had just one value. It was expanded with a second default value 0.']) tp@0: end tp@0: saveindividualdiffirs = [saveindividualdiffirs 0]; tp@0: end tp@0: end tp@0: Varlist = [Varlist,' saveindividualdiffirs']; tp@0: tp@0: if exist('firstskipcorner') ~= 1 tp@0: if SHOWTEXT > 0 tp@0: disp([' The parameter firstskipcorner was not set. It will get the default value 1000000.']) tp@0: end tp@0: firstskipcorner = 1000000; tp@0: end tp@0: Varlist = [Varlist,' firstskipcorner']; tp@0: tp@0: if exist('doaddsources') ~= 1 tp@0: if nsou > 1 tp@0: disp([' The parameter doaddsources was not set. It will get the default value 0.']) tp@0: end tp@0: doaddsources = 0; tp@0: end tp@0: Varlist = [Varlist,' doaddsources']; tp@0: tp@0: if exist('dobackscatter') ~= 1 tp@0: dobackscatter = 0; tp@0: end tp@0: Varlist = [Varlist,' dobackscatter']; tp@0: tp@0: if dobackscatter*doaddsources == 1 tp@0: error(['ERROR: You have set both dobackscatter and doaddsources to 1. This does not make sense!']) tp@0: end tp@0: tp@0: if exist('Rstart') ~= 1 tp@0: if SHOWTEXT > 0 tp@0: disp([' The parameter Rstart was not set. It will get the default value 0.']) tp@0: end tp@0: Rstart = 0; tp@0: end tp@0: Varlist = [Varlist,' Rstart']; tp@0: tp@0: if exist('planeseesplanestrategy') ~= 1 tp@0: if SHOWTEXT > 0 tp@0: disp([' The parameter planeseesplanestrategy was not set. It will get the default value 0.']) tp@0: end tp@0: planeseesplanestrategy = 0; tp@0: end tp@0: Varlist = [Varlist,' planeseesplanestrategy']; tp@0: tp@0: %--------------------------------------------------------------------- tp@0: % Optional parameters tp@0: tp@0: if exist('eddatafile') tp@0: Varlist = [Varlist,' eddatafile']; tp@0: end tp@0: if exist('srdatafile') tp@0: Varlist = [Varlist,' srdatafile']; tp@0: end tp@0: if exist('calcpaths') tp@0: Varlist = [Varlist,' calcpaths']; tp@0: end tp@0: if exist('calcirs') tp@0: Varlist = [Varlist,' calcirs']; tp@0: end tp@0: tp@0: %--------------------------------------------------------------------------------------------- tp@0: % Find source and receiver coordinates either in the setup-file or in the CAD-file tp@0: tp@0: [nsou,nsoucols] = size(sources); tp@0: if nsoucols < 3 tp@0: if isempty(cadgeofiletoopen) tp@0: error(['ERROR: sources should be taken from the CAD file, but no cadgeofile was specified as input parameter to EDB1readsetup']) tp@0: end tp@0: eval(['load ',cadgeofiletoopen]) tp@0: [n1,n2] = size(Snames); tp@0: Snames = reshape(Snames.',1,n1*n2); tp@0: strpos = zeros(nsou,1); tp@0: for ii = 1:nsou tp@0: strpos_source = findstr(sources(ii,:),Snames); tp@0: if ~isempty(strpos_source) tp@0: strpos(ii) = strpos_source; tp@0: else tp@0: error(['ERROR: One of the sources could not be found in the CAD-file: ',sources(ii,:)]) tp@0: end tp@0: tp@0: end tp@0: if prod(strpos) == 0 tp@0: error('ERROR: One of the sources could not be found in the CAD-file') tp@0: end tp@0: sounumbers = floor(strpos/n2)+1; tp@0: sources = Scoords(sounumbers,:); tp@0: end tp@0: tp@0: [nrec,nreccols] = size(receivers); tp@0: if nreccols ~= 3 tp@0: if isempty(cadgeofiletoopen) tp@0: error(['ERROR: receivers should be taken from the CAD file, but no cadgeofile was specified as input parameter to EDB1readsetup']) tp@0: end tp@0: eval(['load ',cadgeofiletoopen]) tp@0: strpos = zeros(nrec,1); tp@0: for ii = 1:nrec tp@0: strpos_rec = find(Rnumbers==receivers(ii)); tp@0: if ~isempty(strpos_rec) tp@0: strpos(ii) = strpos_rec; tp@0: else tp@0: error(['ERROR: One of the receivers could not be found in the CAD-file: ',int2str(receivers(ii))]) tp@0: end tp@0: end tp@0: if prod(strpos) == 0 tp@0: error('ERROR: One of the receivers could not be found in the CAD-file') tp@0: end tp@0: receivers = Rcoords(strpos,:); tp@0: else tp@0: if nrec == 1 tp@0: if abs(round(receivers(1))) == receivers(1) & abs(round(receivers(2)))==receivers(2) & abs(round(receivers(3))) == receivers(3) tp@0: if SHOWTEXT > 0 tp@0: disp(['WARNING: You have specified the receivers as a row of three integer values, which is ambiguous']) tp@0: disp([' It is interpreted as one receiver, with given coordinates']) tp@0: end tp@0: end tp@0: end tp@0: end tp@0: tp@0: %--------------------------------------------------------------------------------------------- tp@0: % Check the optional parameters nSbatches etc tp@0: tp@0: nsources = size(sources,1); tp@0: nreceivers = size(receivers,1); tp@0: tp@0: if exist('soulist_for_findpaths') ~= 1 tp@0: soulist_for_findpaths = [1:nsources]; tp@0: else tp@0: if soulist_for_findpaths(1) < 1 tp@0: error('ERROR: soulist_for_findpaths must start with an integer > 0') tp@0: end tp@0: if soulist_for_findpaths(end) > nsources tp@0: error('ERROR: soulist_for_findpaths must end with an integer <= the number of sources') tp@0: end tp@0: end tp@0: if exist('reclist_for_findpaths') ~= 1 tp@0: reclist_for_findpaths = [1:nreceivers]; tp@0: else tp@0: if reclist_for_findpaths(1) < 1 tp@0: error('ERROR: reclist_for_findpaths must start with an integer > 0') tp@0: end tp@0: if reclist_for_findpaths(end) > nreceivers tp@0: error('ERROR: reclist_for_findpaths must end with an integer <= the number of receivers') tp@0: end tp@0: end tp@0: if exist('soulist_for_calcirs') ~= 1 tp@0: soulist_for_calcirs = [1:nsources]; tp@0: else tp@0: if soulist_for_calcirs(1) < 1 tp@0: error('ERROR: soulist_for_calcirs must start with an integer > 0') tp@0: end tp@0: if soulist_for_calcirs(end) > nsources tp@0: error('ERROR: soulist_for_calcirs must end with an integer <= the number of sources') tp@0: end tp@0: end tp@0: if exist('reclist_for_calcirs') ~= 1 tp@0: reclist_for_calcirs = [1:nreceivers]; tp@0: else tp@0: if reclist_for_calcirs(1) < 1 tp@0: error('ERROR: reclist_for_calcirs must start with an integer > 0') tp@0: end tp@0: if reclist_for_calcirs(end) > nreceivers tp@0: error('ERROR: reclist_for_calcirs must end with an integer <= the number of receivers') tp@0: end tp@0: end tp@0: tp@0: Varlist = [Varlist,' soulist_for_findpaths reclist_for_findpaths soulist_for_calcirs reclist_for_calcirs']; tp@0: tp@0: %--------------------------------------------------------------------- tp@0: % Optional parameters for batch processing tp@0: tp@0: eval(['load ',cadgeofiletoopen]) tp@0: batchsize = 6000; tp@0: tp@0: suggestednSbatches = ceil(size(planecorners,1)*size(sources,1)/batchsize); tp@0: suggestednRbatches = ceil(size(planecorners,1)*size(receivers,1)/batchsize); tp@0: tp@0: if exist('nRbatches') ~= 1 tp@0: if suggestednRbatches > 1 tp@0: disp(['WARNING!!! The number of planes and receivers is high enough that it is recommended']) tp@0: disp([' to set nRbatches to ',int2str(suggestednRbatches)]) tp@0: disp([' Set SHOWTEXT to 0 or 1 to skip the pause']) tp@0: if SHOWTEXT > 1 tp@0: disp(['Take the chance to stop the processing and change the value of nRbatches']) tp@0: pause tp@0: end tp@0: tp@0: else tp@0: nRbatches = 1; tp@0: end tp@0: else tp@0: if nRbatches < 0, tp@0: error('ERROR: The parameter nRbatches must be a positive integer') tp@0: else tp@0: if suggestednRbatches > nRbatches tp@0: disp(['WARNING!!! The number of planes and receivers is high enough that it is recommended']) tp@0: disp([' to set nRbatches to ',int2str(suggestednRbatches)]) tp@0: disp([' Set SHOWTEXT to 0 or 1 to skip the pause']) tp@0: if SHOWTEXT > 1 tp@0: disp(['Take the chance to stop the processing and change the value of nRbatches']) tp@0: pause tp@0: end tp@0: else tp@0: nRbatches = round(nRbatches); tp@0: end tp@0: end tp@0: end tp@0: if exist('nSbatches') ~= 1 tp@0: if suggestednSbatches > 1 tp@0: disp(['WARNING!!! The number of planes and sources is high enough that it is recommended']) tp@0: disp([' to set nSbatches to ',int2str(suggestednSbatches)]) tp@0: disp([' Set SHOWTEXT to 0 or 1 to skip the pause']) tp@0: if SHOWTEXT > 1 tp@0: disp(['Take the chance to stop the processing and change the value of nSbatches']) tp@0: pause tp@0: end tp@0: else tp@0: nSbatches = 1; tp@0: end tp@0: else tp@0: if nSbatches < 0, tp@0: error('ERROR: The parameter nSbatches must be a positive integer') tp@0: else tp@0: if suggestednSbatches > nSbatches tp@0: disp(['WARNING!!! The number of planes and sources is high enough that it is recommended']) tp@0: disp([' to set nSbatches to ',int2str(suggestednSbatches)]) tp@0: disp([' Set SHOWTEXT to 0 or 1 to skip the pause']) tp@0: if SHOWTEXT > 1 tp@0: disp(['Take the chance to stop the processing and change the value of nSbatches']) tp@0: pause tp@0: end tp@0: else tp@0: nSbatches = round(nSbatches); tp@0: end tp@0: end tp@0: end tp@0: tp@0: Varlist = [Varlist,' nSbatches nRbatches']; tp@0: tp@0: %--------------------------------------------------------------------- tp@0: % Optional parameters for path editing tp@0: tp@0: if exist('symmetricedgepairs') ~= 1 tp@0: symmetricedgepairs = []; tp@0: else tp@0: if size(symmetricedgepairs,2) ~= 2, tp@0: error('ERROR: The matrix symmetricedgepairs must have two columns') tp@0: end tp@0: end tp@0: tp@0: Varlist = [Varlist,' symmetricedgepairs']; tp@0: tp@0: %--------------------------------------------------------------------- tp@0: % Save in the output file tp@0: tp@0: setupmatfile = [Filepath,Filestem,'_setup.mat']; tp@0: tp@0: eval(['save ',setupmatfile,Varlist])