function varargout = MappingMeshTool(varargin)
% MAPPINGMESHTOOL interface for generating new meshes by the mapping method
% for use with the finite element code. View the help for more
% information.

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MappingMeshTool_OpeningFcn, ...
                   'gui_OutputFcn',  @MappingMeshTool_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before MappingMeshTool is made visible.
function MappingMeshTool_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to MappingMeshTool (see VARARGIN)

% get input
handles.mainguifig=varargin{1};

% initialize
if strcmp(get(hObject,'Visible'),'off')
    if ispc
        handles.makemesh.gridsize=2;
    else
        handles.makemesh.gridsize=6;
    end
    xmin=0; xmax=1; xdivs=0.05;
    ymin=0; ymax=1; ydivs=0.05;
    grid=struct('xmin',xmin,'xmax',xmax,'xdivs',xdivs,'ymin',ymin,'ymax',ymax,'ydivs',ydivs);
    handles.makemesh.grid=grid;
    handles.makemesh.numsd=1;
    handles.makemesh.join(1,:)=[0 0 0 0 0 0 0 0];
    handles.numintboundaries=0;
end
set(handles.mapmeshfig,'Color',[.273 .508 .703]);
format long

% Choose default command line output for MappingMeshTool
handles.meshfile = '';
handles.mesh = [];

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes MappingMeshTool wait for user response (see UIRESUME)
uiwait(handles.mapmeshfig);


% --- Outputs from this function are returned to the command line.
function varargout = MappingMeshTool_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.meshfile;
varargout{2} = handles.mesh;

% The figure can be deleted now
delete(handles.mapmeshfig);



