0001 function internal = setinternal(mode, preInternal, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 internal = [];
0040
0041
0042 if mode == 1 | mode == 2 | mode == 3 | mode == 4
0043
0044
0045
0046
0047
0048
0049 [int1, int2] = deal(preInternal{1}, preInternal{2});
0050
0051
0052 for k = 1:size(int1, 1)
0053
0054 if strcmp(upper(int1(k,:)), 'RANDOM') | ...
0055 strcmp(upper(int1(k,:)), 'RANDOM ')
0056
0057 tempInt1(k,1) = randomangle(1, 'x');
0058 elseif strcmp(upper(int1(k,:)), 'OPTIMAL')
0059
0060 tempInt1(k,1) = 1;
0061 else
0062
0063 tempInt1(k,1) = str2double(int1(k,:));
0064
0065 if isnan(tempInt1(k,1))
0066 int1 = int1(k,:)
0067 error('makelist -> setinternal: Error reading int1')
0068 end
0069 end
0070
0071 if strcmp(upper(int2(k,:)), 'RANDOM') | ...
0072 strcmp(upper(int2(k,:)), 'RANDOM ')
0073
0074 tempInt2(k,1) = randomangle(1, 'phi');
0075 elseif strcmp(upper(int2(k,:)), 'OPTIMAL')
0076
0077 tempInt2(k,1) = 0;
0078 else
0079
0080 tempInt2(k,1) = str2double(int2(k,:));
0081
0082 if isnan(tempInt2(k,1))
0083 int2 = int2(k,:)
0084 error('makelist -> setinternal: Error reading int2')
0085 end
0086 end
0087 end
0088
0089 internal = [tempInt1, tempInt2];
0090
0091
0092 elseif mode == 5 | mode == 6
0093
0094
0095 if length(varargin) >= 1
0096 nSim = varargin{1};
0097 else
0098 error(['makelist -> setinternal: Need to know number of '...
0099 'internal angles to generate (nSim)'])
0100 end
0101
0102 if strcmp(class(preInternal), 'char')
0103 if strcmp(upper(preInternal), 'RANDOM')
0104
0105 internal = [randomangle(nSim, 'x'), randomangle(nSim, 'phi')];
0106
0107 elseif strcmp(upper(preInternal), 'OPTIMAL')
0108
0109 internal = repmat([1, 0], nSim, 1);
0110
0111 else
0112 internal = preInternal
0113 error(['makelist -> setinternal: internal must be 1x2 vector '...
0114 'or string ''RANDOM'' or ''OPTIMAL'''])
0115 end
0116 elseif strcmp(class(preInternal), 'double')
0117
0118 internal = repmat(preInternal, nSim, 1);
0119
0120 elseif strcmp(class(preInternal), 'struct')
0121 if ~isfield(preInternal, 'x') | ~isfield(preInternal, 'phi')
0122 internal = preInternal
0123 error(['makelist -> setinternal: The internal struct must '...
0124 'have fields x and phi'])
0125 end
0126
0127 internal = repmat([preInternal.x, preInternal.phi], nSim, 1);
0128
0129 else
0130 internal = preInternal
0131 error(['makelist -> setinternal: Class type of internal must ' ...
0132 'be double, struct or char'])
0133 end
0134
0135 end
0136
0137
0138 check = find(abs(internal(:,1)) > 1);
0139 if ~isempty(check)
0140 int1 = internal(:,1)
0141 error(['makelist -> setinternal: The first internal angle is out of ' ...
0142 'range: (-1 1)'])
0143 end
0144
0145 check = find(internal(:,2) < -pi | internal(:,2) > pi);
0146 if ~isempty(check)
0147 int2 = internal(:,2)
0148 error(['makelist -> setinternal: The second internal angle is out of '...
0149 'range: (-pi pi)'])
0150 end
0151
0152 return