Home > . > makelist.m

makelist

PURPOSE ^

MAKELIST - generate simulations list

SYNOPSIS ^

function list = makelist(varargin)

DESCRIPTION ^

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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.22 2004/05/18 21:16:21 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                 if length(I) == 0
0129                     file{kSim,1} = tempSimId(1:end);
0130                     file{kSim,2} = 'default';
0131                 elseif length(I) == 1
0132                     file{kSim,1} = tempSimId(1:I(1)-1);
0133                     file{kSim,2} = tempSimId(I(1)+1:end);
0134                 else
0135                     simId{kSim,:}
0136                     error('pregenlist: Invalid simId')
0137                 end
0138                 external{kSim} = {ext1{kSim}, ext2{kSim}, ext3{kSim}};   
0139             end
0140             if mode == 2 | mode == 4
0141                 list = pregenlist(nSim, file, [startSamp1(:), startSamp2(:)], external, detId);
0142                 return
0143             else
0144                 list = pregenlist(file, [startSamp1(:), startSamp2(:)], external, detId);
0145                 return
0146             end
0147             
0148         end
0149     elseif ampl <= 0 & ampl ~= -1
0150         ampl
0151         error('makelist: ampl must be > 0')
0152     end
0153     
0154     % Cast variabiles into char class from cell (this will aid in
0155     % comparing variables that may or may not be strings)
0156     [simId, int1, int2, ext1, ext2, ext3] = deal(char(simId), char(int1), ...
0157         char(int2), char(ext1), char(ext2), char(ext3));
0158     
0159     if mode == 2 | mode == 4 % Make nSim draws on the lines of inputFileName
0160         % Number of rows (simulations) in inputFileName
0161         mfname = size(simId, 1); 
0162         for k = 1:mfname
0163             % Read everything into tempList
0164             tempList(k,:) = {simId(k,:), ampl(k), startSamp1(k), ...
0165                     startSamp2(k), int1(k,:), int2(k,:), ext1(k,:), ...
0166                     ext2(k,:), ext3(k,:)};
0167             % tempList is used to construct a cell array of the original
0168             % data in inputFileName and is different in form from the
0169             % output list in that the start time is determined in list
0170             % (list has one less column than tempList)
0171         end
0172         % Make nSim draws on tempList
0173         [simId, ampl, startSamp1, startSamp2, int1, int2, ext1, ext2, ...
0174                 ext3] = ndraws(nSim, tempList);
0175     end
0176     
0177     % Determine angles
0178     internal = {int1, int2};
0179     external = {ext1, ext2, ext3};    
0180     if mode == 1 | mode == 2
0181         [internal, external] = setangles(mode, internal, external);
0182     else
0183         [internal, external] = setangles(mode, internal, external, ...
0184             'null', detId);
0185     end
0186     
0187     % Determine start times
0188     startSamp = pickstime(startSamp1, startSamp2);
0189     if isempty(startSamp)
0190         error('makelist: pickstime returned empty startSamp')
0191     end
0192     
0193     for k=1:size(simId,1)
0194         % Assemble and return list:
0195         list(k,:) = {simId(k,:), ampl(k), startSamp(k), internal(k,1), ...
0196                 internal(k,2), external(k,1), external(k,2), external(k,3)};
0197     end 
0198 end
0199 
0200 if mode == 5 | mode == 6 % Direct variable input modes
0201     % IF variables are directly input into makelist
0202     %   SET angles
0203     %   SET start times
0204     %   SET amplitudes
0205     %   RETURN list
0206     % ENDIF
0207     
0208     % Sort out angles
0209     if mode == 5 
0210         [internal, external] = setangles(mode, internal, external, nSim);
0211     else % mode == 6
0212         [internal, external] = setangles(mode, internal, external, nSim, ...
0213             detId);
0214     end
0215     
0216     % Set start times
0217     startSamp = pickstime(startSamp(1), startSamp(2), nSim);
0218     if isempty(startSamp)
0219         error('makelist: pickstime returned empty startSamp')
0220     end
0221     
0222     % Generate amplitudes to simulate
0223     ampl = setampl(ampl, nSim);
0224     if isempty(ampl)
0225         error('makelist: setampl returned empty ampl')
0226     end
0227     
0228     % Assemble list:
0229     for k = 1:nSim
0230         list(k,:) = {simId, ampl(k), startSamp(k), internal(k,1), ...
0231                 internal(k,2), external(k,1), external(k,2), external(k,3)};
0232         % Return list
0233     end
0234 end
0235 
0236 return

Generated on Tue 05-Oct-2004 10:40:50 by m2html © 2003