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

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

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

Initial import of Stark code.

Line 
1 function outmat=gen_drog_grid(nx,ny,nlev,z,box_coords)
2 %GEN_DROG_GRID Mouse-driven drogue input coordinate generator
3 %
4 % GEN_DROG_GRID - Mouse-driven drogue input coordinate generator prompts
5 %                 the user to draw a box on the current figure, and returns
6 %                 an array of coordinates suitable for a drogue
7 %                 initialization file.
8 %
9 %  INPUT:  nx,ny  - number of drogues in the x and y direction (REQUIRED,
10 %                   INTEGERS).  If nx or ny==1, then the output is a
11 %                   diagonal line from between starting and ending points.
12 %          nlev   - number of vertical levels to duplicate the
13 %                   horizontal positions (OPTIONAL, DEFAULT=1, INTEGER)
14 %                   If nlev is given, then so must z.
15 %          z      - the depth to assign to the horizontal drogue
16 %                   locations.  z must be of length 1:nlev, providing
17 %                   one depth for each horizontal level.  (OPTIONAL, FLOAT)
18 %                   In this version, z must be a single
19 %                   number.  It will be used as the depth for the (nx*ny)
20 %                   horizontal locations.
21 %
22 %          box_coords - optional 4x1 vector defining the sample region. 
23 %                       The 4 values are [X1 Y1 X2 Y2], and if defined
24 %                       they take precedence over the mouse-driven facility.
25 %
26 % OUTPUT:  outmat - if z is supplied as input, outmat is a (nx*ny) by 3
27 %                   array of 3-D starting locations
28 %                   if z is NOT supplied as input, outmat is a (nx*ny) by 2
29 %                   array of 2-D starting locations
30 %
31 % Call as: outmat=gen_drog_grid(nx,ny)
32 %      OR: outmat=gen_drog_grid(nx,ny,z)
33 %      OR: outmat=gen_drog_grid(nx,ny,nlev,z)
34 %      OR: outmat=gen_drog_grid(nx,ny,nlev,z,box_coords)
35 %
36 % Written by :Brian O. Blanton
37 % Summer 1998
38 %
39
40 % Process incoming arguments
41 if nargin<2|nargin>5
42       error('Incorrect number of argument!. "help gen_drog_grid"!');
43 elseif nargin==2
44    if (~isint(nx)|~isint(ny))&(nx~=0|ny~=0)
45       error('First two arguments must be non-0 integers. "help gen_drog_grid"!');
46    end
47    z=[];;
48    nlev=[];
49 elseif nargin==3
50    if (~isint(nx)|~isint(ny))&(nx~=0|ny~=0)
51       error('First two arguments MUST be non-0 integers. "help gen_drog_grid"!');
52    end
53    % if arg==3, assume third is depth
54    z=nlev;
55    nlev=1;
56 elseif nargin==4
57    if (~isint(nx)|~isint(ny))&(nx~=0|ny~=0)
58       error('First two arguments MUST be non-0 integers. "help gen_drog_grid"!');
59    end
60    % if arg==4, assume third is nlev, check for integer, as length of z==nlev
61    if ~isint(nlev)
62       error('Number of vertical levels MUST be integer. "help gen_drog_grid"!');
63    end
64    if length(z)~=nlev
65       error('Length of z MUST equal nlev.  "help gen_drog_grid"!');
66    end
67 elseif nargout~=1
68    error('gen_drog_grid MUST have one output argument')
69 end
70
71 % if 5th arg exists, must be 1x4 or 4x1
72 if nargin==5
73    [m,n]=size(box_coords);
74    if (m*n)~=4
75       error('Box_Coords must be 4x1 or 1x4 in SAMPLE_FIELD_2D.')
76    end
77    if m~=1&n~=1
78       error('Box_Coords must be 4x1 or 1x4 in SAMPLE_FIELD_2D.')
79    end
80    % Further box coord checks??
81 end
82
83 % Delete previously drawn drog grids
84 delete(findobj(gca,'Tag','Gen Drog Grid Box'))
85 delete(findobj(gca,'Tag','Gen Drog Grid Points'))
86
87 currfig=gcf;
88 figure(currfig);
89
90 % Get Grid dimensions
91 if ~exist('box_coords')
92    disp('Click and drag mouse to cover drog patch (lower-left to upper-right)');
93    waitforbuttonpress;
94    Pt1=get(gca,'CurrentPoint');
95    rbbox([get(gcf,'CurrentPoint') 0 0],get(gcf,'CurrentPoint'));
96    Pt2=get(gca,'CurrentPoint');
97    curraxes=gca;
98 else
99    Pt1=[box_coords(1) box_coords(2) NaN;
100         box_coords(1) box_coords(2) NaN];
101    Pt2=[box_coords(3) box_coords(4) NaN;
102         box_coords(3) box_coords(4) NaN];
103 end
104
105 % Draw box around drogue grid
106 line([Pt1(1) Pt2(1) Pt2(1) Pt1(1) Pt1(1)],...
107      [Pt1(3) Pt1(3) Pt2(3) Pt2(3) Pt1(3)],'Tag','Gen Drog Grid Box')
108      
109 xstart=Pt1(1);
110 ystart=Pt1(3);
111 xend=Pt2(1);
112 yend=Pt2(3);
113
114 % If nx or ny==1, then the output is a diagonal line
115 % from (xstart,ystart) to (xend,yend)
116
117 if nx==1 | ny==1
118    n=max(nx,ny);
119    X=linspace(xstart,xend,n);
120    Y=linspace(ystart,yend,n);
121 else
122    x=linspace(xstart,xend,nx);
123    y=linspace(ystart,yend,ny);
124    X=x(:)*(ones(size(y(:)')));
125    X=X';
126    Y=y(:)*(ones(size(x(:)')));
127 end
128  
129 line(X,Y,'Marker','*','LineStyle','none','Tag','Gen Drog Grid Points')
130
131 if isempty(z)
132    X=X(:);Y=Y(:);
133    outmat=[X Y];
134 else
135    X=X(:)*ones(size(1:nlev));
136    Y=Y(:)*ones(size(1:nlev));
137    Z=ones(size(Y));
138    temp=z'*zeros(size(z));
139    temp(:,1)=z';
140    Z=Z*temp';
141    outmat=[X(:) Y(:) Z(:)];
142 end
143
144 %
145 %        Brian O. Blanton
146 %        Department of Marine Sciences
147 %        15-1A Venable Hall
148 %        CB# 3300
149 %        Uni. of North Carolina
150 %        Chapel Hill, NC
151 %                 27599-3300
152 %
153 %        919-962-4466
154 %        blanton@marine.unc.edu
155 %        Summer 1998
156  
Note: See TracBrowser for help on using the browser.