0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if ~exist('Verbose'),
0024 Verbose = 1;
0025 end
0026
0027 if ~exist('GUIactive') && ~exist('UsingLibrary'),
0028 Query = xSpecifyQuery;
0029 if isfield(Query,'SearchFiles'),
0030 Filenames = Query.SearchFiles;
0031 else
0032 Filenames = {'1s72'};
0033 end
0034 end
0035
0036
0037
0038 if ~exist('File'),
0039 [File,SIndex] = zAddNTData(Filenames,0,[],Verbose);
0040 else
0041 [File,SIndex] = zAddNTData(Filenames,0,File,Verbose);
0042 end
0043
0044
0045
0046
0047 clear Filenames
0048
0049 for i = 1:length(SIndex),
0050 Filenames{i} = File(SIndex(i)).Filename;
0051 end
0052
0053
0054
0055 if ~exist('UsingLibrary'),
0056 if isfield(Query,'Filename'),
0057 [File,QIndex] = zAddNTData(Query.Filename,0,File);
0058
0059 Query = xConstructQuery(Query,File(QIndex));
0060 else
0061 Query = xConstructQuery(Query);
0062 end
0063
0064 end
0065
0066 clear Search
0067 Search.SaveName = [datestr(now,31) '-' Query.Name];
0068
0069
0070
0071
0072
0073 if isfield(Query,'NumNT'),
0074
0075
0076
0077 if Verbose > 0,
0078 fprintf('Query %s:', Query.Name);
0079
0080 if isfield(Query,'Description'),
0081 fprintf(' %s\n', Query.Description);
0082 else
0083 fprintf('\n');
0084 end
0085 end
0086
0087
0088
0089 for f=1:length(SIndex),
0090 i = SIndex(f);
0091 if isempty(File(i).Distance),
0092 dmin = 0;
0093 else
0094 dmin = ceil(max(max(File(i).Distance)));
0095 end
0096
0097 if (ceil(Query.DistCutoff) > dmin) && (File(i).NumNT > 0),
0098 c = cat(1,File(i).NT(1:File(i).NumNT).Center);
0099 File(i).Distance = zMutualDistance(c,Query.DistCutoff);
0100
0101 end
0102 end
0103
0104 drawnow
0105
0106
0107
0108 starttime = cputime;
0109
0110 Candidates = xFindCandidates(File(SIndex),Query,Verbose);
0111
0112 if ~isempty(Candidates),
0113 if Query.Geometric > 0,
0114 [Discrepancy, Candidates] = xRankCandidates(File(SIndex),Query,Candidates,Verbose);
0115 if Verbose > 0,
0116 fprintf('Found %d candidates in the desired discrepancy range\n',length(Discrepancy));
0117 end
0118
0119 if (Query.ExcludeOverlap > 0) & (length(Discrepancy) > 0) ...
0120 & (Query.NumNT > 2),
0121 [Candidates, Discrepancy] = xReduceOverlap(Candidates,Discrepancy);
0122
0123 [Candidates, Discrepancy] = xExcludeOverlap(Candidates,Discrepancy,400);
0124
0125 if Verbose > 0,
0126 fprintf('Removed highly overlapping candidates, kept %d\n', length(Candidates(:,1)));
0127 end
0128 end
0129
0130 elseif Query.NumNT > 2,
0131 A = [Candidates sum(Candidates')'];
0132 N = Query.NumNT;
0133 [y,i] = sortrows(A,[N+1 N+2 1:N]);
0134 Candidates = Candidates(i,:);
0135 Discrepancy = (1:length(Candidates(:,1)))';
0136 else
0137 N = Query.NumNT;
0138 [y,i] = sortrows(Candidates,[N+1 1 2]);
0139 Candidates = Candidates(i,:);
0140 Discrepancy = (1:length(Candidates(:,1)))';
0141 end
0142
0143
0144
0145 Search.Query = Query;
0146 Search.Filenames = Filenames;
0147 Search.TotalTime = cputime - starttime;
0148 Search.Date = Search.SaveName(1:10);
0149 Search.Time = Search.SaveName(12:18);
0150 Search.SaveName = strrep(Search.SaveName,' ','_');
0151 Search.SaveName = strrep(Search.SaveName,':','_');
0152 Search.SaveName = strrep(Search.SaveName,'<','_');
0153 Search.SaveName = strrep(Search.SaveName,'>','_');
0154 Search.SaveName = strrep(Search.SaveName,'?','_');
0155 Search.SaveName = strrep(Search.SaveName,'*','_');
0156 Search.SaveName = strrep(Search.SaveName,'&','_');
0157 Search.Candidates = Candidates;
0158 Search.Discrepancy = Discrepancy;
0159
0160 Search = xAddFiletoSearch(File(SIndex),Search);
0161
0162 if ~exist('UsingLibrary'),
0163
0164 if ~(exist('SearchSaveFiles') == 7),
0165 mkdir('SearchSaveFiles');
0166 end
0167
0168 save(['SearchSaveFiles' filesep Search.SaveName], 'Search');
0169 end
0170
0171
0172 if Verbose > 0,
0173 fprintf('Entire search took %8.4f seconds, or %8.4f minutes\n', (cputime-starttime), (cputime-starttime)/60);
0174 end
0175
0176 if (~exist('GUIactive')) && (~isempty(Candidates)) && ~exist('UsingLibrary'),
0177 xListCandidates(Search,Inf,1);
0178 Search = xDisplayCandidates(File(SIndex),Search);
0179 save(['SearchSaveFiles' filesep Search.SaveName], 'Search');
0180 end
0181
0182 end
0183
0184 end