0001 function [d indReg indServ indRx] = framecut(d,ind, field)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 if(nargin<3)
0025 field = whichField(d, ind);
0026 end
0027
0028
0029
0030
0031
0032 [indReg, indServ, indRx] = determineInd(d, ind, field);
0033
0034
0035 [d buf] = separate_fields(d);
0036
0037
0038 d = framecutSub(d, indRx, indServ, indReg);
0039
0040
0041 d = mergestruct(d, buf);
0042 return;
0043
0044
0045
0046
0047 function d = framecutSub(d, indRx, indServ, indReg)
0048
0049 names=fieldnames(d);
0050 for i=1:length(names)
0051 if(eval(sprintf('isstruct(d.%s)',names{i})))
0052 eval(sprintf('d.%s=framecutSub(d.%s,indRx, indServ, indReg);',names{i},names{i}));
0053 else
0054 eval(sprintf('thisSize = size(d.%s,1);', names{i}));
0055 if(thisSize == length(indRx))
0056 eval(sprintf('d.%s=regcut(d.%s,indRx);',names{i},names{i}));
0057 elseif(thisSize == length(indReg))
0058 eval(sprintf('d.%s=regcut(d.%s,indReg);',names{i},names{i}));
0059 elseif(thisSize == length(indServ))
0060 eval(sprintf('d.%s=regcut(d.%s,indServ);',names{i},names{i}));
0061 else
0062 error('Do not know which dimension to cut over');
0063 end
0064 end
0065 end
0066
0067 return
0068
0069
0070 function r=regcut(r,ind)
0071
0072 switch(ndims(r))
0073 case 1
0074 r=r(ind);
0075 case 2
0076 r=r(ind,:);
0077 case 3
0078 r=r(ind,:,:);
0079 case 4
0080 r=r(ind,:,:,:);
0081 end
0082
0083 return
0084
0085
0086 function field = whichField(d, ind)
0087
0088 lind = length(ind);
0089 if(issubfield(d, 'antenna0', 'servo', 'utc'))
0090 lserv = length(d.antenna0.servo.utc);
0091 else
0092 lserv = 0;
0093 end
0094 if(issubfield(d, 'antenna0', 'receiver', 'utc'))
0095 lrec = length(d.antenna0.receiver.utc);
0096 else
0097 lrec = 0;
0098 end
0099 if(issubfield(d, 'array', 'frame', 'utc'))
0100 lnorm = length(d.array.frame.utc);
0101 else
0102 lnorm = 0;
0103 end
0104
0105
0106 if(lind == lserv)
0107 field = 'servo';
0108 elseif(lind == lrec)
0109 field = 'receiver';
0110 elseif(lind == lnorm)
0111 field = 'regular';
0112 else
0113 error('Vector over which to cut does not match dimensions in data');
0114 end
0115
0116 return;
0117
0118
0119 function [indReg, indServ, indRx] = determineInd(d, ind, field)
0120
0121 switch(field)
0122 case 'regular'
0123 indReg = ind;
0124
0125 indServ = repmat(indReg, [1 5]);
0126 indServ = indServ';
0127 indServ = indServ(:);
0128
0129 indRx = repmat(indReg, [1 100]);
0130 indRx = indRx';
0131 indRx = indRx(:);
0132
0133 case 'servo'
0134 indServ = ind;
0135
0136 indReg = reshape(indServ, [5 length(indServ)/5]);
0137 indReg = mean(indReg)~=0;
0138 indReg = indReg';
0139
0140 indRx = repmat(indServ, [1 20]);
0141 indRx = indRx';
0142 indRx = indRx(:);
0143
0144 case 'receiver'
0145 indRx = ind;
0146
0147 indReg = reshape(indRx, [100 length(indRx)/100]);
0148 indReg = mean(indReg)~=0;
0149 indReg = indReg';
0150
0151 indServ = reshape(indRx, [20 length(indRx)/20]);
0152 indServ = mean(indServ)~=0;
0153 indServ = indServ';
0154
0155 end
0156
0157 return;
0158
0159
0160
0161 function [indReg, indServ, indRx] = determineIndOld(d, ind, field)
0162
0163 halfSec = 0.5/60/60/24;
0164 tenthSec = 0.1/60/60/24;
0165
0166 switch(field)
0167 case 'regular'
0168 indReg = ind;
0169 indRx = zeros(size(d.antenna0.receiver.utc));
0170 indServ = zeros(size(d.antenna0.servo.utc));
0171
0172 times = d.array.frame.utc(ind);
0173 for m=1:length(times)
0174 f = find(d.antenna0.receiver.utc>=(times(m)-halfSec) & d.antenna0.receiver.utc<=(times(m)+halfSec));
0175 indRx(f) = 1;
0176 f = find(d.antenna0.servo.utc>=times(m)-halfSec & d.antenna0.servo.utc<=times(m)+halfSec);
0177 indServ(f) = 1;
0178 end
0179
0180 case 'receiver'
0181 indRx = ind;
0182 indServ = zeros(size(d.antenna0.servo.utc));
0183 indReg = zeros(size(d.array.frame.utc));
0184
0185 times = d.antenna0.receiver.utc(ind);
0186
0187 for m=1:length(times)
0188 f = find(d.array.frame.utc>=times(m)-halfSec & d.array.frame.utc<=times(m)+halfSec);
0189 indReg(f) = 1;
0190 f = find(d.antenna0.servo.utc>=times(m)-tenthSec & d.antenna0.servo.utc<=times(m)+tenthSec);
0191 indServ(f) = 1;
0192 end
0193
0194 case 'servo'
0195 indServ = ind;
0196 indRx = zeros(size(d.antenna0.receiver.utc));
0197 indReg = zeros(size(d.array.frame.utc));
0198
0199 times = d.antenna0.servo.utc(ind);
0200
0201 for m=1:length(times)
0202 f = find(d.array.frame.utc>=times(m)-halfSec & d.array.frame.utc<=times(m)+halfSec);
0203 indReg(f) = 1;
0204 f = find(d.antenna0.servo.utc>=times(m)-tenthSec & d.antenna0.servo.utc<=times(m)+tenthSec);
0205 indRx(f) = 1;
0206 end
0207 end
0208
0209 indRx = logical(indRx);
0210 indServ = logical(indServ);
0211 indReg = logical(indReg);
0212
0213 return;