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

root/gliderproc/trunk/MATLAB/opnml/VIZICQ4_1.2/vizicq4_guts.m

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

Initial import of Stark code.

Line 
1 function vizicq4_guts(command,option)
2 %THIS IS THE guts OF VIZICQ4;  IT IS NOT CALLED DIRECTLY,
3 %BUT IS CALLED VIA CALLBACKS AND BUTTON DEFINITIONS
4 %
5
6 get_VIZICQ4_handles;
7
8 setptr(VIZICQ4_Figure,'watch')
9
10 switch command
11
12 case 'initialize',       
13 %%%
14 %%%  INITIALIZATION CALLS
15 %%%
16    % option must exist and be a structure as:
17    % option.grid=fem_grid_struct;
18    % option.icq4=icq4name;
19    % on initialization
20    if ~exist('option')
21       error('vizicq4_guts improperly called on init with non-struct option.')
22    elseif ~isstruct(option)
23       error('option to vizicq4_guts on init is not a structure')
24    else
25       if ~isfield(option,'grid')| ~isfield(option,'icq4')
26          disp('option struct to vizicq4_guts does not contain ')
27          disp('a fem_grid_struct and/or an icq4 filename')
28          return
29       end
30    end
31    
32 case 'Load_Grid'   
33    % Load the grid, and set the VIZICQ4_Grid_Axes  UserData to contain
34    % the fem_grid_struct
35    % Get the domain name typed into the "Domain :" ui
36    domainname=get(VIZICQ4_Current_Domain,'String');
37    if strcmp(domainname,'<enter domain name>')
38       vizicq4_guts('Error','Domain Name not set.');
39       return
40    end
41    % Try to load the grid files
42    set(VIZICQ4_Info_Text,'String',['Loading grid for ' domainname])
43    drawnow
44    fem_grid_struct=loadgrid(domainname);
45    if isempty(fem_grid_struct)
46       vizicq4_guts('Error',['Grid files not found for ' domainname]);
47       return
48    end
49    % Ensure fem_grid_struct is valid
50    if ~is_valid_struct(fem_grid_struct)
51       errstr=['Invalid fem_grid_struct in VIZICQ4_Current_Domain for '  domainname];
52       vizicq4_guts('Error',errstr);
53       return
54    end
55
56    % Force negative depths!!
57    fem_grid_struct.z=-fem_grid_struct.z;
58    
59    % Attach element finding arrays
60    fem_grid_struct=belint(fem_grid_struct);
61    
62    % Attach valid fem_grid_struct to figure UserData
63    set(VIZICQ4_Grid_Axes,'UserData',fem_grid_struct)
64    axes(VIZICQ4_Grid_Axes);
65    drawelems(fem_grid_struct);
66    plotbnd(fem_grid_struct);
67    set(VIZICQ4_Error_Text,'String','')
68    axes(VIZICQ4_Slice_Axes);
69    drawelems3d(fem_grid_struct);
70    plotbnd(fem_grid_struct);
71 %   hb=plotbnd(fem_grid_struct);
72
73    % Load default region limits into place
74    xmin=min(fem_grid_struct.x);
75    xmax=max(fem_grid_struct.x);
76    ymin=min(fem_grid_struct.y);
77    ymax=max(fem_grid_struct.y);
78    set(VIZICQ4_Region_Xmin,'String',xmin,'Enable','on')
79    set(VIZICQ4_Region_Xmax,'String',xmax,'Enable','on')
80    set(VIZICQ4_Region_Ymin,'String',ymin,'Enable','on')
81    set(VIZICQ4_Region_Ymax,'String',ymax,'Enable','on')
82    axes(VIZICQ4_Grid_Axes)
83    line([xmin xmax xmax xmin xmin],...
84         [ymin ymin ymax ymax ymin],'Tag','VIZICQ4_Region_Box')
85    set(VIZICQ4_Info_Text,'String','Load in a .icq4 file.')
86    
87 case 'Clear'
88    switch option
89       case 'Vectors'
90          delete(findobj(VIZICQ4_Figure,'Tag','VIZICQ4_Vectors'))
91       case 'Volumes'
92          delete(findobj(VIZICQ4_Figure,'Tag','VIZICQ4_Volume'))
93       case 'HSlices'
94          delete(findobj(VIZICQ4_Figure,'Tag','VIZICQ4_Ribbon_HSlice'))
95       case 'VSlices'
96          delete(findobj(VIZICQ4_Figure,'Tag','VIZICQ4_Ribbon_VSlice'))
97       otherwise,
98          vizicq4_guts('Error','Bad Option to VIZICQ4_GUTS -->> Clear')
99          setptr(VIZICQ4_Figure,'arrow')
100          return     
101    end   
102    
103 case 'RotateRegion'
104
105    theta=eval(get(VIZICQ4_DELTA_THETA,'String'))*pi/180;
106    if abs(theta)<1e-3
107       vizicq4_guts('Error','Theta too small.');
108       break;
109    end
110    sign=-1;
111    if strcmp(option,'CCW'),sign=1;,end
112
113
114 case 'Error'
115    set(VIZICQ4_Error_Text,'String',option)
116    set(VIZICQ4_Info_Text,'String','')
117    
118 case 'Info'
119    set(VIZICQ4_Info_Text,'String',option)
120    set(VIZICQ4_Error_Text,'String','')
121    
122 case 'Load_Icq4'   
123    dirname=get(VIZICQ4_Current_Icq4_Dir,'String');
124    set(VIZICQ4_Error_Text,'String','')
125    set(VIZICQ4_Info_Text,'String','Reading .icq4 file...')
126    drawnow
127    switch option
128    case 'Directory'
129       % get directory name from VIZICQ4_Current_Icq4_Dir
130       if exist(dirname)~=7
131          vizicq4_guts('Info','');
132          vizicq4_guts('Error',[dirname ' does not exist.']);
133          return
134       end
135       % if dirname DOES exist, create a filelist of *.icq4 contents,
136       % and change the style of VIZICQ4_Current_Icq4_Name to listbox
137       % to allow mouse selection of .icq4 filename.
138       d=dir([dirname '/*.icq4']);
139       filenames={d.name}';
140       if isempty(filenames)
141          vizicq4_guts('Info','');
142          set(VIZICQ4_Error_Text,'String','No .icq4 files in directory.')
143         return
144       end
145       set(VIZICQ4_Current_Icq4_Name,'Style','listbox',...
146                                     'String',filenames,...
147                                     'UserData',filenames,...
148                                     'Position',[0.78 .875 .18 .08])
149                                        
150    case 'Name'
151       %
152       % Determine style of VIZICQ4_Current_Icq4_Name ui
153       %
154       style=get(VIZICQ4_Current_Icq4_Name,'Style');
155       if strcmp(style,'edit')
156          icq4name=get(VIZICQ4_Current_Icq4_Name,'String');
157       else
158          filelist=get(VIZICQ4_Current_Icq4_Name,'UserData');
159          value=get(VIZICQ4_Current_Icq4_Name,'Value');
160          icq4name=filelist{value};
161       end
162      
163       % Load the .icq4 file, and set the VIZICQ4_Slice_Axes UserData to contain
164       % the fem_icq4_struct
165       % Get the icq4 filename typed into the "Icq4 name: " ui
166      
167       fullname=[dirname '/' icq4name];
168      
169       if ~exist(fullname)
170          vizicq4_guts('Error',[icq4name ' does not exist.']);
171          % Enable uigetfile
172          [fname,fpath]=uigetfile('*.icq4','Select .icq4 file');
173          if fname==0
174             vizicq4_guts('Info','No .icq4 file selected.');
175             return
176          else
177             fullname=[fpath '/' fname];
178             set(VIZICQ4_Current_Icq4_Name,'String',fname);
179             vizicq4_guts('Error','');
180             icq4name=fname;
181          end
182       end
183       fem_icq4_struct=read_icq4(fullname);
184      
185      
186       % Compute density from Q4_EQNSTATE2
187       fem_icq4_struct.RHO=q4_eqnstate2(fem_icq4_struct.TMPMID,fem_icq4_struct.SALMID);
188       set(VIZICQ4_Info_Text,'String',[icq4name ' read.'])
189       set(VIZICQ4_icq4_select_button,'enable','on')
190       set(VIZICQ4_Slice_Axes,'UserData',fem_icq4_struct);
191     otherwise
192        disp('Option hole in switch in vizicq4_guts, LoadIcq4')
193     end
194 case 'Icq4_Info'
195    fem_icq4_struct=get(VIZICQ4_Slice_Axes,'UserData');
196    if isempty(fem_icq4_struct)
197       set(VIZICQ4_Icq4_Info_Fig,'Visible','off');
198    else
199       % Toggle visibility of info figure
200       state=get(VIZICQ4_Icq4_Info_Fig,'Visible');
201       if strcmp(state,'on')
202          set(VIZICQ4_Icq4_Info_Fig,'Visible','off');
203          setptr(VIZICQ4_Figure,'arrow')
204          break;
205       else
206          set(VIZICQ4_Icq4_Info_Fig,'Visible','on');
207       end
208       nn=fem_icq4_struct.nn;
209       nnv=fem_icq4_struct.nnv;
210      
211       set(VIZICQ4_Icq4_Info_Line(1),'String',fem_icq4_struct.codename)
212       set(VIZICQ4_Icq4_Info_Line(2),'String',fem_icq4_struct.casename)
213       set(VIZICQ4_Icq4_Info_Line(3),'String',fem_icq4_struct.inqfilename)
214       set(VIZICQ4_Icq4_Info_Line(4),'String',fem_icq4_struct.initcondname)
215       set(VIZICQ4_Icq4_Info_Line(5),'String',int2str(nn))
216       set(VIZICQ4_Icq4_Info_Line(6),'String',int2str(nnv))
217       set(VIZICQ4_Icq4_Info_Line(7),'String',int2str(fem_icq4_struct.day))
218       set(VIZICQ4_Icq4_Info_Line(8),'String',int2str(fem_icq4_struct.month))
219       set(VIZICQ4_Icq4_Info_Line(9),'String',int2str(fem_icq4_struct.year))
220       set(VIZICQ4_Icq4_Info_Line(10),'String',int2str(fem_icq4_struct.curr_seconds))
221       string2d=['[' int2str(nn)  ' double]'];
222       string3d=['[' int2str(nn) 'x' int2str(nnv) ' double]'];
223       set(VIZICQ4_Icq4_Info_Line(11),'String',string3d)
224       set(VIZICQ4_Icq4_Info_Line(12),'String',string3d)
225       set(VIZICQ4_Icq4_Info_Line(13),'String',string3d)
226       set(VIZICQ4_Icq4_Info_Line(14),'String',string3d)
227       set(VIZICQ4_Icq4_Info_Line(15),'String',string3d)
228       set(VIZICQ4_Icq4_Info_Line(16),'String',string3d)
229       set(VIZICQ4_Icq4_Info_Line(17),'String',string3d)
230       set(VIZICQ4_Icq4_Info_Line(18),'String',string3d)
231       set(VIZICQ4_Icq4_Info_Line(19),'String',string3d)
232
233    end
234    
235 case 'Toggle_Axes'
236    % Determine which axes is currently visible
237    state=get(VIZICQ4_Grid_Axes,'Visible');
238    invisaxstdpos=get(VIZICQ4_LabCont,'UserData');
239    axstdpos=get(VIZICQ4_DelCont,'UserData');
240    if strcmp(state,'on')
241       set(VIZICQ4_Grid_Axes,'Visible','off')
242       set(VIZICQ4_Slice_Axes,'Visible','on')
243       set(VIZICQ4_Grid_Axes,'Position',invisaxstdpos)
244       set(VIZICQ4_Slice_Axes,'Position',axstdpos)
245    else
246       set(VIZICQ4_Grid_Axes,'Visible','on')
247       set(VIZICQ4_Slice_Axes,'Visible','off')
248       set(VIZICQ4_Grid_Axes,'Position',axstdpos)
249       set(VIZICQ4_Slice_Axes,'Position',invisaxstdpos)
250    
251    end
252    
253 case 'Terminate'
254    delete([VIZICQ4_Figure VIZICQ4_Volume_Fig VIZICQ4_Slicer_Fig VIZICQ4_Icq4_Info_Fig])
255    return
256 case 'print'
257    disp('No print function yet')
258 case 'Help'
259 %   switch option
260    disp('No help yet')   
261
262 case 'ZContours'
263    fem_grid_struct=get(VIZICQ4_Grid_Axes,'UserData');
264    if isempty(fem_grid_struct)
265       vizicq4_guts('Error','No grid defined yet.')
266       break
267    end
268    vals=get(VIZICQ4_Contour_Vals,'String');
269    if strcmp(vals,'linspace(zmin,zmax,7)')
270      % Determine default depth contour values
271       zmax=max(fem_grid_struct.z);
272       zmin=min(fem_grid_struct.z);
273       vals=linspace(zmin,zmax,7);
274       vals([1 7])=[];
275    else     
276       vals=['[' vals ']'];
277       vals=eval(vals);
278    end   
279    lcontour(fem_grid_struct,'z',vals);
280    vizicq4_guts('Error','')
281    vizicq4_guts('Info','')
282 case 'DelCont'
283    ch_gca=get(VIZICQ4_Grid_Axes,'Ch');        %  children of the current axes
284    cont_objs=findobj(ch_gca,'Tag','contour');
285    delete(cont_objs);
286    ch_gca=get(VIZICQ4_Grid_Axes,'Ch');        %  children of the current axes
287    textobjs=findobj(ch_gca,'Type','text');
288    delete(textobjs);
289
290 case 'LabCont'
291    fem_grid_struct=get(VIZICQ4_Grid_Axes,'UserData');
292    if isempty(fem_grid_struct)
293       vizicq4_guts('Error','No grid defined yet.')
294    % Search for contours to label
295    elseif isempty(findobj(VIZICQ4_Grid_Axes,'Tag','contour'))
296       vizicq4_guts('Error','No contours to label yet.')
297    else
298
299    private_lc(VIZICQ4_Figure,VIZICQ4_Grid_Axes,VIZICQ4_Info_Text,VIZICQ4_Error_Text)
300       vizicq4_guts('Error','')
301       vizicq4_guts('Info','')
302    end
303    
304 otherwise,
305    disp('Command hole in switch in vizicq4_guts')
306 end
307
308 setptr(VIZICQ4_Figure,'arrow')
Note: See TracBrowser for help on using the browser.