% PeiGui: Visualization tool for HOPS netcdf files.
%
% USAGE:  peigui
% Pedro Velez (UIB-IEO), July 1999, email: dfspvb4@ps.uib.es
%
%  This sofware permit to visualize output files from the 
%  HOPS model. The present sofware scan which variables can 
%  visualized form the output file. All the information is read
%  form the .nc file, so any additional information is needed
%
%
% Once the Variable has been selected (Variables>) 
% different things that can be done at each time step of the model output:
%
%     *) Horizontal sections at user-selected depths (the interpolation 
%            is done using matlab-vectorizing) in the Depth Slider.
%     *) Horizontal sections at user selected sigma levels at the Kindex Slider.
%     *) Overlay the vector field contained in the .nc file, the vector
%        can just be overlayed to horizontal sections, using in that case
%        the vector filed at the apropiate depth or k-level. 
%        (Radio Button: Overlay Arrows) The default
%        settings for the arrows can be modificated in the menu: 
%        Default Values>Velocity Settings.
%     *) Overlay the land mask (Radio Button: Overlay Land Mask).
%     *) Vertical sections at user selected i index (Iindex Slider).
%          In case of a non oblique domain it means vertical sections at fixed longitude. 
%           The bathymery is overimposed by difault.
%     *) Vertical sections at user selected j index(Iindex Slider).
%          In case of a non oblique domain it means vertical sections at fixed latitude. 
%           The bathymery is overimposed by difault.
%     *) Overlay the vector field contained in the output file.
%
%       A common feature to the previous graphs is the possibility of doing 
%       labeles contour (Radio Button: Contour Labels), or change 
% 	  the automaric contouring for a manula contouring, where the mix,max 
%	  and increment values are introduced by the user trough the corresponding
%	  boxes in the main frame. The matlab zoom option have been incorporated 
%	  to the main frame as a radio buttom.
%       The resulting figure can be printed to a file (ps or eps) or 
%       directly to the printer(Menu: File>Print). 
%       
%	For labelling purposes is possible to define an absolute time for
%     the initial time step of the model (menu:
%     *) Animations (in time) of whatever of the previos graphs, the animations
%        are a little time consuming but the can be saved for further 
%        use.(Menu: Animation>Make New)
%     *) Visualize previously done animations. (Menu:Animation>play Saved)
%     *) ,...
%
%  For additional information read the tutorial.ps or visit 
%  the web page (http://songoanda.uib.es/~pedro/)
%
%

disp('>>>>> Type help peigui for a short introduction')

%
%    Here there is a brief explanation of the way the code works
%    in case you are interested in modify it the clues here are enouht:
%   
%    The main function is hopsgui where all the initial variables are defined.
%    All those inital (and sucesive) are defined in a cell array called 
%    peigui_obj{1}. All the parametres are passed to the subroutines trough this 
%    cell arry, excep the data it self that is never stored due to Memory problems
%    at the moment of this work. 
%    The Description of 'peigui_obj' structure fields is here

clear all
global peigui_obj

%General purpose variables
peigui_obj{1}.filein = '';     	%Mexcdf file
peigui_obj{1}.variable = '';   	%Variable to plot (tempo,salt,...)
peigui_obj{1}.time = 1;        	%Actual Time
peigui_obj{1}.depth = -10.;    	%Actual depth
peigui_obj{1}.iindex = 1;		%Actual iindex for slices
peigui_obj{1}.jindex= 1;         	%Actual jindex for slices
peigui_obj{1}.kindex= 1;          	%Actual jindex for slices
peigui_obj{1}.titlrun='';        	%Title of the Run
peigui_obj{1}.action='';            %The last action performed, (usually contouring), defined later.
peigui_obj{1}.timemax=1;		%Maximun value for time
peigui_obj{1}.timeinterval=0. ;	%Interval of time between plotted time steps (hours)


%%%%Values for contour levels
peigui_obj{1}.cautomatic=1;  	   	%Label to do or not automatic levels in contour plots
peigui_obj{1}.cmin=1.;        	%Min value to be ploted
peigui_obj{1}.cmax=1.;        	%Max value to be ploted
peigui_obj{1}.cint=.1;              %Interval of the contouring
peigui_obj{1}.labelcontours=0;  	%Flag to put or not labels in the contour lines
peigui_obj{1}.linecontours=0;  	%Flag to put or not labels in the contour lines

%Default values for drawing vectors
peigui_obj{1}.drawvectors=0;  	%Flag Overlay or not the vectors
peigui_obj{1}.fac=0.01;        	%Scale factor for vectors in the screen
peigui_obj{1}.isub=1;          	%Sampling interval for vectors
peigui_obj{1}.refvector=20;   	%Size of the reference vetor in units of the 
				       	% read velocity
peigui_obj{1}.vectorcolor='k'; 	%default color for the vectors
					 	%k is black,w white,b blue,g green, r red, y yellow
					 	%c cyan.
peigui_obj{1}.vectorvar='vclin';     %Is the vector field  of vector to be draw

%%%%Land mask
peigui_obj{1}.drawmask=0;  		%Flag Overlay or not the land mask

%%%%Animation 
peigui_obj{1}.nframes=2;		%Numero de frames
peigui_obj{1}.fps=6;			%Frames by second 
peigui_obj{1}.nta=1;			%Number of times the movie is repeated

%Default values for the absolute time
peigui_obj{1}.absyear=0;
peigui_obj{1}.absmonth=0;
peigui_obj{1}.absday=0;
peigui_obj{1}.abshour=0;

%%%%Handles of the differents objects used
%  hfigure		Handle for the main figure
%  haxes1		Handle for the Main axes
%  haxes2		Handle for the Colorbar axes
%  htextaxes	Handle for the Upper Text in main axis
%  hedit_iindex   Handle for the edit iindex box
%  hslider_iindex Handle for the Slider iindex
%  hedit_jindex	Handle for the edit jindex box
%  hslider_jindex	Handle for the slider jindex
%  hedit_kindex	Handle for the edit jindex box
%  hslider_kindex	Handle for the slider jindex
%  hedit_depth	Handle for the edit depth box
%  hslider_depth	Handle for the slider depth
%  edit_timestep  Handle for the edit time box
%  hmenuvar       handle for the menu of the variables
%  hvelocitysettingsmenu   handle for the menu used to change 
%				   some default values in the vectors
%  hautominedit	Handle for the edit min box
%  hautomaxedit	Handle for the edit min box
%


%  Once the different default values are defined the mani frame is done in the
%  peigui_main.m file, here all the windows are defined exepct those form 
%  velocity setting (done in  velocity_settingsmenu.m), 

%  absolute time (abstimegui.m ) and animatios (animationsaved.m and  )
%  All the callbacks for the differents interfaces in hopsgui are evaluated in:
%     peigui_menu_command     for general purposes and mainly gui
%     peigui_contour_command  for the differents contourings 
%     peigui_vector_command   for overlaying vectors
%     animation               for operations just related with animation
%  Although, of course, some operations are done using several calls
%  to the previous functions.


%Call the main menu window
peigui_mainmenu


%  And additional set of subroutines:
%  peigui_2dslice, peigui_depthslice, peigui_depthsliceu, peigui_depthslicev, 
%  peigui_islice, peigui_isliceu, peigui_islicev, peigui_jslice, 
%  peigui_jsliceu, peigui_jslicev, peigui_kslice, peigui_ksliceu, peigui_kslicev
%  Extract the data necesary to produce the sections, for further information
%  just refer to the especified subroutines as all of them are well documented.



%  In the file call tutorial.Txt there is a brief tutorial to become familiar 
%  with the sofware.



% Notes: the present sofware used a couple of subroutines that are not currently installed in matlab:
%	extcontour, Similar to contourf
%     potden80,   Used to calculate potential density from the salt and temperature 
%                fields
%     extrem,     Use to obtain the absolute maximun and minum of a matriz
%     nice, 	Use to obtain and an arbitrarily-but-nicely spaced contour levels. 


	


















