Skip to content
Snippets Groups Projects
crp2.m 49.1 KiB
Newer Older
marwan's avatar
marwan committed
      y1=y1./repmat(Dy,1,m); clear Dx Dy 
      if check_stop(hCRP,hCtrl,nogui,obj), return, end
marwan's avatar
marwan committed

marwan's avatar
marwan committed
      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Reshape Embedding Vectors'),drawnow
marwan's avatar
marwan committed

marwan's avatar
marwan committed
      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Compute Distance Matrix'),drawnow
      if m>1
         s=sqrt(sum(((x1(:,:)-y1(:,:)).^2)'));
      else
         s=abs(x1(:,1)-y1(:,1));
      end
      if check_stop(hCRP,hCtrl,nogui,obj), return, end
marwan's avatar
marwan committed

marwan's avatar
marwan committed
      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Building CRP Matrix'),drawnow
      X=reshape(uint8(255*s/max(s))<(255*e/max(s)),Ny,Nx); clear s x1 y1 
      matext=[num2str(round(100*e)/100) '\sigma (normalized distance euclidean norm)'];
marwan's avatar
marwan committed


marwan's avatar
marwan committed
      %%%%%%%%%%%%%%%%% local CRP, fixed neigbours amount
marwan's avatar
marwan committed

marwan's avatar
marwan committed
      case 5
marwan's avatar
marwan committed

marwan's avatar
marwan committed
      errcode=115;
      if e>=1 
        e=round(e)/100;
        txt=['The value for fixed neigbours amount has to be smaller '...
             'than one. Continue the computation with a value of ' ...
	     num2str(e)];
        if nogui==0
          warndlg(txt,'Threshold value mismatch');
          drawnow
          waitforbuttonpress
          set(findobj('Tag','Size','Parent',gcf),'String',num2str(e))
        end
      end
marwan's avatar
marwan committed

marwan's avatar
marwan committed
      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Reshape Embedding Vectors'),drawnow
marwan's avatar
marwan committed
      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Compute Distance Matrix'),drawnow
      if m>1
         s=sqrt(sum(((x1(:,:)-y1(:,:)).^2)'));
      else
         s=abs(x1(:,1)-y1(:,1));
      end
      if check_stop(hCRP,hCtrl,nogui,obj), return, end

      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Sort Distance Matrix'),drawnow
      mine=round(Ny*e);
      [SS, JJ]=sort(reshape(s,Ny,Nx)); JJ=JJ';
      if check_stop(hCRP,hCtrl,nogui,obj), return, end
marwan's avatar
marwan committed
      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Building CRP Matrix'),drawnow
      X1(Nx*Ny)=uint8(0); X1(JJ(:,1:mine)+repmat([0:Ny:Nx*Ny-1]',1,mine))=uint8(1);
      if check_stop(hCRP,hCtrl,nogui,obj), return, end
      X=reshape(X1,Ny,Nx); clear X1 SS JJ s
marwan's avatar
marwan committed
      matext=[num2str(round(1000*mine/Ny)/10) '% (fixed neighbours amount)'];
marwan's avatar
marwan committed

marwan's avatar
marwan committed
      %%%%%%%%%%%%%%%%% local CRP, interdependent neigbours 

      case 6

      errcode=116;
      warning('Method not available!')
      matext='';


      %%%%%%%%%%%%%%%%% order matrix

      case 7

      errcode=117;
      warning('Method not available!')
      matext='';


      %%%%%%%%%%%%%%%%% order pattern recurrence plot

      case 8

      errcode=118;

      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Compute Order Patterns'),drawnow

      % create a order pattern test
      cmdStr = '';
      for i=2:m;
          cmdStr = [cmdStr, ' permX(:,', num2str(i-1) ,') < permX(:,', num2str(i), ') + eps'];
          if i < m, cmdStr = [cmdStr, ' &']; end
      end
      if m==1
          cmdStr = '1'; 
          disp('Warning: No order patterns for dimension one; please use higher dimension!')
      end

      % order patterns by permutation of the set of values
      clear patt*
      for i=1:size(x,1)
          permX=perms(x(i,:));
          orderPattern = find(eval(cmdStr));
          if isempty(orderPattern) orderPattern = 0; end
          pattX(i) = orderPattern(1);
      end
      for i=1:size(y,1)
          permX=perms(y(i,:));
          orderPattern = find(eval(cmdStr));
          if isempty(orderPattern) orderPattern = 0; end
          pattY(i) = orderPattern(1);
      end

      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Create Order Patterns Matrix'),drawnow

      px = permute(pattX', [ 1 3 2 ]);
      py = permute(pattY', [ 3 1 2 ]);
      X = px(:,ones(1,length(y)),:) == py(ones(1,length(x)),:,:);
      X = X';
      if check_stop(hCRP,hCtrl,nogui,obj), return, end

      matext='';

      %%%%%%%%%%%%%%%%% global CRP

      case length(check_meth)

      errcode=110+length(check_meth);
      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Reshape Embedding Vectors'),drawnow

      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Compute Distance Matrix'),drawnow
      if m>1
         s=sqrt(sum(((x1(:,:)-y1(:,:)).^2)'));
      else
         s=abs(x1(:,1)-y1(:,1));
      end
      if check_stop(hCRP,hCtrl,nogui,obj), return, end

      set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'String','Building CRP Matrix'),drawnow
      X=reshape(s,Ny,Nx);
      matext='';

      end

  end % end plugin
marwan's avatar
marwan committed

  if nogui==0
    for i=1:length(obj.enable), set(obj.children(i),'Enable',obj.enable{i}); end
    set(h(1),'String','Create Recurrence Plot',...
             'ToolTip','Starts the computation - be patient.',...
             'Callback','crp2 compute')
    setptr([hCRP,hCtrl],'arrow')
  end

  %%%%%%%%%%%%%%%%% show CRP 
marwan's avatar
marwan committed

marwan's avatar
marwan committed
  if nogui==0
     Shuttle.hCRP=hCRP;
     Shuttle.hCtrl=hCtrl;
     Shuttle.matext=matext;
     Shuttle.xscale=xscale;
     Shuttle.yscale=yscale;
     Shuttle.mflag=mflag;
     Shuttle.m=m;
     Shuttle.t=t;
     Shuttle.cm=cm;
     Shuttle.txt_cross=txt_cross;
     show_crp(X,Shuttle)
 else
marwan's avatar
marwan committed
   if nargout==1, xout=X; end
marwan's avatar
marwan committed
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
 end

 if strcmpi(get(findobj('Tag','SetPoint','Parent',hCtrl),'Enable'),'off')
     set(findobj('Tag','TextLOSsearch','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','SetPoint','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','ClearPoint','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','ClearAllPoint','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','LOSwidthXtext','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','LOSwidthX','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','LOSwidthYtext','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','LOSwidthY','Parent',hCtrl),'Enable','On')
     set(findobj('Tag','Apply2','Parent',hCtrl),'Enable','On')
 end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% store2

  case 'store2'
  
  errcode=15;
  t=get(findobj('Tag','Apply2','Parent',hCtrl),'UserData');
  if isempty(t)
     warndlg('The LOS vector is still empty. Please start the computation of the LOS before storing.','No LOS')
     waitforbuttonpress
  else
     assignin('base','t_out', t)
  end

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOSmove

  case 'LOSmove'
  
  errcode=16;
  if isempty(get(gco,'UserData'))
    set(gco,'UserData',1,'ButtonDownFcn','crp2 LOSmove_end')
    set(gcf,'WindowButtonMotionFcn','crp2 LOSmove')
  end
  h1 = round(get(gca,'CurrentPoint'));
  set(gco, 'XData', h1(1,1), 'YData', h1(1,2))
  clear h1

  case 'LOSmove_end'
  errcode=161;
  if ~isempty(get(gco,'UserData'))
    set(gco,'UserData',[],'ButtonDownFcn','')
    set(gcf,'WindowButtonMotionFcn','')
  end
    
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOSclear

  case 'LOSclear'
  
  errcode=17;
  if gcf==hCtrl
    figure(hCRP)
    k=waitforbuttonpress;
    h1 = round(get(gca,'CurrentPoint')); h1(2,:)=[]; h1(:,3)=[];
    finalRect = rbbox;
    h2 = round(get(gca,'CurrentPoint')); h2(2,:)=[]; h2(:,3)=[];
    h(1,1)=min(h1(:,1),h2(:,1));h(2,1)=max(h1(:,1),h2(:,1));
    h(1,2)=min(h1(:,2),h2(:,2));h(2,2)=max(h1(:,2),h2(:,2));
    
    i=find(fixp(:,1)>=h(1,1) & fixp(:,2)>=h(1,2) & fixp(:,1)<=h(2,1) & fixp(:,2)<=h(2,2));
    for j=1:length(i); delete(findobj('tag','fixp','Parent',findobj('Parent',hCRP,'Tag','CRPPlot'),'xdata',fixp(i(j),1))), end
  else
    h(1,1)=get(gco,'XData');h(1,2)=get(gco,'YData');
    delete(gco)
  end
  clear h

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOSallclear

  case 'LOSallclear'
  
    errcode=171;
    delete(findobj('tag','fixp','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')))
  
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOSset

  case 'LOSset'
  
  errcode=18;
  if gcf==hCtrl
    figure(hCRP)
    ginput(1);
  end
  
  h=round(get(gca,'currentp'));
  fixp(end+1,1)=h(1,1); fixp(end,2)=h(1,2);
  [i j]=sort(fixp(:,1));
  fixp=fixp(j,:);
  h0=uicontextmenu;
  line(h(1,1),h(1,2),1000,...
       'MarkerSize',12,...
       'Marker','.',...
       'Color',[1 0 0],...
       'Tag','fixp',...
       'UIContextMenu',h0)
  uimenu(h0, 'Label', 'Set Point', 'Callback', 'crp2 LOSset')
  uimenu(h0, 'Label', 'Move Point', 'Callback', 'crp2 LOSmove')
  uimenu(h0, 'Label', 'Clear Point', 'Callback', 'crp2 LOSclear')
  clear h h0

 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LOSsearch

  case 'LOSsearch'

  errcode=19;
  if nogui==0
    setptr([hCRP,hCtrl],'watch')
    h=findobj('Tag','Apply2','Parent',hCtrl);
    obj.children=get(hCtrl,'Children');
    obj.enable=get(obj.children,'Enable'); 
    set(obj.children,'Enable','off')
    set(h(1),'String','Stop',...
             'ToolTip','Stops the computation.',...
             'Enable','on',...
	     'Callback','set(gcbo,''String'',''Stopped'')')
  end
  x0=0;
  y0=0;
  Dmax1=str2num(get(findobj('Tag','LOSwidthX','Parent',hCtrl),'string'));
  Dmax2=str2num(get(findobj('Tag','LOSwidthY','Parent',hCtrl),'string'));
  X=double(get(findobj('Tag','CRPData','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')),'UserData'));
  
  N=size(X); Nleer=0; Nvoll=0;

  minvalue=min(min(X));maxvalue=max(max(X));
  if (length(find(X==minvalue))+length(find(X==maxvalue))==length(X(:)))

  flagpoint=0;
   
% looks for the beginning of the diagonal LOS

  errcode=191;
  for i=1:N(2);
    if check_stop_LOS(hCRP,hCtrl,nogui,obj), break, end
    if i<=N(1)
      if ~isempty(fixp), if i>=fixp(1,1), x0=fixp(1,1); y0=fixp(1,2); end, end
      if X(i+y0,1+x0)~=0 
        v=i+y0;
        h=1+x0;
        break
      end
    end
    if X(1+y0,i+x0)~=0
      h=i+x0;
      v=1+y0;
      break
    end
  end
  
  Nleer=i-1;
%  t(1:v)=h;
  t(1+x0:h)=v;

% start estimation of the LOS

  errcode=192;
  mflag=0;
  i=2;
%  h_wait=waitbar(0,'Compute LOS ...',props.window);
  h_wait=waitbar(0,'Compute LOS ...');
  set(h_wait,'HandleVisibility','on');

  while h<N(2)-1 & v<N(1)-1 & mflag~=1,
    waitbar(h/N(2))
    if check_stop_LOS(hCRP,hCtrl,nogui,obj), break, end

    dw=1;

    W=X(v:v+dw,h:h+dw);
    W(1,1)=0; 

    if ~isempty(fixp)
      if find(h==fixp(:,1))
        dv=fixp(find(h==fixp(:,1)),2)-v;
        dh=1; 
        flagpoint=1;
      end
    end

    if flagpoint==0;

% looks for the existence of the next recurrence point in diagonal direction

    errcode=193;
    while sum(sum(W))==0 & mflag==0 & flagpoint==0,
      Nleer=Nleer+1;
      if ~isempty(fixp)
        if find(h+dw==fixp(:,1))
	  dv=fixp(find(h+dw==fixp(:,1)),2)-v;
  	  W=1; dh=dw;
	  flagpoint=1;
	  break
        end
      end
      dw=dw+1;
      if v+dw < N(1) & h+dw < N(2)
         W=X(v:v+dw,h:h+dw);
         W(1,1)=0; 
      else
         mflag=1;
      end
    end

    if mflag==1
      break
    end

% determines the coordinates of the next recurrence point
  
    errcode=194;
    dh0=min(find(sum(W)));
    dv0=min(find(sum(W')));
    dh=min(find(W(dv0,:)));
    dv=min(find(W(:,dh0)));
    if dh>dh0, dh=dh0;end
    if dv>dv0, dv=dv0;end
  

% determines the local width of the diagonal LOS

    errcode=195;
    dh1=dh;
    dv1=dv;
    
    
    % neues Fenster
    WL1=Dmax1;
    WL2=Dmax2;
    if v+dv1-2+WL2>=N(1), WL2=N(1)-(v+dv1-2); end
    if h+dh1-2+WL1>=N(2), WL1=N(2)-(h+dh1-2); end
    Wn=X(v+dv1-1:v+dv1-2+WL2,h+dh-1:h+dh-2+WL1);
    % Schwerpunkt davon ausrechnen
    if sum(sum(Wn))~=0, Sh=sum(sum(Wn).*[1:WL1])/sum(sum(Wn));else Sh=WL1/2;end
    if sum(sum(Wn'))~=0,Sv=sum(sum(Wn').*[1:WL2])/sum(sum(Wn'));else Sv=WL2/2;end
    % neue Dmax berechnen
    if Sh>=Sv, Dmax2n=WL1*Sv/Sh; Dmax1n=WL1; end
    if Sv>Sh,  Dmax1n=WL2*Sh/Sv; Dmax2n=WL2; end

%    while X(v+dv1-1,h:dh-1)==1 & v+dv1-1<N(1) &dv1<Dmax2

    while X(v+dv1-1,h+dh-1)==1 & v+dv1-1<N(1) &dv1<Dmax2n
     dv1=dv1+1;
    end
%    while X(v:dv-1,h+dh1-1)==1 & h+dh1-1<N(2) & dh1<Dmax1
    while X(v+dv-1,h+dh1-1)==1 & h+dh1-1<N(2) & dh1<Dmax1n
      if ~isempty(fixp)
        if find(h+dh1-1==fixp(:,1)) & find(h+fix((dh1+dh)/2)==fixp(:,1))
          dv=fixp(find((h+dh1-1)==fixp(:,1)),2)-v;
	  if isempty(dv), dv=fixp(find((h+fix((dh1+dh)/2))==fixp(:,1)),2)-v; end
          flagpoint=1;
          break
        end
      end
      dh1=dh1+1;
    end


% compute the mean of the diagonal LOS
  
    errcode=196;
    if flagpoint==0
      dh=fix((dh1+dh)/2);
      dv=fix((dv1+dv)/2);

      if dh>0
        dh=dh-1;
      end
      if dv>0
        dv=dv-1;
      end
%      dh=dh+dh1;
    end
    
    end % flagpoint end
    flagpoint=0;


% output
    if dh~=0 & dv~=0
      t(h:h+dh)=v:dv/dh:v+dv;
    elseif dv~=0
      t(h)=v+dv;
    elseif dv==0
      t(h:h+dh)=v;
    end
    Nvoll=Nvoll+sqrt(dv^2+dh^2);

    if dh==0 & dv==0
      dh=1;
    end

% moves the startpoint for further looking
    h=h+dh;
    v=v+dv;

  end

  else
% DTW algorithm

   h_wait=waitbar(0,'Compute LOS ...');
   set(h_wait,'HandleVisibility','on',props.window);
  
   t=1;
   i=y0+1; j=x0+1;
   flag2=0;
   while i<N(1)-Dmax1-1 & j<N(2)-Dmax2-1
     errcode=197;
     waitbar(i/N(1)), j0=j;
%     [temp pos]=min([sum(sum(X(i:i+Dmax1,j+1:j+1+Dmax2))),sum(sum(X(i+1:i+1+Dmax1,j+1:j+1+Dmax2))),sum(sum(X(i+1:i+1+Dmax1,j:j+Dmax2)))]);
     [temp pos]=min([(mean(X(i,j+1:j+1+Dmax2))),(mean(diag(X(i+1:i+1+Dmax1,j+1:j+1+Dmax2)))),(mean(X(i+1:i+1+Dmax1,j)))]);
     switch(pos)
       case 1
        j=j+1;
	flag1=1;
       case 2
        i=i+1; j=j+1;
	flag1=1;
	flag2=1;
       case 3
        i=i+1;
	flag2=1;
     end
     if ~isempty(fixp) & flag1==1 & flag2==1
       errcode=1981;
       h=find(fixp(:,1)==j);
       if ~isempty(h) & i<max(fixp(h,2)); 
       h2=find(i<=fixp(h,2)); 
       i=fixp(h(h2(1)),2);  flag1=0; end
     end
     if ~isempty(fixp) & flag2==1 & flag1==1
       errcode=1982;
       h=find(fixp(:,2)==i);
       if ~isempty(h) & j<max(fixp(h,1)); 
       h2=find(j<=fixp(h,1));
       j=fixp(h(h2(1)),1);
       t(j0:j-1)=t(j0);
       flag2=0; end
     end
     t(j)=i;

   end

   t(find(~t))=1;

  end

  delete(h_wait)
  errcode=199;
  
  h1=findobj('Parent',hCRP,'Tag','CRPPlot');
  h2=findobj('Tag','Diagonal','Parent',h1);
  if isempty(h2)
    h2=line('Parent',h1,'visible','on','Tag','Diagonal','color',[1 0 0],...
    'LineWidth',1);
  end
  set(h2,'xdata',[1:length(t)],'ydata',t,'visible','on')
  set(findobj('Tag','Apply2','Parent',hCtrl),'UserData',t)
  if nogui==0
    setptr([hCRP,hCtrl],'arrow')
    h=findobj('Tag','Apply2','Parent',hCtrl);
    set(h(1),'String','Apply',...
     	         'ToolTip','Searches the LOS.',...
	         'Callback','crp2 LOSsearch')
    for i=1:length(obj.enable), set(obj.children(i),'Enable',obj.enable{i}); end
  end
  set(findobj('Tag','Store2','Parent',hCtrl),'Enable','On') 

end
try, set(0,props.root), end
warning on
set(0,'ShowHidden','Off')

%%%%%%% error handling

marwan's avatar
marwan committed
%if 0
catch
marwan's avatar
marwan committed
  try, if nogui==0
    for i=1:length(obj.enable), set(obj.children(i),'Enable',obj.enable{i}); end
    set(h(1),'String','Apply',...
             'ToolTip','Starts the computation - be patient.',...
             'Callback','crp compute')
    setptr([hCRP,hCtrl],'arrow')
  end, end
  z=whos;x=lasterr;y=lastwarn;in=varargin{1};
  print_error('crp2',z,x,y,in,mflag,action)
  try, set(0,props.root), end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function out=check_stop_LOS(hCRP,hCtrl,nogui,obj)

    global errcode
    errcode=errcode+.02;
    out=0;
    if nogui==0
      h=findobj('Tag','Apply2','Parent',hCtrl);
      if strcmpi(get(h(1),'String'),'stopped')
        set(h(1),'String','Apply',...
     	         'ToolTip','Searches the LOS.',...
	         'Callback','crp2 LOSsearch')
        for i=1:length(obj.enable), set(obj.children(i),'Enable',obj.enable{i}); end
        set(findobj('Tag','Status','Parent',findobj('Parent',hCRP,'Tag','CRPPlot')'),'String','Stopped'),drawnow
        setptr([hCRP,hCtrl],'arrow')
        out=1;
      end
    end