# GUI tutorial - how to set up a custom GUI for outputs that interest you

## Contents

- Independent GUI use and out definition from scratch (for general use)
- RAPTOR-related use
- simple plots
- overview plot
- customize plot

## Independent GUI use and out definition from scratch (for general use)

    close all hidden;
    clear out;
    run(fullfile(pwd,'..','RAPTOR_path.m')); % add RAPTOR path
    out.rho = linspace(0,1,21)';
    out.time = [0:0.01:1];
    out.a = (out.rho.^2)*sin(2*pi*10*out.time); % fake data

    pp = RAPTOR_plot_GUI; % get defaults

    % plot definitions
    plots{1} = struct('xdata','out.time','xlabel','t',...
                'ydata','out.a(end,:)' ,'ylabel','a(end) time trace','yscale',1,'axesnr',1,'sty','--');

    plots{2} = struct('xdata','out.rho','xlabel','\rho',...
                'ydata','out.a(:,%i)' ,'ylabel','a profile','yscale',1,'axesnr',2,'sty','-','ylim',[-1 1]);

    % axis positions
    axesdef(1).position = [0.1 0.1 0.8 0.4];
    axesdef(2).position = [0.1 0.5 0.8 0.4];

    pp.axes = axesdef;
    pp.plots = plots;
    RAPTOR_plot_GUI(out,pp)

    ans =

      Figure (1: RAPTOR output) with properties:

          Number: 1
            Name: 'RAPTOR output'
           Color: [0.9400 0.9400 0.9400]
        Position: [0.0495 0.1992 0.9000 0.7000]
           Units: 'normalized'

      Use GET to show all properties

## RAPTOR-related use

standard calls for simple RAPTOR run

    [config] = RAPTOR_config; % load default params
    % generate model, params, init, geometry g, kinetic profiles v
    [model,params,init,g,v,U] = build_RAPTOR_model(config);
    U(1,:) = 80e3*ones(size(params.tgrid));
    % input Ip trace: constant 80kA
    init.Ip0 = U(1,1);
    % Define the initial condition
    x0 = RAPTOR_initial_conditions(model,init,g(:,1),v(:,1));
    simres = RAPTOR_predictive(x0,g,v,U,model,params);

         it  telaps newt     res   t[ms]  dt[ms]  Ip[kA] Icd[kA] Ibs[kA] Ioh[kA]      qe    qmin      q0   Vl[V] Te0[keV] Ti0[keV] ne0[e19]   f_ss
          1   0.058    4 5.7e-10       0       1      80       0    1.41    78.5    15.3    5.55    5.55 3.4e+00    0.21    0.21    1.00 1.1e+01
         11    0.29    2 1.8e-12      10       1      80       0     2.4    77.6    15.3    2.89    2.89 2.9e+00    0.30    0.30    1.00 4.1e+00
         21    0.48    2 6.8e-14      20       1      80       0    2.57    77.4    15.3    2.21    2.21 2.7e+00    0.35    0.35    1.00 2.2e+00
         31     0.7    2 1.5e-14      30       1      80       0    2.67    77.3    15.3    1.93    1.93 2.5e+00    0.38    0.38    1.00 1.3e+00
         41     0.9    2 1.7e-14      40       1      80       0    2.72    77.2    15.3    1.79    1.79 2.4e+00    0.39    0.39    1.00 7.5e-01
         51     1.1    2 2.2e-14      50       1      80       0    2.75    77.2    15.3    1.72    1.72 2.4e+00    0.41    0.41    1.00 4.5e-01

generate out structure

    out = RAPTOR_out(simres,model,params);

    % uses of the GUI:

## simple plots

    RAPTOR_plot_GUI(out,'simple');

## overview plot

    RAPTOR_plot_GUI(out,'overview');

## customize plot

    pp = RAPTOR_plot_GUI('simple'); % get config structure for simple
    disp(pp); % inspect
    % customize
    disp(pp.plots{1});
    p = pp.plots; % copy existing trace definitions

    % add li vs time trace to first axis (axesnr,1)
            p = [p, struct('xdata','out.time','xlabel','t',...
                'ydata','out.li3(end,:)' ,'ylabel','li3','yscale',1,'axesnr',1,'sty','--')];

    % add profile trace on sixth axis
    p = [p,struct('xdata','out.rho','xlabel','\rho',...
                'ydata','out.shear(:,%i)' ,'ylabel','shear','yscale',1,'axesnr',6,'sty','-')];
    % '%i' signals that this profile changes in time
    % it is evaluated at time index it as: eval(sprintf('out.shear(:,%i)',it))

    % append to existing pp sturcture
    pp.plots = p;
    % call GUI
    RAPTOR_plot_GUI(out,pp); % get config structure for simple

              plots: {1x6 cell}
        linestylele: [1x7 struct]
               axes: [2x3 struct]

            xdata: 'out.time'
           xlabel: 't'
            ydata: 'out.Ip(end,:)'
           ylabel: 'I_p[MA]'
           yscale: 1.0000e-06
           axesnr: 1
        linestyle: '-'