NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/basics/gen_drog_line.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function outmat=gen_drog_line(nd,z,end_points)
2 %GEN_DROG_LINE Mouse-driven drogue input coordinate generator
3 %   GEN_DROG_LINE - Mouse-driven drogue input coordinate generator
4 %                   prompts the user to draw a line on the current
5 %                   axes and returns an array of coordinates suitable
6 %                   for a drogue initialization file.
7 %
8 %  INPUT:  nd     - number of drogues along the line.
9 %          z      - the depth to assign to the horizontal drogue
10 %                   locations. 
11 %          end_points - optional 4x1 vector defining the end points of
12 %                       the sampling lines. 
13 %                       The 4 values are [X1 Y1 X2 Y2], and if defined
14 %                       they take precedence over the mouse-driven facility.
15 %
16 % OUTPUT:  outmat - if z is supplied as input, outmat is a (nx*ny*length(z)) by 3
17 %                   array of 3-D starting locations
18 %                   if z is NOT supplied as input, outmat is a (nx*ny) by 2
19 %                   array of 2-D starting locations
20 %
21 % Call as: outmat=gen_drog_line(nd)
22 %      OR: outmat=gen_drog_line(nd,z)
23 %      OR: outmat=gen_drog_line(nd,z,end_points)
24 %
25 % Written by :Brian O. Blanton
26 % December 1998
27 %
28
29
30 nargchk(1,3,nargin)
31
32 if ~isint(nd)
33    error('first argument to gen_drog_line must be integer')
34 end
35 if nd==0
36    error('first argument to gen_drog_line cannnot be 0')
37 end
38
39 if nargin==2|nargin==3
40    if prod(size(z))~=length(z)
41       error('depth vector to gen_drog_grid must be 1-D')
42    end
43    nlev=length(z);
44 else
45    z=[];
46    nlev=0;
47 end
48
49 % if 3th arg exists, must be 1x4 or 4x1
50 if nargin==3
51    [m,n]=size(end_points);
52    if (m*n)~=4
53       error('End_points must be 4x1 or 1x4 in gen_drog_line.')
54    end
55    if m~=1&n~=1
56       error('End_Points must be 4x1 or 1x4 in gen_drog_line.')
57    end
58    % Further end point checks?? maybe
59 end
60
61 % Delete previous lines
62 delete(findobj(gca,'Tag','Gen Drog Line'))
63
64 currfig=gcf;
65 figure(currfig);
66
67 % Get line dimensions
68 if ~exist('end_points')
69    disp('Click and drag mouse to draw line');
70    WindowButtonDownFcn = get(gcf,'WindowButtonDownFcn');
71    WindowButtonMotionFcn = get(gcf,'WindowButtonMotionFcn');
72    WindowButtonUpFcn = get(gcf,'WindowButtonUpFcn');
73    set(gcf,'WindowButtonDownFcn','stretchline');   
74    waitforbuttonpress;
75    waitforbuttonpress;
76    set(gcf,'WindowButtonDownFcn',WindowButtonDownFcn, ...
77            'WindowButtonMotionFcn',WindowButtonMotionFcn, ...
78            'WindowButtonUpFcn',WindowButtonUpFcn)
79    % find box object on screen from stretchline
80    hs = findobj(gca,'Type','line','Tag','Box Lines For stretchline');
81    xdata=get(hs,'XData');
82    ydata=get(hs,'YData');
83    
84    end_points=[xdata(1) ydata(1);
85                xdata(2) ydata(2)];
86    Pt1=[end_points(1) end_points(3) NaN;
87         end_points(1) end_points(3) NaN];
88    Pt2=[end_points(2) end_points(4) NaN;
89         end_points(2) end_points(4) NaN];
90
91 %   Pt1=get(gca,'CurrentPoint');
92 %   rbbox([get(gcf,'CurrentPoint') 0 0],get(gcf,'CurrentPoint'));
93 %   Pt2=get(gca,'CurrentPoint');
94    curraxes=gca;
95 else
96    Pt1=[end_points(1) end_points(2) NaN;
97         end_points(1) end_points(2) NaN];
98    Pt2=[end_points(3) end_points(4) NaN;
99         end_points(3) end_points(4) NaN];
100    % Draw line around
101    line([Pt1(1) Pt2(1)],[Pt1(3) Pt2(3)],'Tag','Gen Drog Line')
102 end
103
104
105      
106 xstart=Pt1(1);
107 ystart=Pt1(3);
108 xend=Pt2(1);
109 yend=Pt2(3);
110
111 dx=(xend-xstart)/nd;
112 dy=(yend-ystart)/nd;
113
114 if abs(dx)<eps
115    x=xstart*ones(1,nd);
116 else
117    x=linspace(xstart,xend,nd);
118 end
119 if abs(dy)<eps
120    y=ystart*ones(1,nd);
121 else
122    y=linspace(ystart,yend,nd);
123 end
124
125 line(x,y,'LineStyle','*','Tag','Gen Drog Line')
126
127 if isempty(z)
128    outmat=[x(:) y(:)];
129 else
130    keyboard
131    X=repmat(x,[1 nlev]);
132    Y=repmat(y,[1 nlev]);
133    Z=reshape(z(:),1,nlev);
134    Z=repmat(Z,[nd 1]);
135    outmat=[X(:) Y(:) Z(:)];
136 end
137
138 if exist('/tmp')==7
139    fid = fopen('/tmp/init.dat','w');
140    [m,n]=size(outmat);
141    if n==2
142       fprintf(fid,'%f %f\n',outmat(:,1:2)');
143    else
144       fprintf(fid,'%f %f %f\n',outmat(:,1:3)');
145    end
146 end
147
148 if nargout==0
149    clear outmat
150 end
151
152 %
153 %        Brian O. Blanton
154 %        Department of Marine Sciences
155 %        15-1A Venable Hall
156 %        CB# 3300
157 %        Uni. of North Carolina
158 %        Chapel Hill, NC
159 %                 27599-3300
160 %
161 %        919-962-4466
162 %        blanton@marine.unc.edu
163 %        December 1998
164  
Note: See TracBrowser for help on using the browser.