MAKELIST - generate simulations list list = makelist(inputFileName, detId); Generate list from file inputFileName line-by-line list = makelist(nSim, inputFileName, detId); Generate list from nSim random draws on the lines of file inputFileName list = makelist(nSim, simId, ampl, startSamp, internal, external, detId); Generate list with user specified variables; internal and external can also be set to 'RANDOM' or 'OPTIMAL' inputFileName string with name of input file. Each line of the file contains the following (in this order): [simId ampl startSamp1 startSamp2 int1 int2 ext1 ext2 ext3] nSim positive integer indicating how many simulations to generate simId signal type ampl signal amplitude When varargin=6, ampl can be a vector of length 1, 2 or 3 *When length(ampl)=1, the amplitude is fixed *When length(ampl)=2, the amplitude is randomly chosen between ampl(1) and ampl(2) in a logarithmic distribution. N.B. ampl(1)=ampl(2) is equivilent to entering a fixed amplitude *When length(ampl)=3, the amplitdue is randomly chosen from the discrete linear range ampl(1):ampl(2):ampl(3) startSamp 2 component vector defining range of allowed start times in samples since the beginning of data set internal 1x2 vector or struct with 2 fields (x & phi) or string 'RANDOM' or 'OPTIMAL' representing the internal angles of the source external 1x3 vector or struct with 3 fields (x, phi and psi) or string 'RANDOM' or 'OPTIMAL' representing the external angles of the source detId (optional) detector identifier string; only needed for 'OPTIMAL' external angles list Cell array containing simulations list. Each row is a simulation. Each component of the row represent: [simId ampl startSamp int1 int2 ext1 ext2 ext3], in this order. N.B. startSamp is now a scalar - start time has been determined SEE ALSO: GRAVEN, GETIFO
0001 function list = makelist(varargin) 0002 0003 % MAKELIST - generate simulations list 0004 % 0005 % list = makelist(inputFileName, detId); 0006 % Generate list from file inputFileName line-by-line 0007 % list = makelist(nSim, inputFileName, detId); 0008 % Generate list from nSim random draws on the lines of file inputFileName 0009 % list = makelist(nSim, simId, ampl, startSamp, internal, external, detId); 0010 % Generate list with user specified variables; internal and external can 0011 % also be set to 'RANDOM' or 'OPTIMAL' 0012 % 0013 % inputFileName string with name of input file. Each line of the file 0014 % contains the following (in this order): 0015 % [simId ampl startSamp1 startSamp2 int1 int2 ext1 ext2 ext3] 0016 % nSim positive integer indicating how many simulations to generate 0017 % simId signal type 0018 % ampl signal amplitude 0019 % When varargin=6, ampl can be a vector of length 1, 2 or 3 0020 % *When length(ampl)=1, the amplitude is fixed 0021 % *When length(ampl)=2, the amplitude is randomly chosen 0022 % between ampl(1) and ampl(2) in a logarithmic distribution. 0023 % N.B. ampl(1)=ampl(2) is equivilent to entering a fixed 0024 % amplitude 0025 % *When length(ampl)=3, the amplitdue is randomly chosen from 0026 % the discrete linear range ampl(1):ampl(2):ampl(3) 0027 % startSamp 2 component vector defining range of allowed start times in 0028 % samples since the beginning of data set 0029 % internal 1x2 vector or struct with 2 fields (x & phi) or string 0030 % 'RANDOM' or 'OPTIMAL' representing the internal angles of 0031 % the source 0032 % external 1x3 vector or struct with 3 fields (x, phi and psi) or string 0033 % 'RANDOM' or 'OPTIMAL' representing the external angles of 0034 % the source 0035 % detId (optional) detector identifier string; only needed for 0036 % 'OPTIMAL' external angles 0037 % 0038 % list Cell array containing simulations list. Each row is a 0039 % simulation. Each component of the row represent: 0040 % [simId ampl startSamp int1 int2 ext1 ext2 ext3], in this 0041 % order. N.B. startSamp is now a scalar - start time has been 0042 % determined 0043 % 0044 % SEE ALSO: GRAVEN, GETIFO 0045 0046 % $Id: makelist.m,v 1.25 2005/04/28 16:02:31 stuver Exp $ 0047 0048 % DETERMINE operating mode from inputs 0049 % ASSIGN variable names based on mode 0050 % GENERATE list according to mode used 0051 0052 list = {}; 0053 0054 % Determine operating mode 0055 input = varargin; 0056 mode = whatmode(input); 0057 0058 % Assign variable names 0059 switch mode 0060 case 1 0061 inputFileName = varargin{1}; 0062 case 2 0063 [nSim, inputFileName] = deal(varargin{:}); 0064 case 3 0065 [inputFileName, detId] = deal(varargin{:}); 0066 case 4 0067 [nSim, inputFileName, detId] = deal(varargin{:}); 0068 case 5 0069 [nSim, simId, ampl, startSamp, internal, external] = ... 0070 deal(varargin{:}); 0071 case 6 0072 [nSim, simId, ampl, startSamp, internal, external, detId] = ... 0073 deal(varargin{:}); 0074 end 0075 0076 % Generate list based on mode used: 0077 if mode == 1 | mode == 2 | mode == 3 | mode == 4 % File reading modes 0078 % IF mode reads from file 0079 % READ variables from file 0080 % IF mode makes nSim draws on lines of file 0081 % DRAW nSim times on lines of file 0082 % ENDIF 0083 % SET angles 0084 % SET start times 0085 % RETURN list 0086 % ENDIF 0087 0088 % Check to make sure file exists 0089 if exist(inputFileName, 'file') ~= 2 0090 inputFileName 0091 error(['makelist: inputFileName does not exist as a file in '... 0092 'the search path']) 0093 end 0094 0095 % Read file 0096 [simId, ampl, startSamp1, startSamp2, int1, int2, ext1, ext2, ext3]=... 0097 ctextread(inputFileName, '%s %f %f %f %s %s %s %s %s %*[^\n]', ... 0098 'commentstyle', 'shell'); 0099 % The *[^/n] in the last placeholder ignores all remaining columns in a 0100 % row. This enables the log file (which has more columns than the list 0101 % file) to be read in as a list file. 0102 0103 if ampl == -1 0104 % Make nSim draws on the lines of inputFileName 0105 if mode == 2 | mode == 4 0106 % Number of rows (simulations) in inputFileName 0107 mfname = size(simId, 1); 0108 for k = 1:mfname 0109 % Read everything into tempList 0110 tempList(k,:) = {simId(k,:), ampl(k), startSamp1(k), ... 0111 startSamp2(k), int1(k,:), int2(k,:), ext1(k,:), ... 0112 ext2(k,:), ext3(k,:)}; 0113 % tempList is used to construct a cell array of the original 0114 % data in inputFileName and is different in form from the 0115 % output list in that the start time is determined in list 0116 % (list has one less column than tempList) 0117 end 0118 % Make nSim draws on tempList 0119 [simId, ampl, startSamp1, startSamp2, int1, int2, ext1, ext2, ... 0120 ext3] = ndraws(nSim, tempList); 0121 end 0122 0123 if mode <= 4 0124 mSim = size(simId,1); 0125 for kSim = 1:mSim 0126 tempSimId = simId{kSim,1}; 0127 I = find(tempSimId == ','); 0128 C = find(tempSimId == ';'); 0129 if isempty(I) 0130 file{kSim,1} = tempSimId(1:end); 0131 file{kSim,2} = 'default'; 0132 elseif length(I) == 1 & isempty(C) 0133 file{kSim,1} = tempSimId(1:I(1)-1); 0134 file{kSim,2} = tempSimId(I(1)+1:end); 0135 elseif length(I) == 2 & length(C) == 1 0136 file{kSim,1} = tempSimId(1:I(1)-1); 0137 file{kSim,2} = tempSimId(I(1)+1:C-1); 0138 file{kSim,3} = tempSimId(C+1:I(2)-1); 0139 file{kSim,4} = tempSimId(I(2)+1:end); 0140 elseif length(I) == 1 & length(C) == 1 0141 if I < C 0142 file{kSim,1} = tempSimId(1:I-1); 0143 file{kSim,2} = tempSimId(I+1:C-1); 0144 file{kSim,3} = tempSimId(C+1:end); 0145 file{kSim,4} = 'default'; 0146 elseif I > C 0147 file{kSim,1} = tempSimId(1:C-1); 0148 file{kSim,2} = 'default'; 0149 file{kSim,3} = tempSimId(C+1:I-1); 0150 file{kSim,4} = tempSimId(I+1:end); 0151 end 0152 else 0153 simId{kSim,:} 0154 error('pregenlist: Invalid simId') 0155 end 0156 external{kSim} = {ext1{kSim}, ext2{kSim}, ext3{kSim}}; 0157 end 0158 if mode == 2 | mode == 4 0159 list = pregenlist(nSim, file, [startSamp1(:), startSamp2(:)], external, detId); 0160 return 0161 else 0162 list = pregenlist(file, [startSamp1(:), startSamp2(:)], external, detId); 0163 return 0164 end 0165 0166 end 0167 elseif ampl <= 0 & ampl ~= -1 0168 ampl 0169 error(['makelist: ampl must be > 0 (except when switch for pre-generated '... 0170 'waveforms, ampl = -1)']) 0171 end 0172 0173 % Cast variabiles into char class from cell (this will aid in 0174 % comparing variables that may or may not be strings) 0175 [simId, int1, int2, ext1, ext2, ext3] = deal(char(simId), char(int1), ... 0176 char(int2), char(ext1), char(ext2), char(ext3)); 0177 0178 if mode == 2 | mode == 4 % Make nSim draws on the lines of inputFileName 0179 % Number of rows (simulations) in inputFileName 0180 mfname = size(simId, 1); 0181 for k = 1:mfname 0182 % Read everything into tempList 0183 tempList(k,:) = {simId(k,:), ampl(k), startSamp1(k), ... 0184 startSamp2(k), int1(k,:), int2(k,:), ext1(k,:), ... 0185 ext2(k,:), ext3(k,:)}; 0186 % tempList is used to construct a cell array of the original 0187 % data in inputFileName and is different in form from the 0188 % output list in that the start time is determined in list 0189 % (list has one less column than tempList) 0190 end 0191 % Make nSim draws on tempList 0192 [simId, ampl, startSamp1, startSamp2, int1, int2, ext1, ext2, ... 0193 ext3] = ndraws(nSim, tempList); 0194 end 0195 0196 % Determine angles 0197 internal = {int1, int2}; 0198 external = {ext1, ext2, ext3}; 0199 if mode == 1 | mode == 2 0200 [internal, external] = setangles(mode, internal, external); 0201 else 0202 [internal, external] = setangles(mode, internal, external, ... 0203 'null', detId); 0204 end 0205 0206 % Determine start times 0207 startSamp = pickstime(startSamp1, startSamp2); 0208 if isempty(startSamp) 0209 error('makelist: pickstime returned empty startSamp') 0210 end 0211 0212 for k=1:size(simId,1) 0213 % Assemble and return list: 0214 list(k,:) = {simId(k,:), ampl(k), startSamp(k), internal(k,1), ... 0215 internal(k,2), external(k,1), external(k,2), external(k,3)}; 0216 end 0217 end 0218 0219 if mode == 5 | mode == 6 % Direct variable input modes 0220 % IF variables are directly input into makelist 0221 % SET angles 0222 % SET start times 0223 % SET amplitudes 0224 % RETURN list 0225 % ENDIF 0226 0227 % Sort out angles 0228 if mode == 5 0229 [internal, external] = setangles(mode, internal, external, nSim); 0230 else % mode == 6 0231 [internal, external] = setangles(mode, internal, external, nSim, ... 0232 detId); 0233 end 0234 0235 % Set start times 0236 startSamp = pickstime(startSamp(1), startSamp(2), nSim); 0237 if isempty(startSamp) 0238 error('makelist: pickstime returned empty startSamp') 0239 end 0240 0241 % Generate amplitudes to simulate 0242 ampl = setampl(ampl, nSim); 0243 if isempty(ampl) 0244 error('makelist: setampl returned empty ampl') 0245 end 0246 0247 % Assemble list: 0248 for k = 1:nSim 0249 list(k,:) = {simId, ampl(k), startSamp(k), internal(k,1), ... 0250 internal(k,2), external(k,1), external(k,2), external(k,3)}; 0251 % Return list 0252 end 0253 end 0254 0255 return