0001 function [transect] = transect_nodes_screen(Mobj,VarType)
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 subname = 'transect_nodes_screen';
0034 global ftbverbose
0035 if(ftbverbose)
0036 fprintf('\n')
0037 fprintf(['begin : ' subname '\n'])
0038 end;
0039
0040
0041
0042
0043 if(lower(Mobj.nativeCoords(1:3)) == 'car')
0044 x = Mobj.x;
0045 y = Mobj.y;
0046 else
0047 x = Mobj.lon;
0048 y = Mobj.lat;
0049 end;
0050
0051 figure
0052 patch('Vertices',[x,y],'Faces',Mobj.tri,...
0053 'Cdata',Mobj.h,'edgecolor','k','facecolor','interp');
0054 hold on;
0055 plot(x(1316),y(1316),'ro')
0056
0057
0058 [xselect] = ginput2(true,'k+')
0059 [npts,jnk] = size(xselect);
0060
0061 if(npts == 0)
0062 fprintf('you didn''t select any points')
0063 fprintf(['end : ' subname '\n'])
0064 return
0065 end;
0066 fprintf('you selected %d points\n',npts)
0067
0068
0069 for i=1:npts
0070 [ipt(i),dist] = find_nearest_pt(xselect(i,1),xselect(i,2),Mobj);
0071 end;
0072
0073
0074 plot(x(ipt),y(ipt),'ro');
0075
0076 transect.x=[];
0077 transect.y=[];
0078 transect.idx=[];
0079 for i=1:npts-1
0080 dI=1;
0081 keepgoing=1;
0082 while keepgoing
0083 dx=diff(x([ipt(i),ipt(i+1)]));
0084 dy=diff(y([ipt(i),ipt(i+1)]));
0085 datadxy=[dx,dy];
0086 [~,direction]=max(abs([dx,dy]));
0087 data=circshift([x([ipt(i),ipt(i+1)]),y([ipt(i),ipt(i+1)])],[0,direction-1]);
0088 datadxy= circshift( datadxy,[0,direction-1]);
0089 dataXI=data(1,1):datadxy(1)/dI:data(end,1);
0090 dataYI = interp1(data(:,1),data(:,2),dataXI);
0091 dataI=circshift([dataXI(:),dataYI(:)],[0,direction-1]);
0092 plot(dataI(:,1),dataI(:,2),'yx');
0093 idx=nan*ones(1,length(dataI));
0094 for ii=1:length(dataI)
0095 [idx(ii),~] = find_nearest_pt(dataI(ii,1),dataI(ii,2),Mobj);
0096 end;
0097
0098 [~,igood]=unique(idx);
0099 if length(igood)~=length(idx)
0100
0101 keepgoing=0;
0102 else
0103
0104 dI=dI*2;
0105 disp('Increasing resolution of transect')
0106 end
0107 idx= idx(sort(igood));
0108 checkelems={};
0109
0110
0111 for ii=1:length(idx)
0112 checkelems{ii,1}=find(Mobj.tri(:,1)==idx(ii));
0113 checkelems{ii,2}=find(Mobj.tri(:,2)==idx(ii));
0114 checkelems{ii,3}=find(Mobj.tri(:,3)==idx(ii));
0115
0116 end
0117
0118 unique_elems=unique(sort(cat(1,checkelems{:})));
0119 cc=1;newidx=zeros(length(unique_elems),2);
0120 for ii=1:length(unique_elems)
0121 test4nodes=zeros(1,3);
0122 for rr=1:3
0123 test= find(idx==Mobj.tri(unique_elems(ii),rr));
0124 if ~isempty(test);
0125 test4nodes(rr)=test;
0126 end
0127 end
0128 switch length(find(test4nodes))
0129 case 2
0130
0131 newidx(cc,1:2)=test4nodes(find(test4nodes));
0132 cc=cc+1;
0133 case 3
0134 disp(['Too many nodes in element ',num2str(ii)])
0135 disp('Removing the middle node as locations are in order')
0136
0137 newidx(cc,1:2)=test4nodes([1,3]);
0138 cc=cc+1;
0139 end
0140 end
0141 newidx=unique(newidx(:));
0142 newidx=newidx(find(newidx));
0143 if length(newidx)==length(idx)
0144 disp('All nodes are linked, continue to next section')
0145 keepgoing=0;
0146
0147 transect.x=[transect.x;x(idx)];
0148 transect.y=[transect.y;y(idx)];
0149 transect.idx=[transect.idx;idx(:)];
0150 plot(transect.x,transect.y,'wo');
0151
0152 else
0153 disp('Mising linked nodes in transect, continue with increased resolution')
0154 keepgoing=1;
0155 end
0156 end
0157 end
0158
0159 transect.x=unique(transect.x);
0160 transect.y=unique(transect.y);
0161 transect.idx=unique(transect.idx);
0162 return