classdef clipWRdata < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        figure_main         matlab.ui.Figure
        edit_hole           matlab.ui.control.EditField
        holeEditFieldLabel  matlab.ui.control.Label
        edit_site           matlab.ui.control.NumericEditField
        coreLabel_4         matlab.ui.control.Label
        edit_exp            matlab.ui.control.NumericEditField
        coreLabel_2         matlab.ui.control.Label
        edit_filename       matlab.ui.control.EditField
        filenameLabel       matlab.ui.control.Label
        edit_sect           matlab.ui.control.NumericEditField
        sectionLabel        matlab.ui.control.Label
        edit_core           matlab.ui.control.NumericEditField
        coreLabel           matlab.ui.control.Label
        button_save_new     matlab.ui.control.Button
        button_update       matlab.ui.control.Button
        button_profile      matlab.ui.control.Button
        button_data         matlab.ui.control.Button
        axis_data_5         matlab.ui.control.UIAxes
        axis_data_4         matlab.ui.control.UIAxes
        axis_data_3         matlab.ui.control.UIAxes
        axis_data_2         matlab.ui.control.UIAxes
        axis_data           matlab.ui.control.UIAxes
    end

    
    properties (Access = private)
        exp 
        site
        hole
        core
        sect
        
        DataFile_1
        DataFile_2
        DataFile_3
        DataFile_4
        Profile

        DataTable_1
        DataTable_2
        DataTable_3
        DataTable_4
        PTable
        z
        z_1 % Description
        data_1
        offset_1
        z_2 % Description
        data_2
        offset_2
        z_3 % Description
        data_3
        offset_3
        z_4 % Description
        data_4
        offset_4
        offset_all
        datatype_1
        datatype_2
        datatype_3
        datatype_4
        discrete

        prof_y

        ProfPlot
        dataplot
    end
    

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            clear;
            clc;
            close all;
        end

        % Button pushed function: button_data
        function button_dataPushed(app, event)
            % Define section
            app.exp = num2str(app.edit_exp.Value);
            app.site = num2str(app.edit_site.Value);
            app.hole = app.edit_hole.Value;
            app.core = num2str(app.edit_core.Value);
            app.sect = num2str(app.edit_sect.Value);
            app.edit_filename.Value = ['E' app.exp '_U' app.site app.hole '_' ...
                app.core '_' app.sect];
            if isempty(app.edit_core.Value) 
                uialert(app.figure_main, 'Please name the file and define a core and section', 'Must define section');
                return
            end


            if isempty(app.edit_core.Value) || isempty(app.edit_sect.Value) || isempty(app.edit_filename.Value)
                uialert(app.figure_main, 'Please name the file and define a core and section', 'Must define section');
                return
            end
            
            cla(app.axis_data_2);
            
            %app.DataFile = uigetfile('*.csv', 'Load loop magnetic susceptibility (WRMSL)  data');
            %figure(app.figure_main);

            %if app.dropdown_datatype.Value == app.dropdown_datatype.Items{1}
                app.DataFile_1 = [app.exp '-U' app.site app.hole '_MS-WRMSL.csv'];
            %elseif app.dropdown_datatype.Value == app.dropdown_datatype.Items{2}
                app.DataFile_2 = [app.exp '-U' app.site app.hole '_MS-SHMSL.csv'];
            %elseif app.dropdown_datatype.Value == app.dropdown_datatype.Items{3}
                app.DataFile_3 = [app.exp '-U' app.site app.hole '_GRA.csv'];
            %elseif app.dropdown_datatype.Value == app.dropdown_datatype.Items{4}
                app.DataFile_4 = [app.exp '-U' app.site app.hole '_NGR.csv'];
            %end

            app.DataTable_1 = readtable([pwd '/data_raw/' app.DataFile_1]);
            app.DataTable_2 = readtable([pwd '/data_raw/' app.DataFile_2]);
            app.DataTable_3 = readtable([pwd '/data_raw/' app.DataFile_3]);
            app.DataTable_4 = readtable([pwd '/data_raw/' app.DataFile_4]);

            coredata_1 = app.DataTable_1(app.DataTable_1.Core == app.edit_core.Value, :);
            sectiondata_1 = coredata_1(coredata_1.Sect == app.edit_sect.Value, :);
            app.DataTable_1 = sectiondata_1;

             coredata_2 = app.DataTable_2(app.DataTable_2.Core == app.edit_core.Value, :);
            sectiondata_2 = coredata_2(coredata_2.Sect == app.edit_sect.Value, :);
            app.DataTable_2 = sectiondata_2;

             coredata_3 = app.DataTable_3(app.DataTable_3.Core == app.edit_core.Value, :);
            sectiondata_3 = coredata_3(coredata_3.Sect == app.edit_sect.Value, :);
            app.DataTable_3 = sectiondata_3;

             coredata_4 = app.DataTable_4(app.DataTable_4.Core == app.edit_core.Value, :);
            sectiondata_4 = coredata_4(coredata_4.Sect == app.edit_sect.Value, :);
            app.DataTable_4 = sectiondata_4;

        if ~isempty(sectiondata_4)

            app.offset_all = 2:2:150;
            app.offset_all = app.offset_all';
         
            %if app.dropdown_datatype.Value == app.dropdown_datatype.Items{1}
                % WMRLS MS data
                % =========
                
                app.z_1 =   app.DataTable_1.DepthCSF_A_m_  ; % zm = depth below seafloor
                app.data_1 = app.DataTable_1.MagneticSusceptibility_instr_Units_ ;  % ml = data
                app.offset_1 = app.DataTable_1.Offset_cm_ ; % czm = section depth (offset)

                if ~isequal(app.offset_all, app.offset_1)
                    nans = nan(length(app.offset_all)-length(app.offset_1),1);
                    app.data_1 = [app.data_1;nans];
                end

                app.datatype_1 = 'Magnetic Susceptibility (WRMSL)'; 

                
            %elseif app.dropdown_datatype.Value == app.dropdown_datatype.Items{2}
                % SHMSL MS data
                % =============
                
                app.z_2 = app.DataTable_2.DepthCSF_A_m_ ;% zmp = depth below seafloor
                app.data_2 = app.DataTable_2.MagneticSusceptibility_instr_Units_ ;% mp = data
                app.offset_2 = app.DataTable_2.Offset_cm_ ;% czp = section depth (offset)

                app.datatype_2 = 'Magnetic Susceptibility (SHMSL)';

                % in case some data were removed
                %endofsect = app.offset(end);
                %range = 2:2:endofsect;
                %missingind = ~ismember(range, app.offset);
                %if any(missingind~=0)
                %    missingval = range(missingind);
                %    app.offset = [app.offset; missingval(1);missingval(2)];
                %    app.offset = sort(app.offset);
                %    c = nan(size(app.offset));
                %    c(~missingind)=app.data;
                %    app.data = c;
                %end

                if ~isequal(app.offset_all, app.offset_2)
                    nans = nan(length(app.offset_all)-length(app.offset_2),1);
                    app.data_2 = [app.data_2;nans];
                end
   
            %elseif app.dropdown_datatype.Value == app.dropdown_datatype.Items{3}
                % Density data
                % ============
                app.z_3 = app.DataTable_3.DepthCSF_A_m_ ;% zd = depth below seafloor
                app.data_3 = app.DataTable_3.BulkDensity_GRA_ ; % d = data
                app.offset_3 = app.DataTable_3.Offset_cm_ ; % czd = section depth (offset)

                if ~isequal(app.offset_all, app.offset_3)
                    nans = nan(length(app.offset_all)-length(app.offset_3),1);
                    app.data_3 = [app.data_3;nans];
                end

                app.datatype_3 = 'Density (GRA)'; 

            %elseif app.dropdown_datatype.Value == app.dropdown_datatype.Items{4}
                % Natural Gamma Ray data
                % ========================
                app.z_4 = app.DataTable_4.DepthCSF_A_m_ ;% zd = depth below seafloor
                app.data_4 = app.DataTable_4.NGRTotalCounts_cps_; % d = data
                app.offset_4 = app.DataTable_4.Offset_cm_ ; % czd = section depth (offset)
                
            
                if ~isequal(app.offset_all, app.offset_4)
                        nans = nan(length(app.offset_all),1);
                        t =  (0:5:max(app.offset_4/2)+1);
                        t(1)=1;
                        
                        k=1;
                        for i=t
                            nans(i) = app.data_4(k);
                           k= k+1;
                        end
                end
                app.data_4 = nans;
                

                app.datatype_4 = 'Natural Gamma Ray (counts/s)'; 

            % 1
            app.axis_data_2.XLabel.String = app.datatype_1; 
            if app.discrete==1
                app.dataplot = plot(app.axis_data_2, app.data_1, app.z_1, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            else
                app.dataplot = plot(app.axis_data_2, app.data_1, app.offset_all, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            end
            app.axis_data_2.YDir = 'reverse';
            app.axis_data_2.YTick = 2:2:150;
            ax = [app.axis_data app.axis_data_2];
            linkaxes(ax,'y')
            app.axis_data_2.Title.String = 'Core Data';
            app.axis_data_2.YLabel.String = 'Offset (cm)';

            % 2
            app.axis_data_3.XLabel.String = app.datatype_2; 
            app.dataplot = plot(app.axis_data_3, app.data_2, app.offset_all, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            app.axis_data_3.YDir = 'reverse';
            app.axis_data_3.YTick = 2:2:150;
            ax = [app.axis_data app.axis_data_3];
            linkaxes(ax,'y')
            app.axis_data_3.Title.String = 'Core Data';
            app.axis_data_3.YLabel.String = 'Offset (cm)';

            % 3 
            app.axis_data_4.XLabel.String = app.datatype_3; 
            app.dataplot = plot(app.axis_data_4, app.data_3, app.offset_all, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            app.axis_data_4.YDir = 'reverse';
            app.axis_data_4.YTick = 2:2:150;
            ax = [app.axis_data app.axis_data_4];
            linkaxes(ax,'y')
            app.axis_data_4.Title.String = 'Core Data';
            app.axis_data_4.YLabel.String = 'Offset (cm)';

            % 4
            app.axis_data_5.XLabel.String = app.datatype_4; 
            app.dataplot = plot(app.axis_data_5, app.data_4, app.offset_all, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            app.axis_data_5.YDir = 'reverse';
            app.axis_data_5.YTick = 2:2:150;
            ax = [app.axis_data app.axis_data_5];
            linkaxes(ax,'y')
            app.axis_data_5.Title.String = 'Core Data';
            app.axis_data_5.YLabel.String = 'Offset (cm)';

        else
            uialert(app.figure_main, 'No recorded data for this section and datatype', 'Missing data');
            return
        end
        end

        % Button pushed function: button_profile
        function button_profilePushed(app, event)
            
            % Define section
            app.exp = num2str(app.edit_exp.Value);
            app.site = num2str(app.edit_site.Value);
            app.hole = app.edit_hole.Value;
            app.core = num2str(app.edit_core.Value);
            app.sect = num2str(app.edit_sect.Value);
            app.edit_filename.Value = ['E' app.exp '_U' app.site app.hole '_' ...
                app.core '_' app.sect];
            if isempty(app.edit_core.Value) 
                uialert(app.figure_main, 'Please name the file and define a core and section', 'Must define section');
                return
            end
            

            % Profile data
            % ============
            
            if app.edit_sect.Value<10
                profname = [app.exp '-u' app.site app.hole '-' app.core 'r-' app.sect '-'];
            else
                profname = [app.exp '-u' app.hole '-' app.core 'r-' app.sect];
            end

            load([pwd '/profiles/formatted/' profname '.mat'], 'offset', 'laser');

            zprof = offset; % zprof = depth in section
            prof = laser; % prof = data

            app.z = zprof;

            app.ProfPlot = plot(app.axis_data, prof, zprof, 'Marker','*');
            app.axis_data.XLabel.String = 'Laser Profile';
            app.axis_data.Title.String = 'Core Profile';
            app.axis_data.YTick = 2:2:150;
            app.axis_data.YDir = 'reverse';
            app.axis_data.YLabel.String = 'Offset (cm)';


        end

        % Button pushed function: button_update
        function button_updatePushed(app, event)
            app.prof_y = app.axis_data.Children.YData';
            app.prof_y = app.prof_y(1:200:end);
            app.prof_y = app.prof_y(2:end);
            if length(app.prof_y ) ~= 75
                app.prof_y(end+1) = app.prof_y(end)+2;
            end

            plot(app.axis_data_2, app.data_1, app.prof_y, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            plot(app.axis_data_3, app.data_2, app.prof_y, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            plot(app.axis_data_4, app.data_3, app.prof_y, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            plot(app.axis_data_5, app.data_4, app.prof_y, 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
        end

        % Button pushed function: button_save_new
        function button_save_newButtonPushed(app, event)
            
            app.prof_y = app.axis_data.Children.YData';
            app.prof_y = app.prof_y(1:200:end);
            app.prof_y = app.prof_y(2:end);
            if length(app.prof_y ) ~= 75
                app.prof_y(end+1) = app.prof_y(end)+2;
            end
            
            % Find max depth 
            max_z_1 = max(app.z_1);
            max_z_2 = max(app.z_2);
            max_z_3 = max(app.z_3);
            %max_z_4 = max(app.z_4);
            maxes = [max_z_1,max_z_2, max_z_3];
            [~,ind_max]=max(maxes);

            if ind_max==1
                app.z=app.z_1;
            elseif ind_max==2
                app.z=app.z_2;
            elseif ind_max==3
                app.z=app.z_3;
            %elseif ind_max==4
             %   app.z=app.z_4;
            end

            nz = length(app.z);
            

            datatable = table(app.offset_all(1:nz),'VariableNames',"Depth in section (offset) (cm)");
            datatable.Depth_mbsf = app.z;
% 1

            newx = app.axis_data_2.Children.XData';
            newy = app.axis_data_2.Children.YData';
            
            nr = length(newx);
           
            for i=1:nr
                if isnan(newy(i))
                    newx(i) = NaN;
                end
            end
           
            app.data_1 = newx(1:nz);
           
            datatypecell = cellstr(app.datatype_1);
            datatable.NewVar = app.data_1;
            [~, numcol] = size(datatable);
            datatable.Properties.VariableNames(numcol) = datatypecell;

            
% 2 
            newx = app.axis_data_3.Children.XData';
            newy = app.axis_data_3.Children.YData';
            
            nr = length(newx);

            for i=1:nr
                if isnan(newy(i))
                    newx(i) = NaN;
                end
            end

            app.data_2 = newx(1:nz);

            datatypecell = cellstr(app.datatype_2);
            datatable.NewVar = app.data_2;
            [~, numcol] = size(datatable);
            datatable.Properties.VariableNames(numcol) = datatypecell;
% 3
            newx = app.axis_data_4.Children.XData';
            newy = app.axis_data_4.Children.YData';
            
            nr = length(newx);

            for i=1:nr
                if isnan(newy(i))
                    newx(i) = NaN;
                end
            end

            app.data_3 = newx(1:nz);

            datatypecell = cellstr(app.datatype_3);
            datatable.NewVar = app.data_3;
            [~, numcol] = size(datatable);
            datatable.Properties.VariableNames(numcol) = datatypecell;

% 4
            newx = app.axis_data_5.Children.XData';
            newy = app.axis_data_5.Children.YData';
            
            nr = length(newx);

            for i=1:nr
                if isnan(newy(i))
                    newx(i) = NaN;
                end
            end

            app.data_4 = newx(1:nz);
            
            datatypecell = cellstr(app.datatype_4);
            datatable.NewVar = app.data_4;
            [~, numcol] = size(datatable);
            datatable.Properties.VariableNames(numcol) = datatypecell;  

% update plots


            plot(app.axis_data_2, app.data_1, app.offset_all(1:nz), 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            plot(app.axis_data_3, app.data_2, app.offset_all(1:nz), 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            plot(app.axis_data_4, app.data_3, app.offset_all(1:nz), 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');
            plot(app.axis_data_5, app.data_4, app.offset_all(1:nz), 'k', 'LineWidth',2, 'Marker','x', 'LineStyle','-');

            

            outputname = app.edit_filename.Value;
      
            writetable(datatable, [pwd '/outputs/' outputname '_filtered.xlsx'])

            uialert(app.figure_main, ['New excel sheet created: ', 'outputs/' outputname '_filtered.xlsx'], 'Success', 'Icon','success');

        end

        % Callback function
        function button_save_sectionButtonPushed(app, event)
            
            newx = app.axis_data_2.Children.XData';
            newy = app.axis_data_2.Children.YData';
            
            nr = length(newx);

            for i=1:nr
                if isnan(newy(i))
                    newx(i) = NaN;
                end
            end

            app.data = newx;
            
            outputname = app.edit_filename.Value;

            datatable = readtable(['outputs/' outputname, '_filtered.xlsx']);
            datatable.NewData = app.data;

            datatypecell = cellstr(app.datatype);
            [~, numcol] = size(datatable);
            datatable.Properties.VariableNames(numcol) = datatypecell;
            
            writetable(datatable, [pwd '/outputs/' outputname '_filtered.xlsx'])

            uialert(app.figure_main,['New data added to existing excel sheet created: ', 'outputs/' outputname '_filtered.xlsx'],  'Success', 'Icon','success');

        end

        % Callback function
        function button_save_holeButtonPushed(app, event)
            

            newx = app.axis_data_2.Children.XData';
            newy = app.axis_data_2.Children.YData';
            
            nr = length(newx);

            for i=1:nr
                if isnan(newy(i))
                    newx(i) = NaN;
                end
            end

            app.data = newx;
            
            outputname = app.edit_filename.Value;

            datatable = readtable(['outputs/' outputname, '_filtered.xlsx']);
            datatable.NewData = app.data;

            datatypecell = cellstr(app.datatype);
            [~, numcol] = size(datatable);
            datatable.Properties.VariableNames(numcol) = datatypecell;
            
            writetable(datatable, [pwd '/outputs/' outputname '_filtered.xlsx'])

            uialert(app.figure_main,['New data added to existing excel sheet created: ', 'outputs/' outputname '_filtered.xlsx'],  'Success', 'Icon','success');


        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create figure_main and hide until all components are created
            app.figure_main = uifigure('Visible', 'off');
            app.figure_main.Position = [100 100 1516 1034];
            app.figure_main.Name = 'MATLAB App';

            % Create axis_data
            app.axis_data = uiaxes(app.figure_main);
            title(app.axis_data, 'Title')
            xlabel(app.axis_data, 'X')
            ylabel(app.axis_data, 'Y')
            zlabel(app.axis_data, 'Z')
            app.axis_data.YMinorTick = 'on';
            app.axis_data.XGrid = 'on';
            app.axis_data.YGrid = 'on';
            app.axis_data.FontSize = 10;
            app.axis_data.Position = [1 99 442 928];

            % Create axis_data_2
            app.axis_data_2 = uiaxes(app.figure_main);
            title(app.axis_data_2, 'Title')
            xlabel(app.axis_data_2, 'X')
            ylabel(app.axis_data_2, 'Y')
            zlabel(app.axis_data_2, 'Z')
            app.axis_data_2.YTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
            app.axis_data_2.XGrid = 'on';
            app.axis_data_2.YGrid = 'on';
            app.axis_data_2.YMinorGrid = 'on';
            app.axis_data_2.FontSize = 10;
            app.axis_data_2.Position = [463 99 259 928];

            % Create axis_data_3
            app.axis_data_3 = uiaxes(app.figure_main);
            title(app.axis_data_3, 'Title')
            xlabel(app.axis_data_3, 'X')
            ylabel(app.axis_data_3, 'Y')
            zlabel(app.axis_data_3, 'Z')
            app.axis_data_3.YTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
            app.axis_data_3.XGrid = 'on';
            app.axis_data_3.YGrid = 'on';
            app.axis_data_3.YMinorGrid = 'on';
            app.axis_data_3.FontSize = 10;
            app.axis_data_3.Position = [722 100 259 928];

            % Create axis_data_4
            app.axis_data_4 = uiaxes(app.figure_main);
            title(app.axis_data_4, 'Title')
            xlabel(app.axis_data_4, 'X')
            ylabel(app.axis_data_4, 'Y')
            zlabel(app.axis_data_4, 'Z')
            app.axis_data_4.YTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
            app.axis_data_4.XGrid = 'on';
            app.axis_data_4.YGrid = 'on';
            app.axis_data_4.YMinorGrid = 'on';
            app.axis_data_4.FontSize = 10;
            app.axis_data_4.Position = [980 99 259 928];

            % Create axis_data_5
            app.axis_data_5 = uiaxes(app.figure_main);
            title(app.axis_data_5, 'Title')
            xlabel(app.axis_data_5, 'X')
            ylabel(app.axis_data_5, 'Y')
            zlabel(app.axis_data_5, 'Z')
            app.axis_data_5.YTick = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
            app.axis_data_5.XGrid = 'on';
            app.axis_data_5.YGrid = 'on';
            app.axis_data_5.YMinorGrid = 'on';
            app.axis_data_5.FontSize = 10;
            app.axis_data_5.Position = [1237 99 259 928];

            % Create button_data
            app.button_data = uibutton(app.figure_main, 'push');
            app.button_data.ButtonPushedFcn = createCallbackFcn(app, @button_dataPushed, true);
            app.button_data.FontSize = 18;
            app.button_data.Position = [871 46 100 31];
            app.button_data.Text = 'Plot data';

            % Create button_profile
            app.button_profile = uibutton(app.figure_main, 'push');
            app.button_profile.ButtonPushedFcn = createCallbackFcn(app, @button_profilePushed, true);
            app.button_profile.FontSize = 18;
            app.button_profile.Position = [386 51 145 31];
            app.button_profile.Text = 'Plot laser profile';

            % Create button_update
            app.button_update = uibutton(app.figure_main, 'push');
            app.button_update.ButtonPushedFcn = createCallbackFcn(app, @button_updatePushed, true);
            app.button_update.FontSize = 18;
            app.button_update.Position = [993 46 119 31];
            app.button_update.Text = 'Update plots';

            % Create button_save_new
            app.button_save_new = uibutton(app.figure_main, 'push');
            app.button_save_new.ButtonPushedFcn = createCallbackFcn(app, @button_save_newButtonPushed, true);
            app.button_save_new.FontSize = 18;
            app.button_save_new.Position = [1212 46 284 31];
            app.button_save_new.Text = 'Save filtered data to spreadsheet';

            % Create coreLabel
            app.coreLabel = uilabel(app.figure_main);
            app.coreLabel.HorizontalAlignment = 'right';
            app.coreLabel.FontSize = 14;
            app.coreLabel.Position = [44 16 37 22];
            app.coreLabel.Text = 'core:';

            % Create edit_core
            app.edit_core = uieditfield(app.figure_main, 'numeric');
            app.edit_core.FontSize = 14;
            app.edit_core.Position = [106 16 35 22];

            % Create sectionLabel
            app.sectionLabel = uilabel(app.figure_main);
            app.sectionLabel.HorizontalAlignment = 'right';
            app.sectionLabel.FontSize = 14;
            app.sectionLabel.Position = [161 16 55 22];
            app.sectionLabel.Text = 'section:';

            % Create edit_sect
            app.edit_sect = uieditfield(app.figure_main, 'numeric');
            app.edit_sect.FontSize = 14;
            app.edit_sect.Position = [225 16 39 22];

            % Create filenameLabel
            app.filenameLabel = uilabel(app.figure_main);
            app.filenameLabel.HorizontalAlignment = 'right';
            app.filenameLabel.FontSize = 14;
            app.filenameLabel.Position = [309 16 66 22];
            app.filenameLabel.Text = 'file name:';

            % Create edit_filename
            app.edit_filename = uieditfield(app.figure_main, 'text');
            app.edit_filename.FontSize = 14;
            app.edit_filename.Position = [386 16 258 22];

            % Create coreLabel_2
            app.coreLabel_2 = uilabel(app.figure_main);
            app.coreLabel_2.HorizontalAlignment = 'right';
            app.coreLabel_2.FontSize = 14;
            app.coreLabel_2.Position = [7 55 74 22];
            app.coreLabel_2.Text = 'expedition:';

            % Create edit_exp
            app.edit_exp = uieditfield(app.figure_main, 'numeric');
            app.edit_exp.FontSize = 14;
            app.edit_exp.Position = [89 55 43 22];

            % Create coreLabel_4
            app.coreLabel_4 = uilabel(app.figure_main);
            app.coreLabel_4.HorizontalAlignment = 'right';
            app.coreLabel_4.FontSize = 14;
            app.coreLabel_4.Position = [153 55 31 22];
            app.coreLabel_4.Text = 'site:';

            % Create edit_site
            app.edit_site = uieditfield(app.figure_main, 'numeric');
            app.edit_site.FontSize = 14;
            app.edit_site.Position = [193 55 47 22];

            % Create holeEditFieldLabel
            app.holeEditFieldLabel = uilabel(app.figure_main);
            app.holeEditFieldLabel.HorizontalAlignment = 'right';
            app.holeEditFieldLabel.FontSize = 14;
            app.holeEditFieldLabel.Position = [258 55 36 22];
            app.holeEditFieldLabel.Text = 'hole:';

            % Create edit_hole
            app.edit_hole = uieditfield(app.figure_main, 'text');
            app.edit_hole.FontSize = 14;
            app.edit_hole.Position = [309 55 32 22];

            % Show the figure after all components are created
            app.figure_main.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = clipWRdata

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.figure_main)

            % Execute the startup function
            runStartupFcn(app, @startupFcn)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.figure_main)
        end
    end
end