function xminval_Callback(hObject, eventdata, handles)
% hObject    handle to xminval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xminval as text
%        str2double(get(hObject,'String')) returns contents of xminval as a double
handles.makemesh.grid.xmin=str2double(get(hObject,'String'));
% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function xminval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xminval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function xspaceval_Callback(hObject, eventdata, handles)
% hObject    handle to xspaceval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xspaceval as text
%        str2double(get(hObject,'String')) returns contents of xspaceval as a double
handles.makemesh.grid.xdivs=str2double(get(hObject,'String'));
% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function xspaceval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xspaceval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function xmaxval_Callback(hObject, eventdata, handles)
% hObject    handle to xmaxval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xmaxval as text
%        str2double(get(hObject,'String')) returns contents of xmaxval as a double
handles.makemesh.grid.xmax=str2double(get(hObject,'String'));
% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function xmaxval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xmaxval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function yminval_Callback(hObject, eventdata, handles)
% hObject    handle to yminval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of yminval as text
%        str2double(get(hObject,'String')) returns contents of yminval as a double
handles.makemesh.grid.ymin=str2double(get(hObject,'String'));
% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function yminval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yminval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function yspaceval_Callback(hObject, eventdata, handles)
% hObject    handle to yspaceval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of yspaceval as text
%        str2double(get(hObject,'String')) returns contents of yspaceval as a double
handles.makemesh.grid.ydivs=str2double(get(hObject,'String'));
% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function yspaceval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yspaceval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function ymaxval_Callback(hObject, eventdata, handles)
% hObject    handle to ymaxval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ymaxval as text
%        str2double(get(hObject,'String')) returns contents of ymaxval as a double
handles.makemesh.grid.ymax=str2double(get(hObject,'String'));
% Update handles structure
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function ymaxval_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ymaxval (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- When the "MESH COMPLETE" button is pressed:
function meshdonebutton_Callback(hObject, eventdata, handles)
% hObject    handle to meshdonebutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% finished with MappingMeshTool. return to main GUI.
uiresume(handles.mapmeshfig);



% --- When the "SAVE SD" button is pressed:
function makeSDbutton_Callback(hObject, eventdata, handles)
% hObject    handle to makeSDbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% save the vertex locations for the SD you've just defined
for i=1:8
    eval(['xsd(',num2str(i),')=str2num(get(handles.v',num2str(i),'x,''String''));']);
    eval(['ysd(',num2str(i),')=str2num(get(handles.v',num2str(i),'y,''String''));']);
end
numsd=handles.makemesh.numsd;
handles.makemesh.xsd(numsd,:)=xsd;
handles.makemesh.ysd(numsd,:)=ysd;

% save the divisions in each direction
handles.makemesh.divs13(numsd)=floor(str2double(get(handles.divs13,'String')));
handles.makemesh.divs24(numsd)=floor(str2double(get(handles.divs24,'String')));

% draw all existing subdomains in the window,
% so you have an idea of what the mesh looks like so far

% first redraw the grid
grid=handles.makemesh.grid;
xn=grid.xmin; xd=grid.xdivs; xx=grid.xmax; yn=grid.ymin; yd=grid.ydivs; yx=grid.ymax;
xgrid=[xn:xd:xx]; ygrid=[yn:yd:yx]; [x,y]=meshgrid(xgrid,ygrid); x=reshape(x,1,[]); y=reshape(y,1,[]);
plot(x,y,'.','MarkerSize',handles.makemesh.gridsize);
hold on
% now, for each SD, draw the outline
for i=1:numsd
    x=handles.makemesh.xsd(i,:); x=[x x(1)];
    y=handles.makemesh.ysd(i,:); y=[y y(1)];
    plot(x,y)
end
hold off
       
    
% ask if another SD is needed
anothersub=questdlg('Do you want to add another subdomain?','Subdomain finished','Yes','No','No');
if strcmp(anothersub,'Yes') % keep going - more SDs to be drawn
    handles.makemesh.numsd=handles.makemesh.numsd+1;
    % clear the vertex location boxes, so they're ready for new information
    for i=1:8
        eval(['set(handles.v',num2str(i),'x,''String'','''');']);
        eval(['set(handles.v',num2str(i),'y,''String'','''');']);
    end
    guidata(hObject,handles)
else % make the mesh
    % ask if SDs must be reviewed
    reviewSDs=questdlg('Do you want to review the mesh coordinates?','Review Mesh?','Yes','No','No');
    if strcmp(reviewSDs,'Yes') % cycle through SDs, allowing revision
        set(handles.makeSDbutton,'Visible','off'); % turn off the "SAVE SD" button
        set(handles.SDokbutton,'Visible','on');    % turn on  the "ACCEPT SD" button
        for rsd=1:numsd
            for i=1:rsd % draw the SDs upto and including the current one
                x=handles.makemesh.xsd(i,:); x=[x x(1)];
                y=handles.makemesh.ysd(i,:); y=[y y(1)];
                plot(x,y)
                hold on
            end
            hold off
            set(get(gca,'Title'),'String',['Subdomain ',num2str(rsd)],...
                'FontSize',16,'FontWeight','Bold','Color','white');
            handles.makemesh.rsd=rsd; guidata(hObject,handles); FRMT='%10.8e';
            for i=1:8
                eval(['set(handles.v',num2str(i),'x,''String'',num2str(handles.makemesh.xsd(rsd,i),FRMT));']);
                eval(['set(handles.v',num2str(i),'y,''String'',num2str(handles.makemesh.ysd(rsd,i),FRMT));']);
            end
            uiwait% wait for any changes, and if the "ACCEPT SD" button is pressed, move on
            handles=guidata(hObject);
        end
    end % done confirming SDs
    MakeJoinArray(handles); handles=guidata(hObject); % make the join array that goes into the *.gen file
    MakeMappingInput(handles); % makes the actual mesh.dat file, which will be loaded into redAnTS
    set(handles.meshdonebutton,'Visible','on'); handles=guidata(hObject);
    %draw the mesh in the window
    meshstruct = handles.mesh;
    meshdata=meshstruct.size;
    numel = meshdata(1);
    x=meshstruct.xcoords;
    y=meshstruct.ycoords;
    np=meshstruct.connect;
    axes(handles.axes1)
    for i=1:numel
        a=x(np(i,[1 2 3 1]));
        b=y(np(i,[1 2 3 1]));
        plot(a,b);
        hold on
    end
    hold off
    axis equal
end
uiwait; % wait for the user to press the "MESH COMPLETE" button

function MakeJoinArray(handles)
% make the join array
numsd=handles.makemesh.numsd;
numintboundaries=handles.numintboundaries;
if numsd>1 % if there are multiple SDs
    for SD=2:numsd %start at the second SD and go through all remaining SDs
        join=zeros(1,8); %initialize the join array
        clear mysd
        mysd(1,:)=handles.makemesh.xsd(SD,:); %get the x coords of the SD vertices
        mysd(2,:)=handles.makemesh.ysd(SD,:); %get the y coords of the SD vertices
        mysd=SDsides(mysd); %find the vertices that make up each side of the SD
        for i=1:(SD-1) %now prepare to cycle through all the previous SDs, looking for common sides
            oldsd(1,:)=handles.makemesh.xsd(i,:); %get other SD x coords
            oldsd(2,:)=handles.makemesh.ysd(i,:); %get other SD y coords
            oldsd=SDsides(oldsd); %get other SD sides
            [cor,Io,Im]=intersect(oldsd,mysd,'rows'); %see if any sides match
            join((2*Im-1):(2*Im))=[i,Io]; %use any matches to form the join array
            % now match the number of divisions in the apropriate
            % directions
            if Io==2 | Io==4
                odivs='divs24';
            elseif Io==1 | Io==3
                odivs='divs13';
            end
            if Im==2 | Im==4
                mdivs='divs24';
            elseif Im==1 | Im==3
                mdivs='divs13';
            end
            if exist('odivs') & exist('mdivs') % this means there was a matching side
                eval(['handles.makemesh.',mdivs,'(numsd)=handles.makemesh.',odivs,'(i);']);
                numintboundaries=numintboundaries+1; % increase the number of internal boundaries
            end
            clear oldsd odivs mdivs
        end
        handles.makemesh.join(SD,:)=join; % have now cycled through all previous SDs: write join array
    end %now go on to the next SD and compare it to all previous SDs
end
%save and report results
handles.numintboundaries=numintboundaries;
guidata(handles.mapmeshfig,handles);
uiwait(msgbox(['There are a total of ',num2str(handles.numintboundaries),...
    ' internal boundaries (i.e. joined subdomain sides).'],'Joined subdomains','modal'));


function output=SDsides(x)
% x is a 2x8 matrix of vertex positions (x and y coords). 
% SDsides returns a 4x6 matrix of the side coordinates of the SD
        a1=reshape(sortrows(x(:,(1:3))')',1,6); 
        a2=reshape(sortrows(x(:,(3:5))')',1,6); 
        a3=reshape(sortrows(x(:,(5:7))')',1,6); 
        a4=reshape(sortrows(x(:,([7 8 1]))')',1,6); 
        output=[a1;a2;a3;a4];
        

function MakeMappingInput(handles)
%first get the basename to work with
filterspec = '*';
title = 'Mesh Base Name:';
dflt='MappedMesh';
[filename,pn]=uiputfile(filterspec,title,dflt);
currdir=pwd; cd(pn); %change to whichever directory was chosen
% now create the text file that mesh_3tri will use.
numsd=handles.makemesh.numsd;
fid=fopen([filename,'.gen'],'w'); %call it basename.gen
fprintf(fid,'%5d %5d\n',numsd,3); %1st line has # of SDs and 3 (for #nodes per element)
for i=1:numsd %for each SD
    divs1=handles.makemesh.divs13(i); 
    divs2=handles.makemesh.divs24(i);
    fprintf(fid,'%5d %5d\n',divs1,divs2); %print the #divs in each direction
    j=handles.makemesh.join(i,:);
    fprintf(fid,'%5d %5d %5d %5d %5d %5d %5d %5d\n',j); %print the join array
    xsd=handles.makemesh.xsd(i,:); %get the x coords
    ysd=handles.makemesh.ysd(i,:); %get the y coords
    coords(1:2:16)=xsd; %form coord array
    coords(2:2:16)=ysd; %form coord array
    fprintf(fid,'%15.8e %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e %15.8e \n',coords); %print coords
end
fclose(fid); %basename.gen file finished

% now call the meshing program to create the mesh from the temporary input
% file. the results of this are the ultimate output from this GUI
mesh_3tri([filename,'.gen'],[filename,'_mesh.dat']);
[handles.meshfile, handles.mesh] = MappingMethod(handles.mainguifig,[filename,'_mesh.dat']);
guidata(gcbo,handles);
cd(currdir); %switch back to original working directory

% --- Executes on button press in gridpushbutton.
function gridpushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to gridpushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% draw the grid
grid=handles.makemesh.grid;
xn=grid.xmin; xd=grid.xdivs; xx=grid.xmax;
yn=grid.ymin; yd=grid.ydivs; yx=grid.ymax;
xgrid=[xn:xd:xx]; ygrid=[yn:yd:yx];
[x,y]=meshgrid(xgrid,ygrid);
x=reshape(x,1,[]);
y=reshape(y,1,[]);
axes(handles.axes1);
plot(x,y,'.','MarkerSize',handles.makemesh.gridsize);
h=datacursormode(gcf);
set(h,'Enable','on','SnapToDataVertex','on');

% enable click to draw SD
set(handles.drawverticesbutton,'Visible','on');
guidata(hObject,handles);


% --- When you choose "CLICK ON SD POINTS":
function drawverticesbutton_Callback(hObject, eventdata, handles)
% hObject    handle to drawverticesbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% initialize with the grid locations
numsd=handles.makemesh.numsd;
grid=handles.makemesh.grid;
xn=grid.xmin; xd=grid.xdivs; xx=grid.xmax;
yn=grid.ymin; yd=grid.ydivs; yx=grid.ymax;
xgrid=[xn:xd:xx]; ygrid=[yn:yd:yx];

% Now get the vertices of a subdivision
[cx,cy]=ginput(8); %read the 8 mouse clicks
for i=1:8 %for each click
    %find the coordinate of the grid point closest to the mouse click
    cnx=xgrid(find(min(abs(xgrid-cx(i)))==abs(xgrid-cx(i)))); 
    cornerx(i)=cnx(1);
    cny=ygrid(find(min(abs(ygrid-cy(i)))==abs(ygrid-cy(i))));
    cornery(i)=cny(1);
end
%write the coords in the vertex location boxes
set(handles.v1x,'String',cornerx(1)); set(handles.v1y,'String',cornery(1));
set(handles.v2x,'String',cornerx(2)); set(handles.v2y,'String',cornery(2));
set(handles.v3x,'String',cornerx(3)); set(handles.v3y,'String',cornery(3));
set(handles.v4x,'String',cornerx(4)); set(handles.v4y,'String',cornery(4));
set(handles.v5x,'String',cornerx(5)); set(handles.v5y,'String',cornery(5));
set(handles.v6x,'String',cornerx(6)); set(handles.v6y,'String',cornery(6));
set(handles.v7x,'String',cornerx(7)); set(handles.v7y,'String',cornery(7));
set(handles.v8x,'String',cornerx(8)); set(handles.v8y,'String',cornery(8));
% Update handles structure
guidata(hObject, handles);

% Draw the subdivision
xdraw=[cornerx(1) cornerx(2) cornerx(3) cornerx(4) cornerx(5) cornerx(6) cornerx(7) cornerx(8) cornerx(1)];
ydraw=[cornery(1) cornery(2) cornery(3) cornery(4) cornery(5) cornery(6) cornery(7) cornery(8) cornery(1)];
axes(handles.axes1);
line(xdraw,ydraw)
clear cornerx cornery


% --------------------------------------------------------------------
function Help_Callback(hObject, eventdata, handles)
% hObject    handle to Help (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
web(['file:///' which('MapMeshTool_top.html')], '-helpbrowser');
  


% --- When you press "ACCEPT SD" button:
function SDokbutton_Callback(hObject, eventdata, handles)
% hObject    handle to SDokbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

SD=handles.makemesh.rsd;
% save the vertex locations
for i=1:8
    eval(['xsd(',num2str(i),')=str2num(get(handles.v',num2str(i),'x,''String''));']);
    eval(['ysd(',num2str(i),')=str2num(get(handles.v',num2str(i),'y,''String''));']);
end
handles.makemesh.xsd(SD,:)=xsd;
handles.makemesh.ysd(SD,:)=ysd;

% save the divisions in each direction
handles.makemesh.divs13(SD)=floor(str2double(get(handles.divs13,'String')));
handles.makemesh.divs24(SD)=floor(str2double(get(handles.divs24,'String')));
% Update handles structure
guidata(hObject, handles);

%continue to the next SD
uiresume 



% % %
% % %   Below this point are only automatically generated functions to which
% % %   no change has been made.
% % %


function v1x_Callback(hObject, eventdata, handles)
% hObject    handle to v1x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v1x as text
%        str2double(get(hObject,'String')) returns contents of v1x as a double


% --- Executes during object creation, after setting all properties.
function v1x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v1x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v1y_Callback(hObject, eventdata, handles)
% hObject    handle to v1y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v1y as text
%        str2double(get(hObject,'String')) returns contents of v1y as a double


% --- Executes during object creation, after setting all properties.
function v1y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v1y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v2x_Callback(hObject, eventdata, handles)
% hObject    handle to v2x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v2x as text
%        str2double(get(hObject,'String')) returns contents of v2x as a double


% --- Executes during object creation, after setting all properties.
function v2x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v2x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v2y_Callback(hObject, eventdata, handles)
% hObject    handle to v2y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v2y as text
%        str2double(get(hObject,'String')) returns contents of v2y as a double


% --- Executes during object creation, after setting all properties.
function v2y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v2y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v3x_Callback(hObject, eventdata, handles)
% hObject    handle to v3x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v3x as text
%        str2double(get(hObject,'String')) returns contents of v3x as a double


% --- Executes during object creation, after setting all properties.
function v3x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v3x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v3y_Callback(hObject, eventdata, handles)
% hObject    handle to v3y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v3y as text
%        str2double(get(hObject,'String')) returns contents of v3y as a double


% --- Executes during object creation, after setting all properties.
function v3y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v3y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v4x_Callback(hObject, eventdata, handles)
% hObject    handle to v4x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v4x as text
%        str2double(get(hObject,'String')) returns contents of v4x as a double


% --- Executes during object creation, after setting all properties.
function v4x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v4x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v4y_Callback(hObject, eventdata, handles)
% hObject    handle to v4y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v4y as text
%        str2double(get(hObject,'String')) returns contents of v4y as a double


% --- Executes during object creation, after setting all properties.
function v4y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v4y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v5x_Callback(hObject, eventdata, handles)
% hObject    handle to v5x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v5x as text
%        str2double(get(hObject,'String')) returns contents of v5x as a double


% --- Executes during object creation, after setting all properties.
function v5x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v5x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v5y_Callback(hObject, eventdata, handles)
% hObject    handle to v5y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v5y as text
%        str2double(get(hObject,'String')) returns contents of v5y as a double


% --- Executes during object creation, after setting all properties.
function v5y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v5y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v6x_Callback(hObject, eventdata, handles)
% hObject    handle to v6x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v6x as text
%        str2double(get(hObject,'String')) returns contents of v6x as a double


% --- Executes during object creation, after setting all properties.
function v6x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v6x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v6y_Callback(hObject, eventdata, handles)
% hObject    handle to v6y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v6y as text
%        str2double(get(hObject,'String')) returns contents of v6y as a double


% --- Executes during object creation, after setting all properties.
function v6y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v6y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v7x_Callback(hObject, eventdata, handles)
% hObject    handle to v7x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v7x as text
%        str2double(get(hObject,'String')) returns contents of v7x as a double


% --- Executes during object creation, after setting all properties.
function v7x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v7x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v7y_Callback(hObject, eventdata, handles)
% hObject    handle to v7y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v7y as text
%        str2double(get(hObject,'String')) returns contents of v7y as a double


% --- Executes during object creation, after setting all properties.
function v7y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v7y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v8x_Callback(hObject, eventdata, handles)
% hObject    handle to v8x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v8x as text
%        str2double(get(hObject,'String')) returns contents of v8x as a double


% --- Executes during object creation, after setting all properties.
function v8x_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v8x (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function v8y_Callback(hObject, eventdata, handles)
% hObject    handle to v8y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of v8y as text
%        str2double(get(hObject,'String')) returns contents of v8y as a double


% --- Executes during object creation, after setting all properties.
function v8y_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v8y (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function divs13_Callback(hObject, eventdata, handles)
% hObject    handle to divs13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of divs13 as text
%        str2double(get(hObject,'String')) returns contents of divs13 as a double


% --- Executes during object creation, after setting all properties.
function divs13_CreateFcn(hObject, eventdata, handles)
% hObject    handle to divs13 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function divs24_Callback(hObject, eventdata, handles)
% hObject    handle to divs24 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of divs24 as text
%        str2double(get(hObject,'String')) returns contents of divs24 as a double


% --- Executes during object creation, after setting all properties.
function divs24_CreateFcn(hObject, eventdata, handles)
% hObject    handle to divs24 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


